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.0.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.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file mol2mesh-0.1.0.tar.gz.

File metadata

  • Download URL: mol2mesh-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 66d5fe4b9f9dd24dca4d9be1d62680fe4b9baac3f57948856724a1566a41716d
MD5 49db21471a5a67aa2201bb864497ae60
BLAKE2b-256 e9dca3032c1d50f0e9e17fd1627e07900c4b30b2c7e2c44493dff6324f01398b

See more details on using hashes here.

File details

Details for the file mol2mesh-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mol2mesh-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d93ae440eb6446b77b6a4891802a745cd14d3e1d1a05d9fd7a4e604516aafcf7
MD5 7efe5e9703dc5ad25554924a80f398c5
BLAKE2b-256 3f714eed06c33e725c778e222ce66a2cef381c26a39b2435c23c81c644485c55

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