Submolecule from OBMol

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Submolecule from OBMol

mwojcikowski
Hi all,

Quick question: I have OBMol and want to create a sub-molecule from a subset of atoms given by atom/bond indices. Is there a clever way to do it in OpenBabel? I'm aware that I can make a copy and prune the unwanted atoms ;)

----
Pozdrawiam,  |  Best regards,
Maciek Wójcikowski
[hidden email]

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Submolecule from OBMol

Noel O'Boyle
Administrator
This would be a useful API function.

If it's a disconnected portion of the molecule, and you wanted to
write a smiles, there is a fragment option for the smiles writer that
you could use.

- Noel

On 17 June 2017 at 21:44, Maciek Wójcikowski <[hidden email]> wrote:

> Hi all,
>
> Quick question: I have OBMol and want to create a sub-molecule from a subset
> of atoms given by atom/bond indices. Is there a clever way to do it in
> OpenBabel? I'm aware that I can make a copy and prune the unwanted atoms ;)
>
> ----
> Pozdrawiam,  |  Best regards,
> Maciek Wójcikowski
> [hidden email]
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> OpenBabel-discuss mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Submolecule from OBMol

mwojcikowski
I'm trying to get back the ECFP environments, most preferably as smiles. So it's literally a list of connected atoms.

The dumb solution goes as follows:

def submol(mol, idxs):
    mol_clone = mol.clone
    mol_clone.OBMol.BeginModify()
    delete_atoms = []
    for i in reversed(range(len(mol.atoms))):
        if i in idxs:
            continue
        delete_atoms.append(mol_clone.OBMol.GetAtomById(i))
    for atom in delete_atoms:
        mol_clone.OBMol.DeleteAtom(atom)
    mol_clone.OBMol.BeginModify()
    return mol_clone

----
Pozdrawiam,  |  Best regards,
Maciek Wójcikowski
[hidden email]

2017-06-19 15:53 GMT+02:00 Noel O'Boyle <[hidden email]>:
This would be a useful API function.

If it's a disconnected portion of the molecule, and you wanted to
write a smiles, there is a fragment option for the smiles writer that
you could use.

- Noel

On 17 June 2017 at 21:44, Maciek Wójcikowski <[hidden email]> wrote:
> Hi all,
>
> Quick question: I have OBMol and want to create a sub-molecule from a subset
> of atoms given by atom/bond indices. Is there a clever way to do it in
> OpenBabel? I'm aware that I can make a copy and prune the unwanted atoms ;)
>
> ----
> Pozdrawiam,  |  Best regards,
> Maciek Wójcikowski
> [hidden email]
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> OpenBabel-discuss mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Submolecule from OBMol

mwojcikowski
The last BeginModify should be EndModify.

----
Pozdrawiam,  |  Best regards,
Maciek Wójcikowski
[hidden email]

2017-06-19 16:39 GMT+02:00 Maciek Wójcikowski <[hidden email]>:
I'm trying to get back the ECFP environments, most preferably as smiles. So it's literally a list of connected atoms.

The dumb solution goes as follows:

def submol(mol, idxs):
    mol_clone = mol.clone
    mol_clone.OBMol.BeginModify()
    delete_atoms = []
    for i in reversed(range(len(mol.atoms))):
        if i in idxs:
            continue
        delete_atoms.append(mol_clone.OBMol.GetAtomById(i))
    for atom in delete_atoms:
        mol_clone.OBMol.DeleteAtom(atom)
    mol_clone.OBMol.BeginModify()
    return mol_clone

----
Pozdrawiam,  |  Best regards,
Maciek Wójcikowski
[hidden email]

2017-06-19 15:53 GMT+02:00 Noel O'Boyle <[hidden email]>:
This would be a useful API function.

If it's a disconnected portion of the molecule, and you wanted to
write a smiles, there is a fragment option for the smiles writer that
you could use.

- Noel

On 17 June 2017 at 21:44, Maciek Wójcikowski <[hidden email]> wrote:
> Hi all,
>
> Quick question: I have OBMol and want to create a sub-molecule from a subset
> of atoms given by atom/bond indices. Is there a clever way to do it in
> OpenBabel? I'm aware that I can make a copy and prune the unwanted atoms ;)
>
> ----
> Pozdrawiam,  |  Best regards,
> Maciek Wójcikowski
> [hidden email]
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> OpenBabel-discuss mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Submolecule from OBMol

Andrew Dalke
In reply to this post by mwojcikowski
On Jun 19, 2017, at 16:39, Maciek Wójcikowski <[hidden email]> wrote:
>
> I'm trying to get back the ECFP environments, most preferably as smiles. So it's literally a list of connected atoms.
>
> The dumb solution goes as follows:
>
> def submol(mol, idxs):

Perhaps you want Chem.MolFragmentToSmiles(mol, atomsToUse=idxs)?

http://www.rdkit.org/docs-beta/api/rdkit.Chem.rdmolfiles-module.html#MolFragmentToSmiles




                                Andrew
                                [hidden email]



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Submolecule from OBMol

Geoff Hutchison
In reply to this post by Noel O'Boyle
> If it's a disconnected portion of the molecule, and you wanted to
> write a smiles, there is a fragment option for the smiles writer that
> you could use.

It doesn't have to be a disconnected portion. That feature to the SMILES writer will take a bit mask for the fragment -- it can be any combination of atoms as a mask onto the OBMol.

-Geoff
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Submolecule from OBMol

Andrew Dalke
In reply to this post by Andrew Dalke
Me:
> Perhaps you want Chem.MolFragmentToSmiles(mol, atomsToUse=idxs)?
>
> http://www.rdkit.org/docs-beta/api/rdkit.Chem.rdmolfiles-module.html#MolFragmentToSmiles

Err, umm, *blush*. Forgot which list I was reading.

[Andrew! It says it right in the subject line! :]

                                Andrew
                                [hidden email]


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Submolecule from OBMol

Noel O'Boyle
Administrator
In reply to this post by Geoff Hutchison
Actually, for the task described, it's perfect. It can take any
subset, but I was hesitant to suggest it as it doesn't give the same
results as subsetting the molecule (e.g. you can have a portion of an
aromatic ring).

- Noel

On 19 June 2017 at 16:07, Geoffrey Hutchison <[hidden email]> wrote:

>> If it's a disconnected portion of the molecule, and you wanted to
>> write a smiles, there is a fragment option for the smiles writer that
>> you could use.
>
> It doesn't have to be a disconnected portion. That feature to the SMILES writer will take a bit mask for the fragment -- it can be any combination of atoms as a mask onto the OBMol.
>
> -Geoff
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> OpenBabel-discuss mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Submolecule from OBMol

mwojcikowski
In reply to this post by Andrew Dalke
No worries :) I planned to do Chem.FindAtomEnvironmentOfRadiusN() and Chem.PathToSubMol() in RDKit, but the function you've suggested is also feasible.

@Geoff - the smiles fragment does not perserve any bond information from what I've tested so far.

----
Pozdrawiam,  |  Best regards,
Maciek Wójcikowski
[hidden email]

2017-06-19 17:12 GMT+02:00 Andrew Dalke <[hidden email]>:
Me:
> Perhaps you want Chem.MolFragmentToSmiles(mol, atomsToUse=idxs)?
>
> http://www.rdkit.org/docs-beta/api/rdkit.Chem.rdmolfiles-module.html#MolFragmentToSmiles

Err, umm, *blush*. Forgot which list I was reading.

[Andrew! It says it right in the subject line! :]

                                Andrew
                                [hidden email]


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Submolecule from OBMol

mwojcikowski
I was wrong, the "F" option retains bonds' order and it even works for aromatic atoms.
For future reference, to generate smiles of fragment by atom indices in Python you can do:
idxs = [1,2,3,4]
mol.write('smi', opt={'F': ' '.join(map(str, idxs))}).strip()

----
Pozdrawiam,  |  Best regards,
Maciek Wójcikowski
[hidden email]

2017-06-19 17:19 GMT+02:00 Maciek Wójcikowski <[hidden email]>:
No worries :) I planned to do Chem.FindAtomEnvironmentOfRadiusN() and Chem.PathToSubMol() in RDKit, but the function you've suggested is also feasible.

@Geoff - the smiles fragment does not perserve any bond information from what I've tested so far.

----
Pozdrawiam,  |  Best regards,
Maciek Wójcikowski
[hidden email]

2017-06-19 17:12 GMT+02:00 Andrew Dalke <[hidden email]>:
Me:
> Perhaps you want Chem.MolFragmentToSmiles(mol, atomsToUse=idxs)?
>
> http://www.rdkit.org/docs-beta/api/rdkit.Chem.rdmolfiles-module.html#MolFragmentToSmiles

Err, umm, *blush*. Forgot which list I was reading.

[Andrew! It says it right in the subject line! :]

                                Andrew
                                [hidden email]


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Submolecule from OBMol

Geoff Hutchison
I was wrong, the "F" option retains bonds' order and it even works for aromatic atoms.
For future reference, to generate smiles of fragment by atom indices in Python you can do:
idxs = [1,2,3,4]
mol.write('smi', opt={'F': ' '.join(map(str, idxs))}).strip()


Yes, this method was from Craig James for fragment-based fingerprints, IIRC. It would be nice to get it up into OBMol as well.

-Geoff

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss