[Open Babel] splitting molecule file - the hard case

2015-11-10 Thread Filip Stefaniak
Hi,
I have a mol2 file:
https://gist.github.com/filipsPL/0b936f4d416bdc45ebea

There are three apparently separate molecules inside. But I'm not able
to separate them. obabel -m doesn't solve the problem.

I've tried to do it in python with pybel, but I don't know how to
exactly code it (it is not the simple case as described here:
https://openbabel.org/docs/dev/UseTheLibrary/PythonExamples.html#split-an-sdf-file-using-the-molecule-titles)

In pybel I can see that the molecules are actually separated somehow:

from pybel import *
mol = readfile("mol2", "ligand.mol2").next()
print mol

result is:
[Rh](N)(N)(N)(N)(N)N.[Rh](N)(N)(N)(N)(N)N.[Rh](N)(N)(N)(N)(N)N

so my question is: how to separate this mol2 file into separate
components? python or shell methods are acceptable.

thank you for any tips,
Filip


-- 
Filip Stefaniak
Uptime: 13185 dni 16 godzin
W lodówce ma 8.8stC, na działce w sadku 12.2stC

--
___
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss


Re: [Open Babel] splitting molecule file - the hard case

2015-11-10 Thread Maciek Wójcikowski
Hi Filip,

OBMol has a Separate method, which does exactly what you'd like.
http://openbabel.org/dev-api/classOpenBabel_1_1OBMol.shtml#a1e5c6955a32c0ec2317a8de12ab7ba5a

import pybel
> mol = pybel.readfile('mol2', 'ligand.mol2').next()
> for m in mol.OBMol.Separate():
> print m


Note that m is an OBMol object, so to get pybel molecule you need to
initiate it via Molecule class:

for m in mol.OBMol.Separate():
> print pybel.Molecule(m)





Pozdrawiam,  |  Best regards,
Maciek Wójcikowski
mac...@wojcikowski.pl

2015-11-10 16:59 GMT+01:00 Filip Stefaniak :

> Hi,
> I have a mol2 file:
> https://gist.github.com/filipsPL/0b936f4d416bdc45ebea
>
> There are three apparently separate molecules inside. But I'm not able
> to separate them. obabel -m doesn't solve the problem.
>
> I've tried to do it in python with pybel, but I don't know how to
> exactly code it (it is not the simple case as described here:
>
> https://openbabel.org/docs/dev/UseTheLibrary/PythonExamples.html#split-an-sdf-file-using-the-molecule-titles
> )
>
> In pybel I can see that the molecules are actually separated somehow:
>
> from pybel import *
> mol = readfile("mol2", "ligand.mol2").next()
> print mol
>
> result is:
> [Rh](N)(N)(N)(N)(N)N.[Rh](N)(N)(N)(N)(N)N.[Rh](N)(N)(N)(N)(N)N
>
> so my question is: how to separate this mol2 file into separate
> components? python or shell methods are acceptable.
>
> thank you for any tips,
> Filip
>
>
> --
> Filip Stefaniak
> Uptime: 13185 dni 16 godzin
> W lodówce ma 8.8stC, na działce w sadku 12.2stC
>
>
> --
> ___
> OpenBabel-discuss mailing list
> OpenBabel-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>
--
___
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss


Re: [Open Babel] splitting molecule file - the hard case

2015-11-10 Thread Filip Stefaniak
Hi Maciek,

Maciek Wójcikowski pisze:
> Hi Filip,
> 
> OBMol has a Separate method, which does exactly what you'd
> like. 
> http://openbabel.org/dev-api/classOpenBabel_1_1OBMol.shtml#a1e5c6955a32c0ec2317a8de12ab7ba5a
> 
> import pybel
> mol = pybel.readfile('mol2', 'ligand.mol2').next()
> for m in mol.OBMol.Separate():
> print m
> 
> 
> Note that m is an OBMol object, so to get pybel molecule you need to
> initiate it via Molecule class:
> 
> for m in mol.OBMol.Separate():
> print pybel.Molecule(m)

Thanks for that tip. I will try it.

best regards,
Filip


-- 
Filip Stefaniak
Uptime: 13079 dni 19 godzin
W lodówce ma 10.8stC, na działce w sadku 16.7stC

--
___
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss


Re: [Open Babel] splitting molecule file - the hard case

2015-11-10 Thread Maciek Wójcikowski
FYI The obabel -m option you've used separates molecules in multi-mol2 file
- the molecules must already be in separate molecule blocks.


Pozdrawiam,  |  Best regards,
Maciek Wójcikowski
mac...@wojcikowski.pl

2015-11-10 19:54 GMT+01:00 Filip Stefaniak :

> Hi Maciek,
>
> Maciek Wójcikowski pisze:
> > Hi Filip,
> >
> > OBMol has a Separate method, which does exactly what you'd
> > like.
> http://openbabel.org/dev-api/classOpenBabel_1_1OBMol.shtml#a1e5c6955a32c0ec2317a8de12ab7ba5a
> >
> > import pybel
> > mol = pybel.readfile('mol2', 'ligand.mol2').next()
> > for m in mol.OBMol.Separate():
> > print m
> >
> >
> > Note that m is an OBMol object, so to get pybel molecule you need to
> > initiate it via Molecule class:
> >
> > for m in mol.OBMol.Separate():
> > print pybel.Molecule(m)
>
> Thanks for that tip. I will try it.
>
> best regards,
> Filip
>
>
> --
> Filip Stefaniak
> Uptime: 13079 dni 19 godzin
> W lodówce ma 10.8stC, na działce w sadku 16.7stC
>
>
> --
> ___
> OpenBabel-discuss mailing list
> OpenBabel-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>
--
___
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss


Re: [Open Babel] splitting molecule file - the hard case

2015-11-12 Thread Filip Stefaniak
On 11/10/2015 05:23 PM, Maciek Wójcikowski wrote:
> Hi Filip,
> 
> OBMol has a Separate method, which does exactly what you'd
> like. 
> http://openbabel.org/dev-api/classOpenBabel_1_1OBMol.shtml#a1e5c6955a32c0ec2317a8de12ab7ba5a
> 
> import pybel
> mol = pybel.readfile('mol2', 'ligand.mol2').next()
> for m in mol.OBMol.Separate():
> print m
> 
> 
> Note that m is an OBMol object, so to get pybel molecule you need to
> initiate it via Molecule class:
> 
> for m in mol.OBMol.Separate():
> print pybel.Molecule(m)
> 
> 

Thanks once more. Just for future reference, here is the full script for
splitting molecule and saving it to separate files:
https://gist.github.com/filipsPL/5c810a452559a7fcc99e


import pybel
from openbabel import *

mol = pybel.readfile('mol2', 'ligand.mol2').next()
separated = mol.OBMol.Separate()

def writeOut( theConformer, outputPath ):
  myConversion = OBConversion()
  outputFormat = myConversion.FormatFromExt( outputPath )
  myConversion.SetOutFormat( outputFormat )
  myConversion.WriteFile( theConformer, outputPath )

i = 0
for singlemol in separated:
  i+=1
  print "Writing part %i" % (i)
  writeOut(singlemol, "output-%i.mol2" %(i) )



bests,
Filip

-- 
Filip Stefaniak
Uptime: 13187 dni 13 godzin
W lodówce ma 9.7stC, na działce w sadku 11.2stC

--
___
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss