One method to generate 3D structures of organic molecules is by converting molecular information written in SMILES notation. This article explains how to execute this process in the Matlantis environment.
- Using Matlantis Features
- Using autodE for creating 5-coordinate and 6-coordinate structures
1. Using Matlantis Features
In the Matlantis environment, it is possible to generate 3D structures using Matlantis Features as shown below:
# Example of creating a Testosterone molecule
from matlantis_features.atoms import MatlantisAtoms
molec = MatlantisAtoms.from_smiles("O=C4\C=C2/[C@]([C@H]1CC[C@@]3([C@@H](O)CC[C@H]3[C@@H]1CC2)C)(C)CC4").ase_atoms
molec
The output result is as follows:
Atoms(symbols='OC9OC10H28', pbc=False)
To display the 3D structure, execute the following:
from pfcc_extras import view_ngl
view_ngl(molec, representations=["ball+stick"])
Note: However, it will fail for 5-coordinate and 6-coordinate structures.
molec = MatlantisAtoms.from_smiles("[P1](F)(F)(F)(F)(F)(F)").ase_atoms
The following error will be obtained as the result:
[00:14:42] SMILES Parse Error: syntax error while parsing: [P1](F)(F)(F)(F)(F)(F)
[00:14:42] SMILES Parse Error: Failed parsing SMILES '[P1](F)(F)(F)(F)(F)(F)' for input: '[P1](F)(F)(F)(F)(F)(F)'
---------------------------------------------------------------------------
ArgumentError Traceback (most recent call last)
/tmp/ipykernel_3167/1113753141.py in <cell line: 1>()
----> 1 molec = MatlantisAtoms.from_smiles("[P1](F)(F)(F)(F)(F)(F)").ase_atoms
~/.py39/lib/python3.9/site-packages/matlantis_features/atoms.py in from_smiles(cls, smiles, method, seed)
73 """
74 mol = Chem.MolFromSmiles(smiles)
---> 75 mol = Chem.AddHs(mol)
76
77 if method not in ["etkdg_v2", "etkdg", "etdg", "kdg", "2d"]:
ArgumentError: Python argument types in
rdkit.Chem.rdmolops.AddHs(NoneType)
did not match C++ signature:
AddHs(RDKit::ROMol mol, bool explicitOnly=False, bool addCoords=False, boost::python::api::object onlyOnAtoms=None, bool addResidualInfo=False)
Please refer to the following for methods to resolve this issue.
2. Using autodE for Creating 5-coordinate and 6-coordinate Structures
When creating 5-coordinate and 6-coordinate structures from SMILES notation, it has been confirmed that using autodE can resolve the issue.
First, install autodE by following these steps:
!git clone https://github.com/duartegroup/autodE.git
!cd autodE && pip install .
After that, define the following functions. Using these functions, you will be able to generate 3D structures even for 5-coordinate and 6-coordinate molecules.
import autode as ade
from ase import Atoms, Atom
import numpy as np
from pfcc_extras.visualize.view import view_ngl
def smiles_to_ase_atoms(smiles):
ade_mol = ade.Molecule(smiles=smiles)
ase_atoms = ade_to_ase_atoms(ade_mol.atoms)
return ase_atoms
def ade_to_ase_atoms(ade_atoms):
ele = np.array([atom.atomic_symbol for atom in ade_atoms])
pos = np.array([atom.coord for atom in ade_atoms])
return Atoms(ele, pos)
molec = smiles_to_ase_atoms("[P](F)(F)(F)(F)(F)(F)")
view_ngl(molec, representations=["ball+stick"])