Re: [Rdkit-discuss] MolToSmiles preserve atom order

2019-11-18 Thread Andrew Dalke
On Nov 18, 2019, at 17:40, David Cosgrove  wrote:
> 
> Point taken. I don’t think you’d be able to get RDKit to spit such SMILES 
> strings out unless you tortured it pretty hard, however. 

Did someone mention one of my favorite things to do? :)  See:

  
http://dalkescientific.com/writings/diary/archive/2010/12/28/reordering_smiles.html

Note that that code does not preserve stereochemistry.

It's for Python 2, so change the:

  available_closures = range(100)

to

 available_closures = list(range(100))

to make it work under Python 3.

Here's what it looks like:

>>> from x import reordered_smiles
>>> from rdkit import Chem
>>> mol = Chem.MolFromSmiles("OCCl")
>>> atoms = list(mol.GetAtoms())
>>> reordered_smiles(mol, [atoms[1], atoms[0], atoms[2]])
'[CH2]12.[OH1]1.[Cl]2'



Andrew
da...@dalkescientific.com




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


Re: [Rdkit-discuss] MolToSmiles preserve atom order

2019-11-18 Thread Rafal Roszak
On Mon, 18 Nov 2019 16:40:28 +
David Cosgrove  wrote:

> Point taken. I don’t think you’d be able to get RDKit to spit such SMILES
> strings out unless you tortured it pretty hard, however.

Export smiles with arbitrary given atom order is diffrent problem.
Normally working with mol object you dont remove any bond, but rather
you change atoms properties (such as isotope, AtomMapNum, explicitHs
and so on). I want to show some simple example but in simple cases
MolToSmiles with rootedAtAtom=0, canonical=False preserve atom order.
I found one example when it didn't work as I expected (atom order was
altered) but it seems I lost this smiles. 
Anyway, is such code:

mol=Chem.MolFromSmiles(someSmilesString)
change_properties_of_some_atoms_in_mol(mol) #this function changes isotopes of 
selected atoms
smiles2 = Chem.MolToSmiles(mol, rootedAtAtom=0, canonical=False)
mol_from_smiles2 = Chem.MolFromSmiles(smiles2)

atom order (or atom indices returned by GetIdx() function) should be the same 
or it can be diffrent?


best,

Rafal


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


Re: [Rdkit-discuss] MolToSmiles preserve atom order

2019-11-18 Thread David Cosgrove
Hi Rocco,
Point taken. I don’t think you’d be able to get RDKit to spit such SMILES
strings out unless you tortured it pretty hard, however.
Dave


On Mon, 18 Nov 2019 at 16:36, Rocco Moretti  wrote:

> Actually, it is possible to get arbitrary orders, if you (ab)use the '.'
> component ("zero order bond") directive and the numeric bonding ("ring
> closure") directives:
>
> >>> Chem.MolToSmiles( Chem.MolFromSmiles("O1.Cl2.C12" ) )
> 'OCCl'
>
> Whether you want to do things that way is another question.
>
> On Mon, Nov 18, 2019 at 10:24 AM David Cosgrove <
> davidacosgrov...@gmail.com> wrote:
>
>> Hi Rafal,
>> It is not always possible to preserve the atom ordering in the SMILES
>> string because there is an implied bond between contiguous symbols in the
>> SMILES. I think, for example, that the molecule with the SMILES OCCl
>> couldn’t have the order in the molecule object O first, Cl second, C third,
>> with bonds between 1 and 3 and 2 and 3 and get the SMILES in that order.
>>
>> I hope that made sense. Please ask again if not.
>>
>> Best regards,
>> Dave
>>
>>
>> On Mon, 18 Nov 2019 at 12:33, Rafal Roszak  wrote:
>>
>>> Hi all,
>>>
>>> Is there any way to preserve atom order from Mol object during
>>> exporting to smiles? I tried MolToSmiles with rootedAtAtom=0 and
>>> canonical=False options but it not always prevent oryginal order.
>>> I know I can use _smilesAtomOutputOrder to map old indices to new one
>>> in canonical smiles but maybe we have something more handy?
>>>
>>> Best,
>>>
>>> Rafał
>>>
>>>
>>> ___
>>> Rdkit-discuss mailing list
>>> Rdkit-discuss@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>>>
>> --
>> David Cosgrove
>> Freelance computational chemistry and chemoinformatics developer
>> http://cozchemix.co.uk
>>
>> ___
>> 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
>
-- 
David Cosgrove
Freelance computational chemistry and chemoinformatics developer
http://cozchemix.co.uk
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] MolToSmiles preserve atom order

2019-11-18 Thread Rocco Moretti
Actually, it is possible to get arbitrary orders, if you (ab)use the '.'
component ("zero order bond") directive and the numeric bonding ("ring
closure") directives:

>>> Chem.MolToSmiles( Chem.MolFromSmiles("O1.Cl2.C12" ) )
'OCCl'

Whether you want to do things that way is another question.

On Mon, Nov 18, 2019 at 10:24 AM David Cosgrove 
wrote:

> Hi Rafal,
> It is not always possible to preserve the atom ordering in the SMILES
> string because there is an implied bond between contiguous symbols in the
> SMILES. I think, for example, that the molecule with the SMILES OCCl
> couldn’t have the order in the molecule object O first, Cl second, C third,
> with bonds between 1 and 3 and 2 and 3 and get the SMILES in that order.
>
> I hope that made sense. Please ask again if not.
>
> Best regards,
> Dave
>
>
> On Mon, 18 Nov 2019 at 12:33, Rafal Roszak  wrote:
>
>> Hi all,
>>
>> Is there any way to preserve atom order from Mol object during
>> exporting to smiles? I tried MolToSmiles with rootedAtAtom=0 and
>> canonical=False options but it not always prevent oryginal order.
>> I know I can use _smilesAtomOutputOrder to map old indices to new one
>> in canonical smiles but maybe we have something more handy?
>>
>> Best,
>>
>> Rafał
>>
>>
>> ___
>> Rdkit-discuss mailing list
>> Rdkit-discuss@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>>
> --
> David Cosgrove
> Freelance computational chemistry and chemoinformatics developer
> http://cozchemix.co.uk
>
> ___
> 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] MolToSmiles preserve atom order

2019-11-18 Thread David Cosgrove
Hi Rafal,
It is not always possible to preserve the atom ordering in the SMILES
string because there is an implied bond between contiguous symbols in the
SMILES. I think, for example, that the molecule with the SMILES OCCl
couldn’t have the order in the molecule object O first, Cl second, C third,
with bonds between 1 and 3 and 2 and 3 and get the SMILES in that order.

I hope that made sense. Please ask again if not.

Best regards,
Dave


On Mon, 18 Nov 2019 at 12:33, Rafal Roszak  wrote:

> Hi all,
>
> Is there any way to preserve atom order from Mol object during
> exporting to smiles? I tried MolToSmiles with rootedAtAtom=0 and
> canonical=False options but it not always prevent oryginal order.
> I know I can use _smilesAtomOutputOrder to map old indices to new one
> in canonical smiles but maybe we have something more handy?
>
> Best,
>
> Rafał
>
>
> ___
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
-- 
David Cosgrove
Freelance computational chemistry and chemoinformatics developer
http://cozchemix.co.uk
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss