From e280afb076b1676ac5edebd1de351e8f49767f99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=BCller?= Date: Wed, 22 Jun 2016 14:47:24 +0200 Subject: [PATCH] Return iterative resisue ids from tpr files. Since Gromacs doesn't care about the residue number in gro files, they are not stored in the tpr files and thus have to be reproduced by hand. This solution increases the residue index with each new molecule. --- pygmx/tpxio.pyx | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/pygmx/tpxio.pyx b/pygmx/tpxio.pyx index 7656452..370f6ce 100644 --- a/pygmx/tpxio.pyx +++ b/pygmx/tpxio.pyx @@ -49,38 +49,32 @@ cdef atoms_from_topology(gmx_mtop_t *topology): int moltype, resind atoms = [] - masses = [] - charges = [] residues = [] + res_id = 0 for i_molblock in range(topology.nmolblock): moltype = topology.molblock[i_molblock].type - c_atoms = topology.moltype[moltype].atoms - mol_atoms = [] - mol_q = [] - mol_m = [] - for i_atom in range(c_atoms.nr): - resind = c_atoms.atom[i_atom].resind - resname = c_atoms.resinfo[resind].name[0] - if resname not in residues: - residues.append(resname) - resid = residues.index(resname) + 1 - mol_atoms.append(( - resid, - resname, - c_atoms.atomname[i_atom][0], - )) - mol_q.append(c_atoms.atom[i_atom].q) - mol_m.append(c_atoms.atom[i_atom].m) - n_mol = topology.molblock[i_molblock].nmol - atoms += mol_atoms * n_mol - charges += mol_q * n_mol - masses += mol_m * n_mol - + for n in range(topology.molblock[i_molblock].nmol): + mol_atoms = [] + res_id += 1 + for i_atom in range(c_atoms.nr): + resind = c_atoms.atom[i_atom].resind + resname = c_atoms.resinfo[resind].name[0] + if resname not in residues: + residues.append(resname) + resid = residues.index(resname) + 1 + mol_atoms.append(( + res_id, + resname, + c_atoms.atomname[i_atom][0], + )) + atoms += mol_atoms return np.array(atoms) + ctypedef object (*atom_func)(t_atom) + cdef atom_charge(t_atom atom): return atom.q