Giter VIP home page Giter VIP logo

mogli's Introduction

mogli

mogli is python module for easily rendering molecules.

The fastest way to get started is using mogli.py in the command line:

% python -m mogli <file_name> 

This will open a new window in which the molecule will be rendered. You can then rotate the molecule using your mouse.

In python, you can achieve something similar with three lines of code:

>>> import mogli
>>> molecules = mogli.read('examples/dna.xyz')
>>> mogli.show(molecules[0])

DNA rendered in a GR window

Atomic bonds

You might notice that the atomic bonds between the atoms don't look right. You can hide the bonds by adding the show_bonds=False to your show() call, but of course there's a a better way to fix the missing bonds here.

For the example above, adding bond_param=1.15 to show() will do the trick. mogli currently offers two ways of calculating atomic bonds. The first method compares the distance between every two atoms with the sum of their valence radii. If they are further apart, no bond is formed. To allow a bit of adjustment, this radii sum is multiplied with a factor that can be set using the bond_param parameter to show() and draw(). By default, 1.0 is used.

The second method uses a constant maximum distance instead. If you use this method by passing bond_method='constant_delta' to show() or draw(), you can set the constant distance with the bond_param parameter.

Exporting to files

Instead of viewing molecules interactively, you can export the molecule as well, for example as Portable Network Graphics into a .png file, or as HTML5 page with interactive WebGL code as .html file. To do so, simply call the export() function, like so:

>>> import mogli
>>> molecules = mogli.read('examples/dna.xyz')
>>> mogli.export(molecules[0], 'dna.html', width=1920, height=1080,
                 bonds_param=1.15, camera=((40, 0, 0),
                                           (0, 0, 0),
                                           (0, 1, 0)))

This example code also shows setting the camera in code by passing the camera parameter. It expects three sequences of three floating point numbers: the camera position, the center of focus and a direction that should point upward. Exporting to HTML5 with WebGL is a pretty near feature, give it a try!

Drawing with GR

In case you use the GR framework, you can use mogli to draw molecules into your GR graphics. To do so, just call draw(). You can use the parameters xmin, xmax, ymin, ymax, width and height just like you would when using gr.drawimage().

>>> import gr
>>> import mogli
>>> molecules = mogli.read('examples/dna.xyz')
>>> mogli.draw(molecules[0])
>>> gr.updatews()

DNA rendered in a GR window

Dependencies

mogli depends on GR3, which is included in the GR framework (PyPI, GitHub), on glfw3 (GitHub) and python bindings for glfw3 (PyPI, GitHub).

Additionally, Pybel should be installed; mogli will work without it, but only for xyz files.

mogli's People

Contributors

florianrhiem avatar jheinen avatar

Watchers

James Cloos avatar  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.