Re: [Rdkit-discuss] Euclidean distance between atoms using RDKit

2019-09-04 Thread Navid Shervani-Tabar
Thanks Omar, That indeed fix the problem.

Navid

On Wed, Sep 4, 2019 at 7:15 PM Omar H94  wrote:

> Dear Navid,
> You need to embed your molecule to have a 3D conformation.
> Try:
>
> from rdkit.Chem import AllChem
> mol = Chem.MolFromSmiles('O=CC1OC12CC1OC12')
> AllChem.EmbedMolecule(mol)
> conf = mol.GetConformer()
> at1Coords = np.array(conf.GetAtomPosition(1))
> at2Coords = np.array(conf.GetAtomPosition(2))
> print(np.linalg.norm(at2Coords - at1Coords))
>
> I hope this works for you.
> Best regards,
> Omar
>
> On Thu, Sep 5, 2019 at 1:59 AM Navid Shervani-Tabar 
> wrote:
>
>> Hello,
>>
>> I'm trying to find the Euclidean distance between two atoms in the
>> molecule with SMILES representation `O=CC1OC12CC1OC12` using the `rdkit`
>> package. Looking online, I have converged to the following code.
>>
>> import numpy as np
>> from rdkit import Chem
>>
>> mol = Chem.MolFromSmiles('O=CC1OC12CC1OC12')
>>
>> conf = mol.GetConformer()
>> at1Coords = np.array(conf.GetAtomPosition(bond_i.GetBeginAtomIdx()))
>> at2Coords = np.array(conf.GetAtomPosition(bond_i.GetEndAtomIdx()))
>> print(np.linalg.norm(at2Coords - at1Coords))
>>
>> But I get the error
>>
>> conf = mol.GetConformer()
>> ValueError: Bad Conformer Id
>>
>> I was wondering how to fix the issue.
>>
>> Thanks!
>> Navid
>>
>> ___
>> Rdkit-discuss mailing list
>> Rdkit-discuss@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>>
> ___
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] Euclidean distance between atoms using RDKit

2019-09-04 Thread Omar H94
Dear Navid,
You need to embed your molecule to have a 3D conformation.
Try:

from rdkit.Chem import AllChem
mol = Chem.MolFromSmiles('O=CC1OC12CC1OC12')
AllChem.EmbedMolecule(mol)
conf = mol.GetConformer()
at1Coords = np.array(conf.GetAtomPosition(1))
at2Coords = np.array(conf.GetAtomPosition(2))
print(np.linalg.norm(at2Coords - at1Coords))

I hope this works for you.
Best regards,
Omar

On Thu, Sep 5, 2019 at 1:59 AM Navid Shervani-Tabar 
wrote:

> Hello,
>
> I'm trying to find the Euclidean distance between two atoms in the
> molecule with SMILES representation `O=CC1OC12CC1OC12` using the `rdkit`
> package. Looking online, I have converged to the following code.
>
> import numpy as np
> from rdkit import Chem
>
> mol = Chem.MolFromSmiles('O=CC1OC12CC1OC12')
>
> conf = mol.GetConformer()
> at1Coords = np.array(conf.GetAtomPosition(bond_i.GetBeginAtomIdx()))
> at2Coords = np.array(conf.GetAtomPosition(bond_i.GetEndAtomIdx()))
> print(np.linalg.norm(at2Coords - at1Coords))
>
> But I get the error
>
> conf = mol.GetConformer()
> ValueError: Bad Conformer Id
>
> I was wondering how to fix the issue.
>
> Thanks!
> Navid
>
> ___
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


[Rdkit-discuss] Euclidean distance between atoms using RDKit

2019-09-04 Thread Navid Shervani-Tabar
Hello,

I'm trying to find the Euclidean distance between two atoms in the molecule
with SMILES representation `O=CC1OC12CC1OC12` using the `rdkit` package.
Looking online, I have converged to the following code.

import numpy as np
from rdkit import Chem

mol = Chem.MolFromSmiles('O=CC1OC12CC1OC12')

conf = mol.GetConformer()
at1Coords = np.array(conf.GetAtomPosition(bond_i.GetBeginAtomIdx()))
at2Coords = np.array(conf.GetAtomPosition(bond_i.GetEndAtomIdx()))
print(np.linalg.norm(at2Coords - at1Coords))

But I get the error

conf = mol.GetConformer()
ValueError: Bad Conformer Id

I was wondering how to fix the issue.

Thanks!
Navid
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] Xenon atoms have hydrogen added

2019-09-04 Thread Tim Dudgeon

Rocco,

Great. You nailed it!

Many thanks.

Tim

On 04/09/2019 17:41, Rocco Moretti wrote:
I think the issue is that you're making an explicit bond to a Xenon 
atom, and Xenon's valence model in the RDKit says that it has either 
zero bond or it has two bonds. (Don't worry - it's not really 
something you should have known /a priori /- valence models are funky. 
) 



list( Chem.GetPeriodicTable().GetValenceList("Xe") ) # Returns [0, 2]

Since you have at least one bond to Xenon (to the carbon), you can't 
have zero bonds, so you must have two bonds, so RDKit fills in the 
missing valence with an implicit hydrogen:


atom.GetTotalValence() # returns 2
atom.GetNumImplicitHs() # returns 1

The hydrogen is implicit, so removing the hydrogens with 
Chem.RemoveHs() won't do anything.


This then interacts with the Smiles code. The Smiles model says that 
if you have an atom in brackets (which Xenon always is), you need to 
explicitly record the hydrogens it has. (See here 
 for more.)


Ways around it: The easiest would be if you could change your element 
to something which takes a single valence, or something that doesn't 
have valences for implicit hydrogen purposes. (Astatine is a decent 
choice for the former, many of the the actinides work well for the 
latter.) If you really do want to use Xenon, you can always manually 
flag the atom to not have any implicit hydrogens.*

*
*
*
*...*
xe = Chem.Atom(54) # 54 is Xenon
*xe.SetNoImplicit(True)*
idx = mw.AddAtom(xe)
mw.AddBond(0,6,Chem.BondType.SINGLE)
Chem.SanitizeMol(mw)
atom = mw.GetAtomWithIdx(idx)
atom.GetExplicitValence() # returns 1
atom.GetTotalValence() *# returns 1*
atom.GetNumImplicitHs() *# returns 0***
Chem.MolToSmiles(mw) *# returns '[Xe]c1c1'*

On Wed, Sep 4, 2019 at 9:35 AM Tim Dudgeon > wrote:


I'm finding that if I add a Xenon atom to a molecule it seems to
get an
unwanted hydrogen added to it.
Example notebook here:
https://gist.github.com/tdudgeon/ba3497341d9de95b4d78f3e5ed9fc0f7

Basic code is like this:

from rdkit import Chem
m = Chem.MolFromSmiles("c1c1")
mw = Chem.RWMol(m)
xe = Chem.Atom(54) # 54 is Xenon
idx = mw.AddAtom(xe)
mw.AddBond(0,6,Chem.BondType.SINGLE)
Chem.SanitizeMol(mw)
atom = mw.GetAtomWithIdx(idx)
atom.GetExplicitValence() # returns 1
Chem.MolToSmiles(mw) # returns [XeH]c1c1, expecting [Xe]c1c1

Even if I do a Chem.RemoveHs() the H remains.

Any ideas why and how to fix?





___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] Xenon atoms have hydrogen added

2019-09-04 Thread Rocco Moretti
I think the issue is that you're making an explicit bond to a Xenon atom,
and Xenon's valence model in the RDKit says that it has either zero bond or
it has two bonds. (Don't worry - it's not really something you should have
known *a priori *- valence models are funky.
)


list( Chem.GetPeriodicTable().GetValenceList("Xe") ) # Returns [0, 2]

Since you have at least one bond to Xenon (to the carbon), you can't have
zero bonds, so you must have two bonds, so RDKit fills in the missing
valence with an implicit hydrogen:

atom.GetTotalValence() # returns 2
atom.GetNumImplicitHs() # returns 1

The hydrogen is implicit, so removing the hydrogens with Chem.RemoveHs()
won't do anything.

This then interacts with the Smiles code. The Smiles model says that if you
have an atom in brackets (which Xenon always is), you need to explicitly
record the hydrogens it has. (See here

for more.)

Ways around it: The easiest would be if you could change your element to
something which takes a single valence, or something that doesn't have
valences for implicit hydrogen purposes. (Astatine is a decent choice for
the former, many of the the actinides work well for the latter.) If you
really do want to use Xenon, you can always manually flag the atom to not
have any implicit hydrogens.

*...*
xe = Chem.Atom(54) # 54 is Xenon
*xe.SetNoImplicit(True)*
idx = mw.AddAtom(xe)
mw.AddBond(0,6,Chem.BondType.SINGLE)
Chem.SanitizeMol(mw)
atom = mw.GetAtomWithIdx(idx)
atom.GetExplicitValence() # returns 1
atom.GetTotalValence() *# returns 1*
atom.GetNumImplicitHs() *# returns 0*
Chem.MolToSmiles(mw) *# returns '[Xe]c1c1'*

On Wed, Sep 4, 2019 at 9:35 AM Tim Dudgeon  wrote:

> I'm finding that if I add a Xenon atom to a molecule it seems to get an
> unwanted hydrogen added to it.
> Example notebook here:
> https://gist.github.com/tdudgeon/ba3497341d9de95b4d78f3e5ed9fc0f7
>
> Basic code is like this:
>
> from rdkit import Chem
> m = Chem.MolFromSmiles("c1c1")
> mw = Chem.RWMol(m)
> xe = Chem.Atom(54) # 54 is Xenon
> idx = mw.AddAtom(xe)
> mw.AddBond(0,6,Chem.BondType.SINGLE)
> Chem.SanitizeMol(mw)
> atom = mw.GetAtomWithIdx(idx)
> atom.GetExplicitValence() # returns 1
> Chem.MolToSmiles(mw) # returns [XeH]c1c1, expecting [Xe]c1c1
>
> Even if I do a Chem.RemoveHs() the H remains.
>
> Any ideas why and how to fix?
>
>
>
>
>
> ___
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


[Rdkit-discuss] Xenon atoms have hydrogen added

2019-09-04 Thread Tim Dudgeon
I'm finding that if I add a Xenon atom to a molecule it seems to get an 
unwanted hydrogen added to it.
Example notebook here: 
https://gist.github.com/tdudgeon/ba3497341d9de95b4d78f3e5ed9fc0f7


Basic code is like this:

from rdkit import Chem
m = Chem.MolFromSmiles("c1c1")
mw = Chem.RWMol(m)
xe = Chem.Atom(54) # 54 is Xenon
idx = mw.AddAtom(xe)
mw.AddBond(0,6,Chem.BondType.SINGLE)
Chem.SanitizeMol(mw)
atom = mw.GetAtomWithIdx(idx)
atom.GetExplicitValence() # returns 1
Chem.MolToSmiles(mw) # returns [XeH]c1c1, expecting [Xe]c1c1

Even if I do a Chem.RemoveHs() the H remains.

Any ideas why and how to fix?





___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss