Code Monkey home page Code Monkey logo

blender-chemicals's Introduction

Chemicals in Blender

Draws chemicals in Blender โ‰ฅ2.8 using common input formats (smiles, molfiles, cif files, etc.). For details, read my blog post.

Samples

Caffeine, ball and stick

Penicillin, ball and stick, Cycles render

NU-100, ball and stick

NU-100, 3D printed from Blender output

Installation

With Conda

conda install -c openbabel openbabel
pip install blender-chemicals

This library uses Open Babel to read multiple chemical file formats. The easiest way to install is through conda. If you're a scientist that doesn't currently use conda, I recommend taking the time to learn it before continuing.

Without Conda

If you prefer to build from source, read through the Open Babel installation instructions. The commands usually boil down to something like:

git clone https://github.com/openbabel/openbabel --depth 1 && cd openbabel
mkdir build && cd build
cmake ../openbabel -DPYTHON_BINDINGS=ON
make && make install

Then, install this library with pip install blender-chemicals. Alternately, you can git clone and run with python -m blender_chemicals.run c1ccccc1.

Usage

Command Line

This library installs a command-line tool that handles common use cases. To test, run:

blender-chemicals c1ccccc1

If this works, the command will load benzene into a Blender window. You can replace c1ccccc1 with another string or file path, and the program will do its best to determine input format.

Beyond this, there are a number of configuration options. Type blender-chemicals --help to learn more.

In Blender

The command line simplifies the majority of usage, but it can't do everything. If you want to customize, you'll likely want to import or edit the scripts directly. I'd recommend copy-pasting the drawing code into Blender. For details, read my blog post.

With the current library organization, you would copy the contents of draw.py into a Blender window. You can then hardcode the path of atoms.json (top of file) and your JSON-formatted molecule (bottom of file).

Generating JSON

If you're going the custom route, you'll still need to generate the proper JSON format. To generate from the command line, run:

blender-chemicals c1ccccc1 --convert-only > molecule.json

If you're looking to draw hundred of chemicals, you can access the python function directly.

import pybel
from blender_chemicals.parse import process

output = []
for molecule in my_molecules:
    mol = pybel.readstring('format', molecule)
    output.append(process(mol))

From here, hardcode the paths in your blender script and adjust as needed.

blender-chemicals's People

Contributors

patrickfuller avatar slashme avatar pyxidatol-c avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.