Use the Python keyword "next" on an iterator to get the next item:

mol1 = next(pybel.readfile(....)

You can add an OBMol to an existing one:

m1 += m2

I'd recommend writing it out as SMILES at this point, just to check the
structure:

print(pybel.Molecule(m1).write("smi"))

If the hydrogens are explicit in the XYZ, then you can call DeleteAtom() on
the hydrogens to delete them. To create a bond, use AddBond(). See the
Doxygen documentation.

- Noel

On Wed, 8 Apr 2020 at 17:31, Marco Di Gennaro (TME) <
marco.di.genn...@external.toyota-europe.com> wrote:

> Hello everyone,
>
>
>
> I have two molecules (benzene and methane) in two separate xyz files.
>
> I would like to create a methylbenzene molecule out of these and relax it
> with a UFF.
>
> I am new to pybel (and babel in general). I would like to:
>
>    - open the two files
>    - remove one hydrogen from the benzene and one from the methane
>    - create a bond among the two carbons
>    - perform UFF relaxation.
>
>
>
> So far I have tried several things, mostly trying to follow this
> discussion (which is a bit outdated actually):
> http://forums.openbabel.org/OBGenericData-and-OBPairData-td4651441.html#a4651899
>
> I could not get much out of it for the moment:
>
>    - I could read the files with readfile(), but why do I get an iterator?
>    - Is OBBuilder() what I am looking for? How to use it properly?
>    - Should I rather use OBPairData() ?
>    - I know I can use -d to remove (all) hydrogens in babel. How do I do
>    it for specific atoms in pybel?
>
>
>
> Below you can find the little code I could write at the moment. I am
> attaching the two xyz files.
>
> Any help would be greatly appreciated.
>
> Thank you.
>
> Marco
>
>
>
> import pybel as pb
>
> mol1 = [ m for m in pb.readfile('xyz', 'benzene.xyz')][0]
>
> mol2 = [ m for m in pb.readfile('xyz', 'methane.xyz')][0]
>
>
>
> mol1 + mol2 # This gives a TypeError: unsupported operand type(s) for +:
> ‘Molecule’ and ‘Molecule’
>
>
>
> m1 = mol1.OBMol
>
> m2 = mol2.OBMol
>
> m3 = m1 + m2  # This gives a TypeError: unsupported operand type(s) for +:
> ‘OBMol’ and ‘OBMol’
>
>
>
>
>
>
>
> ==
>
> Marco Di Gennaro, Ph.D.
>
> Toyota Motor Europe
>
>
>
> This e-mail may contain confidential information. If you are not an
> addressee or otherwise authorised to receive this message, you should not
> use, copy, disclose or take any action based on this e-mail. If you have
> received this e-mail in error, please inform the sender promptly and delete
> this message and any attachments immediately.
> _______________________________________________
> 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

Reply via email to