From: Magnus Lundborg Date: Thu, 19 Jun 2014 08:56:00 +0000 (+0200) Subject: Improved check to decide if to add chain/residue. X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=4aa9a80630f2084a1fe6f509aa3f610e75f99d4f;p=alexxy%2Fgromacs.git Improved check to decide if to add chain/residue. Together with the latest TNG library updates this fixes #1507 Change-Id: Iea7160cc1194fc398f9c4db0cc66f4bd43ce724a --- diff --git a/src/gromacs/fileio/tngio.cpp b/src/gromacs/fileio/tngio.cpp index 6cba319816..da7a7f12fb 100644 --- a/src/gromacs/fileio/tngio.cpp +++ b/src/gromacs/fileio/tngio.cpp @@ -189,6 +189,9 @@ static void addTngMoleculeFromTopology(tng_trajectory_t tng, gmx_int64_t numMolecules, tng_molecule_t *tngMol) { + tng_chain_t tngChain = NULL; + tng_residue_t tngRes = NULL; + if (tng_molecule_add(tng, moleculeName, tngMol) != TNG_SUCCESS) { gmx_file("Cannot add molecule to TNG molecular system."); @@ -205,24 +208,32 @@ static void addTngMoleculeFromTopology(tng_trajectory_t tng, { const t_resinfo *resInfo = &atoms->resinfo[at->resind]; char chainName[2] = {resInfo->chainid, 0}; - tng_chain_t tngChain = NULL; - tng_residue_t tngRes = NULL; tng_atom_t tngAtom = NULL; + t_atom *prevAtom; - if (tng_molecule_chain_find (tng, *tngMol, chainName, - (gmx_int64_t)-1, &tngChain) != - TNG_SUCCESS) + if (atomIndex > 0) + { + prevAtom = &atoms->atom[atomIndex - 1]; + } + else { - tng_molecule_chain_add (tng, *tngMol, chainName, - &tngChain); + prevAtom = 0; } - /* FIXME: When TNG supports both residue index and residue - * number the latter should be used. Wait for TNG 2.0*/ - if (tng_chain_residue_find(tng, tngChain, *resInfo->name, - at->resind + 1, &tngRes) - != TNG_SUCCESS) + /* If this is the first atom or if the residue changed add the + * residue to the TNG molecular system. */ + if (!prevAtom || resInfo != &atoms->resinfo[prevAtom->resind]) { + /* If this is the first atom or if the chain changed add + * the chain to the TNG molecular system. */ + if (!prevAtom || resInfo->chainid != + atoms->resinfo[prevAtom->resind].chainid) + { + tng_molecule_chain_add(tng, *tngMol, chainName, + &tngChain); + } + /* FIXME: When TNG supports both residue index and residue + * number the latter should be used. Wait for TNG 2.0*/ tng_chain_residue_add(tng, tngChain, *resInfo->name, &tngRes); } tng_residue_atom_add(tng, tngRes, *(atoms->atomname[atomIndex]), *(atoms->atomtype[atomIndex]), &tngAtom);