Re: [Rdkit-discuss] Does AddConformer function lose SDF properties of conformers when adding them?

2018-05-24 Thread Udvarhelyi, Aniko
Dear Paolo,

thank you very much! Now it is working as I hoped it would.
My error was that I was using suppl[0] when writing out, instead of defining a 
new variable mol=suppl[0] and doing the copy_coords with that mol variable, as 
you did.

Many thanks for your help!
best regards,
Anikó

From: Paolo Tosco [mailto:paolo.tosco.m...@gmail.com]
Sent: Mittwoch, 23. Mai 2018 17:02
To: Udvarhelyi, Aniko; Greg Landrum
Cc: rdkit-discuss@lists.sourceforge.net
Subject: Re: [Rdkit-discuss] Does AddConformer function lose SDF properties of 
conformers when adding them?


Dear Aniko,
Here is a Jupyter notebook that does what you need:

https://gist.github.com/ptosco/28bc22acbb6d000812c12699b6711be6<https://urldefense.proofpoint.com/v2/url?u=https-3A__gist.github.com_ptosco_28bc22acbb6d000812c12699b6711be6=DwMDaQ=ZbgFmJjg4pdtrnL2HUJUDw=ANfhdkzkLaTzqQrdJ1uJyFwAJDWEMRAEFydqudcLj6o=PhG51Rc_bwPvECLKpbXXAAxoebXonCKrECV8ji1HgXM=TK6CbooNsGVu47UfabACw_De2-gBATimkGqC_xdKeD0=>
Cheers,
p.
On 05/23/18 14:11, Udvarhelyi, Aniko wrote:
Dear Paolo,

thank you very much for your quick reply! So does this mean that Conformer 
Objects cannot have properties themselves, i.e. specific to the conformer 
itself and independent of the properties of the parent Mol Object? So there is 
no way to directly handle conformer properties by reading/writing to/from SDFs?

I implemented your suggested round-about solution as follows.

# reading in confs as written below, calling AlignMolConformers --> allconfs 
object stores aligned confs
def copy_coords(source, to):
for i in range(source.GetNumAtoms()):
to.SetAtomPosition(i, source.GetAtomPosition(i))

i = 0
for conf in confs:  # looping again over original confs to update their 
coordinates from aligned allconfs
suppl = Chem.SDMolSupplier(conf, removeHs = False)
copy_coords(allconfs.GetConformer(i), suppl[0].GetConformer())
wname = conf.split(“.sdf”,1)[0] + “_aligned.sdf”
w = Chem.SDWriter(wname)
w.write(suppl[0])
i += 1
w.close()

Unfortunately it did not work. The original coordinates were kept in the 
_aligned.SDF files and were not updated with the coordinates after alignment. 
What am I doing wrong here?

I would highly appreciate any hints and help on this!

Many thanks and best regards,
Anikó


From: Paolo Tosco [mailto:paolo.tosco.m...@gmail.com]
Sent: Mittwoch, 23. Mai 2018 11:41
To: Udvarhelyi, Aniko; Greg Landrum
Cc: 
rdkit-discuss@lists.sourceforge.net<mailto:rdkit-discuss@lists.sourceforge.net>
Subject: Re: [Rdkit-discuss] Does AddConformer function lose SDF properties of 
conformers when adding them?


Dear Aniko,

properties are associated to the Mol object, not to the Conformer object. If 
you wish to retain the original properties associated with each Mol you may 
copy the aligned coordinates to the original Mol object and write that instead. 
This will allow you to retain the original properties. Please note that I 
haven't tried to run my own sample code below, so please bear with me if it 
does not quite work as is, but it was just to give you an idea how to achieve 
your goal:

def copy_coords(from, to):
for i in range(from.GetNumAtoms()):
to.SetAtomPosition(i, from.GetAtomPosition(i))

w = Chem.SDWriter(“aligned.sdf”)
nconfs = len(allconfs.GetConformers())
i = 0
for conf in confs:   # loop over my sdf files
suppl = Chem.SDMolSupplier(conf, removeHs = False)
if “_c0.sdf” in conf:
copy_coords(allconfs.GetConformer(0), suppl[0].GetConformer())
w.write(suppl[0])
else:
for mol in suppl:
i += 1
if (i == nconfs):
raise RuntimeError('Something went wrong, i = nconfs = 
{0:d}'.format(nconfs))
copy_coords(allconfs.GetConformer(i), mol.GetConformer())
w.write(mol)
w.close()
HTH, Cheers,
p.

On 05/23/18 09:11, Udvarhelyi, Aniko wrote:
Dear Greg,

I have separate SDF files of conformers of the same molecule (they are called 
_c0.sdf, _c1.sdf, _c2.sdf and so on), with a few properties for 
each conformer. I am using the following code to read them into RDKit and align 
them:

for conf in confs:   # loop over my sdf files
suppl = Chem.SDMolSupplier(conf, removeHs = False)
if “_c0.sdf” in conf:
allconfs = suppl[0]
else:
for i,mol in enumerate(suppl):
allconfs.AddConformer(mol.GetConformer(), assignId = True)

And then I am using AllChem.AlignMolConformers(allconfs) to align the 
conformers. It all works fine BUT: when I save the aligned conformers with the 
SDWriter, all the conformers have the properties of the very first conformer. 
What should I do to keep the original SDF properties of the conformers from 
before the alignment? Does AddConformer lose the properties or is something 
wrong with how I write them out? I am using the following to save the aligned 
conformers into one sdf:

w = Chem.SDWriter(“aligned.sdf”)
for conf_id in range(len(allconf.GetConformers)):
w

Re: [Rdkit-discuss] Does AddConformer function lose SDF properties of conformers when adding them?

2018-05-23 Thread Paolo Tosco

Dear Aniko,

Here is a Jupyter notebook that does what you need:

https://gist.github.com/ptosco/28bc22acbb6d000812c12699b6711be6

Cheers,
p.

On 05/23/18 14:11, Udvarhelyi, Aniko wrote:


Dear Paolo,

thank you very much for your quick reply! So does this mean that 
Conformer Objects cannot have properties themselves, i.e. specific to 
the conformer itself and independent of the properties of the parent 
Mol Object? So there is no way to directly handle conformer properties 
by reading/writing to/from SDFs?


I implemented your suggested round-about solution as follows.

# reading in confs as written below, calling AlignMolConformers 
àallconfs object stores aligned confs


def copy_coords(source, to):
    for i in range(source.GetNumAtoms()):
    to.SetAtomPosition(i, source.GetAtomPosition(i))

i = 0
for conf in confs:  # looping again over original confs to update 
their coordinates from aligned allconfs

    suppl = Chem.SDMolSupplier(conf, removeHs = False)
    copy_coords(allconfs.GetConformer(i), suppl[0].GetConformer())
wname = conf.split(“.sdf”,1)[0] + “_aligned.sdf”
    w = Chem.SDWriter(wname)
w.write(suppl[0])
i += 1
w.close()

Unfortunately it did not work. The original coordinates were kept in 
the _aligned.SDF files and were not updated with the coordinates after 
alignment. What am I doing wrong here?


I would highly appreciate any hints and help on this!

Many thanks and best regards,

Anikó

*From:*Paolo Tosco [mailto:paolo.tosco.m...@gmail.com]
*Sent:* Mittwoch, 23. Mai 2018 11:41
*To:* Udvarhelyi, Aniko; Greg Landrum
*Cc:* rdkit-discuss@lists.sourceforge.net
*Subject:* Re: [Rdkit-discuss] Does AddConformer function lose SDF 
properties of conformers when adding them?


Dear Aniko,

properties are associated to the Mol object, not to the Conformer 
object. If you wish to retain the original properties associated with 
each Mol you may copy the aligned coordinates to the original Mol 
object and write that instead. This will allow you to retain the 
original properties. Please note that I haven't tried to run my own 
sample code below, so please bear with me if it does not quite work as 
is, but it was just to give you an idea how to achieve your goal:



def copy_coords(from, to):
    for i in range(from.GetNumAtoms()):
    to.SetAtomPosition(i, from.GetAtomPosition(i))

w = Chem.SDWriter(“aligned.sdf”)
nconfs = len(allconfs.GetConformers())
i = 0
for conf in confs:   # loop over my sdf files
    suppl = Chem.SDMolSupplier(conf, removeHs = False)
    if “_c0.sdf” in conf:
    copy_coords(allconfs.GetConformer(0), suppl[0].GetConformer())
    w.write(suppl[0])
    else:
    for mol in suppl:
    i += 1
    if (i == nconfs):
    raise RuntimeError('Something went wrong, i = nconfs = 
{0:d}'.format(nconfs))

    copy_coords(allconfs.GetConformer(i), mol.GetConformer())
    w.write(mol)
w.close()

HTH, Cheers,
p.

On 05/23/18 09:11, Udvarhelyi, Aniko wrote:

Dear Greg,

I have separate SDF files of conformers of the same molecule (they
are called _c0.sdf, _c1.sdf, _c2.sdf and so on), with
a few properties for each conformer. I am using the following code
to read them into RDKit and align them:

*for conf in confs:   # loop over my sdf files*

*    suppl = Chem.SDMolSupplier(conf, removeHs = False)*

*    if “_c0.sdf” in conf:*

*    allconfs = suppl[0]*

*    else:*

*    for i,mol in enumerate(suppl):*

*allconfs.AddConformer(mol.GetConformer(), assignId = True)*

And then I am using *AllChem.AlignMolConformers(allconfs)*to align
the conformers. It all works fine BUT: when I save the aligned
conformers with the SDWriter, all the conformers have the
properties of the very first conformer. What should I do to keep
the original SDF properties of the conformers from before the
alignment? Does AddConformer lose the properties or is something
wrong with how I write them out? I am using the following to save
the aligned conformers into one sdf:

*w = Chem.SDWriter(“aligned.sdf”)*

*for conf_id in range(len(allconf.GetConformers)):*

*w.write(allconfs, confId=conf_id)*

*w.close()*

What should I do to have all the original SDF properties from the
initial conformers in the aligned.sdf file?

Many thanks and best regards,

Anikó





--

Check out the vibrant tech community on one of the world's most

engaging tech sites, Slashdot.org!http://sdm.link/slashdot

<https://urldefense.proofpoint.com/v2/url?u=http-3A__sdm.link_slashdot=DwMDaQ=ZbgFmJjg4pdtrnL2HUJUDw=ANfhdkzkLaTzqQrdJ1uJyFwAJDWEMRAEFydqudcLj6o=CZ6lBy8QxadPv6cUeoQ6ww4N4oaJ_g7z52waY421iNc=1NSYUS7IRMb60DuSVz4HNeUeGacas8a4g-iByKmIpvM=>




___

Rdkit-discuss mailing list

Rdkit-d

Re: [Rdkit-discuss] Does AddConformer function lose SDF properties of conformers when adding them?

2018-05-23 Thread Udvarhelyi, Aniko
Dear Paolo,

thank you very much for your quick reply! So does this mean that Conformer 
Objects cannot have properties themselves, i.e. specific to the conformer 
itself and independent of the properties of the parent Mol Object? So there is 
no way to directly handle conformer properties by reading/writing to/from SDFs?

I implemented your suggested round-about solution as follows.

# reading in confs as written below, calling AlignMolConformers --> allconfs 
object stores aligned confs
def copy_coords(source, to):
for i in range(source.GetNumAtoms()):
to.SetAtomPosition(i, source.GetAtomPosition(i))

i = 0
for conf in confs:  # looping again over original confs to update their 
coordinates from aligned allconfs
suppl = Chem.SDMolSupplier(conf, removeHs = False)
copy_coords(allconfs.GetConformer(i), suppl[0].GetConformer())
wname = conf.split(“.sdf”,1)[0] + “_aligned.sdf”
w = Chem.SDWriter(wname)
w.write(suppl[0])
i += 1
w.close()

Unfortunately it did not work. The original coordinates were kept in the 
_aligned.SDF files and were not updated with the coordinates after alignment. 
What am I doing wrong here?

I would highly appreciate any hints and help on this!

Many thanks and best regards,
Anikó


From: Paolo Tosco [mailto:paolo.tosco.m...@gmail.com]
Sent: Mittwoch, 23. Mai 2018 11:41
To: Udvarhelyi, Aniko; Greg Landrum
Cc: rdkit-discuss@lists.sourceforge.net
Subject: Re: [Rdkit-discuss] Does AddConformer function lose SDF properties of 
conformers when adding them?


Dear Aniko,

properties are associated to the Mol object, not to the Conformer object. If 
you wish to retain the original properties associated with each Mol you may 
copy the aligned coordinates to the original Mol object and write that instead. 
This will allow you to retain the original properties. Please note that I 
haven't tried to run my own sample code below, so please bear with me if it 
does not quite work as is, but it was just to give you an idea how to achieve 
your goal:

def copy_coords(from, to):
for i in range(from.GetNumAtoms()):
to.SetAtomPosition(i, from.GetAtomPosition(i))

w = Chem.SDWriter(“aligned.sdf”)
nconfs = len(allconfs.GetConformers())
i = 0
for conf in confs:   # loop over my sdf files
suppl = Chem.SDMolSupplier(conf, removeHs = False)
if “_c0.sdf” in conf:
copy_coords(allconfs.GetConformer(0), suppl[0].GetConformer())
w.write(suppl[0])
else:
for mol in suppl:
i += 1
if (i == nconfs):
raise RuntimeError('Something went wrong, i = nconfs = 
{0:d}'.format(nconfs))
copy_coords(allconfs.GetConformer(i), mol.GetConformer())
w.write(mol)
w.close()
HTH, Cheers,
p.

On 05/23/18 09:11, Udvarhelyi, Aniko wrote:
Dear Greg,

I have separate SDF files of conformers of the same molecule (they are called 
_c0.sdf, _c1.sdf, _c2.sdf and so on), with a few properties for 
each conformer. I am using the following code to read them into RDKit and align 
them:

for conf in confs:   # loop over my sdf files
suppl = Chem.SDMolSupplier(conf, removeHs = False)
if “_c0.sdf” in conf:
allconfs = suppl[0]
else:
for i,mol in enumerate(suppl):
allconfs.AddConformer(mol.GetConformer(), assignId = True)

And then I am using AllChem.AlignMolConformers(allconfs) to align the 
conformers. It all works fine BUT: when I save the aligned conformers with the 
SDWriter, all the conformers have the properties of the very first conformer. 
What should I do to keep the original SDF properties of the conformers from 
before the alignment? Does AddConformer lose the properties or is something 
wrong with how I write them out? I am using the following to save the aligned 
conformers into one sdf:

w = Chem.SDWriter(“aligned.sdf”)
for conf_id in range(len(allconf.GetConformers)):
w.write(allconfs, confId=conf_id)
w.close()

What should I do to have all the original SDF properties from the initial 
conformers in the aligned.sdf file?

Many thanks and best regards,
Anikó





--

Check out the vibrant tech community on one of the world's most

engaging tech sites, Slashdot.org! 
http://sdm.link/slashdot<https://urldefense.proofpoint.com/v2/url?u=http-3A__sdm.link_slashdot=DwMDaQ=ZbgFmJjg4pdtrnL2HUJUDw=ANfhdkzkLaTzqQrdJ1uJyFwAJDWEMRAEFydqudcLj6o=CZ6lBy8QxadPv6cUeoQ6ww4N4oaJ_g7z52waY421iNc=1NSYUS7IRMb60DuSVz4HNeUeGacas8a4g-iByKmIpvM=>




___

Rdkit-discuss mailing list

Rdkit-discuss@lists.sourceforge.net<mailto:Rdkit-discuss@lists.sourceforge.net>

https://lists.sourceforge.net/lists/listinfo/rdkit-discuss<https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.sourceforge.net_lists_listinfo_rdkit-2Ddiscuss=DwMDaQ=ZbgFmJjg4pdtrnL2HUJUDw=ANfhdkzkLaTzqQrdJ1uJyFwAJDWEMRAEFydqudcLj6o=CZ6lBy8QxadPv6cUeoQ6ww4N4

Re: [Rdkit-discuss] Does AddConformer function lose SDF properties of conformers when adding them?

2018-05-23 Thread Paolo Tosco

Dear Aniko,

properties are associated to the Mol object, not to the Conformer 
object. If you wish to retain the original properties associated with 
each Mol you may copy the aligned coordinates to the original Mol object 
and write that instead. This will allow you to retain the original 
properties. Please note that I haven't tried to run my own sample code 
below, so please bear with me if it does not quite work as is, but it 
was just to give you an idea how to achieve your goal:



def copy_coords(from, to):
    for i in range(from.GetNumAtoms()):
    to.SetAtomPosition(i, from.GetAtomPosition(i))

w = Chem.SDWriter(“aligned.sdf”)
nconfs = len(allconfs.GetConformers())
i = 0
for conf in confs:   # loop over my sdf files
    suppl = Chem.SDMolSupplier(conf, removeHs = False)
    if “_c0.sdf” in conf:
    copy_coords(allconfs.GetConformer(0), suppl[0].GetConformer())
    w.write(suppl[0])
    else:
    for mol in suppl:
    i += 1
    if (i == nconfs):
    raise RuntimeError('Something went wrong, i = nconfs = 
{0:d}'.format(nconfs))

    copy_coords(allconfs.GetConformer(i), mol.GetConformer())
    w.write(mol)
w.close()

**
HTH, Cheers,
p.

On 05/23/18 09:11, Udvarhelyi, Aniko wrote:


Dear Greg,

I have separate SDF files of conformers of the same molecule (they are 
called _c0.sdf, _c1.sdf, _c2.sdf and so on), with a few 
properties for each conformer. I am using the following code to read 
them into RDKit and align them:


*for conf in confs:   # loop over my sdf files*

*    suppl = Chem.SDMolSupplier(conf, removeHs = False)*

*    if “_c0.sdf” in conf:*

*    allconfs = suppl[0]*

*    else:*

*    for i,mol in enumerate(suppl):*

*allconfs.AddConformer(mol.GetConformer(), assignId = True)*

And then I am using *AllChem.AlignMolConformers(allconfs)*to align the 
conformers. It all works fine BUT: when I save the aligned conformers 
with the SDWriter, all the conformers have the properties of the very 
first conformer. What should I do to keep the original SDF properties 
of the conformers from before the alignment? Does AddConformer lose 
the properties or is something wrong with how I write them out? I am 
using the following to save the aligned conformers into one sdf:


*w = Chem.SDWriter(“aligned.sdf”)*

*for conf_id in range(len(allconf.GetConformers)):*

*    w.write(allconfs, confId=conf_id)*

*w.close()*

What should I do to have all the original SDF properties from the 
initial conformers in the aligned.sdf file?


Many thanks and best regards,

Anikó



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot


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


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


[Rdkit-discuss] Does AddConformer function lose SDF properties of conformers when adding them?

2018-05-23 Thread Udvarhelyi, Aniko
Dear Greg,

I have separate SDF files of conformers of the same molecule (they are called 
_c0.sdf, _c1.sdf, _c2.sdf and so on), with a few properties for 
each conformer. I am using the following code to read them into RDKit and align 
them:

for conf in confs:   # loop over my sdf files
suppl = Chem.SDMolSupplier(conf, removeHs = False)
if “_c0.sdf” in conf:
allconfs = suppl[0]
else:
for i,mol in enumerate(suppl):
allconfs.AddConformer(mol.GetConformer(), assignId = True)

And then I am using AllChem.AlignMolConformers(allconfs) to align the 
conformers. It all works fine BUT: when I save the aligned conformers with the 
SDWriter, all the conformers have the properties of the very first conformer. 
What should I do to keep the original SDF properties of the conformers from 
before the alignment? Does AddConformer lose the properties or is something 
wrong with how I write them out? I am using the following to save the aligned 
conformers into one sdf:

w = Chem.SDWriter(“aligned.sdf”)
for conf_id in range(len(allconf.GetConformers)):
w.write(allconfs, confId=conf_id)
w.close()

What should I do to have all the original SDF properties from the initial 
conformers in the aligned.sdf file?

Many thanks and best regards,
Anikó

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss