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.
This commit is contained in:
Niels Müller
2016-06-22 14:47:24 +02:00
parent d30de6e364
commit e280afb076

View File

@ -49,38 +49,32 @@ cdef atoms_from_topology(gmx_mtop_t *topology):
int moltype, resind int moltype, resind
atoms = [] atoms = []
masses = []
charges = []
residues = [] residues = []
res_id = 0
for i_molblock in range(topology.nmolblock): for i_molblock in range(topology.nmolblock):
moltype = topology.molblock[i_molblock].type moltype = topology.molblock[i_molblock].type
c_atoms = topology.moltype[moltype].atoms c_atoms = topology.moltype[moltype].atoms
mol_atoms = [] for n in range(topology.molblock[i_molblock].nmol):
mol_q = [] mol_atoms = []
mol_m = [] res_id += 1
for i_atom in range(c_atoms.nr): for i_atom in range(c_atoms.nr):
resind = c_atoms.atom[i_atom].resind resind = c_atoms.atom[i_atom].resind
resname = c_atoms.resinfo[resind].name[0] resname = c_atoms.resinfo[resind].name[0]
if resname not in residues: if resname not in residues:
residues.append(resname) residues.append(resname)
resid = residues.index(resname) + 1 resid = residues.index(resname) + 1
mol_atoms.append(( mol_atoms.append((
resid, res_id,
resname, resname,
c_atoms.atomname[i_atom][0], c_atoms.atomname[i_atom][0],
)) ))
mol_q.append(c_atoms.atom[i_atom].q) atoms += mol_atoms
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
return np.array(atoms) return np.array(atoms)
ctypedef object (*atom_func)(t_atom) ctypedef object (*atom_func)(t_atom)
cdef atom_charge(t_atom atom): cdef atom_charge(t_atom atom):
return atom.q return atom.q