Skip to main content

mogli

mogli is a 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

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

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.

Metadata

Release files for mogli 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mogli 0.3.0
File Size Uploaded
mogli-0.3.0.tar.gz 12.3 kB Details

Release files / mogli-0.3.0.tar.gz

Download URL mogli-0.3.0.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
959a90aaa09fd4eb66b557e1e0262b8242fc7e43c0d906ac7108452992f9e9bd
BLAKE2b-256 checksum
How to use checksums
5e0c1921faa4ed81c3d0636529b4f49daead7d266938e6087d599dd1f87163b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page