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:[email protected]]
*Sent:* Mittwoch, 23. Mai 2018 11:41
*To:* Udvarhelyi, Aniko; Greg Landrum
*Cc:* [email protected]
*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 xxxx_c0.sdf, xxxx_c1.sdf, xxxx_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&d=DwMDaQ&c=ZbgFmJjg4pdtrnL2HUJUDw&r=ANfhdkzkLaTzqQrdJ1uJyFwAJDWEMRAEFydqudcLj6o&m=CZ6lBy8QxadPv6cUeoQ6ww4N4oaJ_g7z52waY421iNc&s=1NSYUS7IRMb60DuSVz4HNeUeGacas8a4g-iByKmIpvM&e=>




    _______________________________________________

    Rdkit-discuss mailing list

    [email protected]
    <mailto:[email protected]>

    https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
    
<https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.sourceforge.net_lists_listinfo_rdkit-2Ddiscuss&d=DwMDaQ&c=ZbgFmJjg4pdtrnL2HUJUDw&r=ANfhdkzkLaTzqQrdJ1uJyFwAJDWEMRAEFydqudcLj6o&m=CZ6lBy8QxadPv6cUeoQ6ww4N4oaJ_g7z52waY421iNc&s=98K16KJhJ56rnSPodST5uecP_uGyssxzLr8CuCTfHI8&e=>


------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to