[chimera-dev] writing atom information using the mol2 atom order.

Eric Pettersen pett at cgl.ucsf.edu
Tue Nov 3 10:11:58 PST 2009

Hi JD,
	One typically takes the list of atoms, sorts them, and then runs  
through the sorted list.  Like this:

atoms = molecule.atoms
atoms.sort(lambda a1, a2: cmp(a1.serialNumber, a2.serialNumber))
for atom in atoms:


Note that 'molecule.atoms' always returns a copy of the atom list, so  
you can't do this:

for atom in molecule.atoms:

because the first line sorted a _copy_ of the atom list, and the  
second line returns another copy of the original (unsorted) list.

On Nov 3, 2009, at 6:20 AM, Jean Didier Pie Marechal wrote:

> Dear all,
> I have a mol2 file and I would like to generate an input for an  
> external program using chimera. For a great ease in practicability,  
> I would like the mol2 order to be kept.
> I used the following artefact to get to what I want:
> def input(molecule):
>    ##for compatibility with mol2 atom ordering I use the doble loop  
> as follow
>    ##makes the writing substantially slower, but yet the  
> compatibility with mol2 format seems absolute.
>    for i in range(len(molecule.atoms)):
>        for atoms in molecule.atoms:
>            if atoms.serialNumber == i:
>                text=str(atoms.element)+"-"+str(atoms.gaffType) 
> +"-"+str(atoms.charge)+"    "+str(atoms.flex)+"     
> "+str(atoms.coord()) +"\n"
>                filename.write(text)
>        i=i+1
> I think I could order directly the writing in function of the  
> serialNumber (which is preserved regarding the mol2) file. But how  
> could I do this?
> Best,
> JD

More information about the Chimera-dev mailing list