Skip to main content

Convert molecular structures into 3D meshes

Project description


About

Mol2Mesh generates a 3D model of any molecule from its chemical table file

Input (Chemical table file)

Example: Dopamine.sdf

681
  -OEChem-05142402263D

 22 22  0     0  0  0  0  0  0999 V2000
   -2.2392    1.9626    0.0548 O   0  0  0  0  0  0  0  0  0  0  0  0
   -3.3557   -0.5612    0.3868 O   0  0  0  0  0  0  0  0  0  0  0  0
    4.4081    0.2624    0.3445 N   0  0  0  0  0  0  0  0  0  0  0  0
    2.1628   -0.0212   -0.6613 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.7040   -0.1603   -0.3850 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.9862    0.1008    0.6289 C   0  0  0  0  0  0  0  0  0  0  0  0

Output (3D model)

3D models of dopamine .stl (left) and .glb (right) viewed in 3D viewer

Basic usage

Open In Colab

from mol2mesh import Mol2Mesh

#open chemical table file (.sdf, .mol, or .gjf)
input_file = 'sample_files/Dopamine.sdf' #path to file
molecule = Mol2Mesh(input_file)

#check the resulting 3D model of the molecule
molecule.show()

#save 3D model
molecule.save_mesh('Dopamine.stl')

Parameters

Mol2Mesh(file_path, style='BallStick', res_a=25, res_b=15, multicov=False, name=None)
  • file_path: Path to the chemical table file (sdf, mol, or gjf).

  • style: Style configuration defining the radii and colors of atoms and bonds. It can be a configuration class or a string from the defined styles ['BallStick', 'Sticks', 'SpaceFilling'].

  • res_a and res_b: Resolution of an atom sphere and bond cylinder, i.e., the number of points defining each circle forming the sphere or cylinder. Increase the value for a smoother surface and decrease for a smaller file size.

  • multicov: Visibility of multiple covalent bonds *

  • name: The name of the molecule to be stored in the resulting 3D model .stl file.

Methods

  • show(): Visualizes the molecule in 3D using Plotly.
  • save_mesh(): Saves the molecule mesh as an .stl file. The resulting file can be used for 3D printing. .stl files do not store color.
  • get_mesh(): Returns a combined array of meshes as np.array
  • show_mesh(): Displays molecule meshes (vertices and edges) as wireframes using Plotly.
  • save_glb(): Saves the molecule as a 3D model with colors in .glb format. Relies on trimesh library.

Chemical table files

Chemical table file (CT file) is a text file that describes a molecule. A CT file can store many information, but at the very least it should contain xyz coordinates of atoms that make up a molecule. There are many different formats, but the most common one is molfile which can have .mol or .sdf file extension.

Getting chemical table files for known compounds

  • PubChem: Most known small-molecule compounds are registered in PubChem. To get the sdf file, search for the molecule by name, and on its molecule page, go to 3D conformer section to download the sdf file.

  • Wikipedia: If you don't know the exact name of the molecule, you can google the molecule and check whether it has a wikipedia page. In the identifier section (usually located beneath the molecule's structure on the right side of the page), you'll find the PubChem CID, which will redirect you to the molecule's page on PubChem.

Creating chemical table files

For custom molecules, you can use any 3D molecular visualization software. The most simple and acessible one is MolView which allows you to download the .mol file of the molecule, however it doesn't offer energy minimization, so the 3D conformer for unknown compounds might look strange. Alternatively, you can use well-known software such as Avogadro, Chem3D, MarvinView, etc., and save the molecule as .mol, .sdf, or .gjf.

3D models

Types

  • .stl file is a human-readable file of a 3D mesh that contains triangles (xyz coordinates) and their facet normals.
  • .glb file is a representation of a 3D model written by GL Transmission Format (glTF).

Usage

The resulting file can be used for educative or personal purposes, such as making a real 3D model by 3D printing or just for molecule visualization. Additionally, both .stl and .glb files can be imported into PowerPoint slides.


Acknowledgement

The approach for multicov is a contribution from @mziele1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mol2mesh-0.1.1b1.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mol2mesh-0.1.1b1-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file mol2mesh-0.1.1b1.tar.gz.

File metadata

  • Download URL: mol2mesh-0.1.1b1.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for mol2mesh-0.1.1b1.tar.gz
Algorithm Hash digest
SHA256 e7023bade954f2aff37c24d830c1eae13df4107efe2f5cc60865aab40a396cd7
MD5 c5748159e9e6db5d3e773957145c2238
BLAKE2b-256 bcf4e9169cef78a619930ec61df47312f0ba77a4b7ee15f0656ac0fff4e0137c

See more details on using hashes here.

File details

Details for the file mol2mesh-0.1.1b1-py3-none-any.whl.

File metadata

  • Download URL: mol2mesh-0.1.1b1-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for mol2mesh-0.1.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac21c6f10118626fd8679ec1a258e49216c6dd1fc106f0109b4ef9fcab8b69a8
MD5 2dbfc0517c8da8e58b5e2691c3f76032
BLAKE2b-256 89190448f9848268446edb57e89d8c0d9b0f09be7fe89134ca5b318a7326f1f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page