Giter Club home page Giter Club logo

Comments (2)

mojtabah avatar mojtabah commented on June 12, 2024

Hi, thanks for your interest! As you mentioned, we don't support other formats yet. But, we plan to add them in the close future.

Yes, you can override the rdkit molecule. Here is the workaround:

  1. Let's say you can create a rdkit molecule with associated conformation. I am making one here:

>>> from chemml.chem import Molecule
>>> m1 = Molecule('O', 'smiles') # water molecule
>>> m1.to_xyz(optimizer='UFF') # embed and optimize the 3D geometry

This molecule gives you an rdkit molecule:
>>> m1.rdkit_molecule
<rdkit.Chem.rdchem.Mol at 0x13b4b7d00>
>>> m1.xyz.geometry
array([[-6.62167743e-04, 4.04121065e-01, 0.00000000e+00], [-7.82704434e-01, -2.03343606e-01, 0.00000000e+00], [ 7.83366601e-01, -2.00777459e-01, 0.00000000e+00]])

  1. Based on what you described, you only have rdkit objects. Now, I want to create a new chemml molecule using that rdkit molecule only. You first need to instantiate the Molecule class using dummy info:

>>> m2 = Molecule('C', 'smiles')

Please note that if you try to create the xyz geometry with no optimization, the following error raises:

>>> m2.to_xyz(optimizer=None)
ValueError: The conformation has not been built yet (maybe due to the 2D representation of the creator). You should set the optimizer value if you wish to embed and optimize the 3D geometry.

Now, we replace its rdkit_molecule with the water molecule from the first step:

>>> m2.rdkit_molecule = m1.rdkit_molecule # any rdkit.Chem.rdchem.Mol object

when you try to build the geometry with no optimizer, it gets the available conformation from your rdkit molecule:
>>> m2.to_xyz(optimizer=None)
>>> m2.xyz.geometry
array([[-6.62167743e-04, 4.04121065e-01, 0.00000000e+00], [-7.82704434e-01, -2.03343606e-01, 0.00000000e+00], [ 7.83366601e-01, -2.00777459e-01, 0.00000000e+00]])

>>> m2
<chemml.chem.Molecule(
rdkit_molecule : <rdkit.Chem.rdchem.Mol object at 0x13b5cdda0>,
pybel_molecule : None,
creator : ('SMILES', 'C'),
smiles : 'C',
smarts : None,
inchi : None,
xyz : <XYZ(geometry: (3, 3), atomic_numbers: (3, 1), atomic_symbols: (3, 1))>)>

You can also get the correct SMILES if you need:
>>> m2.to_smiles()
>>> m2
<chemml.chem.Molecule(
rdkit_molecule : <rdkit.Chem.rdchem.Mol object at 0x13b5cdda0>,
pybel_molecule : None,
creator : ('SMILES', 'C'),
smiles : '[H]O[H]',
smarts : None,
inchi : None,
xyz : <XYZ(geometry: (3, 3), atomic_numbers: (3, 1), atomic_symbols: (3, 1))>)>

No worries about the creator, this is just the initial creator and as far as I remember doesn't make any issue.

Please let me know if you have any other questions. Thanks!

from chemml.

HenriqueCSJ avatar HenriqueCSJ commented on June 12, 2024

Thanks, it worked like a charm!

from chemml.

Related Issues (11)

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.