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:
1 parent
d30de6e364
commit
e280afb076
1 file changed
+18
-24
+18
-24
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user