示例#1
0
static int write_tng_structure(void *v, int optflags, const molfile_atom_t *atoms)
{
    /* VMD atoms do not contain molecule information, which
     * complicates TNG writing a bit. */
    tng_molecule_t tng_mol;
    tng_chain_t tng_chain;
    tng_residue_t tng_residue;
    tng_atom_t tng_atom;

    tngdata *tng = (tngdata *)v;

    /* A dummy molecule must be added. All atoms will be added to it. */
    tng_molecule_add(tng->tng_traj, "MOL", &tng_mol);
    for(int i = 0; i < tng->natoms; i++)
    {
        if(tng_molecule_chain_find(tng->tng_traj, tng_mol, atoms[i].chain, -1, &tng_chain) !=
            TNG_SUCCESS)
        {
            tng_molecule_chain_add(tng->tng_traj, tng_mol, atoms[i].chain, &tng_chain);
        }
        if (tng_chain_residue_find(tng->tng_traj, tng_chain, atoms[i].resname,
                                   atoms[i].resid, &tng_residue) != TNG_SUCCESS)
        {
            tng_chain_residue_w_id_add(tng->tng_traj, tng_chain, atoms[i].resname,
                                       atoms[i].resid, &tng_residue);
        }
        tng_residue_atom_add(tng->tng_traj, tng_residue, atoms[i].name, atoms[i].type, &tng_atom);
    }

    return MOLFILE_SUCCESS;
}
示例#2
0
static void addTngMoleculeFromTopology(tng_trajectory_t     tng,
                                       const char          *moleculeName,
                                       const t_atoms       *atoms,
                                       gmx_int64_t          numMolecules,
                                       tng_molecule_t      *tngMol)
{
    if (tng_molecule_add(tng, moleculeName, tngMol) != TNG_SUCCESS)
    {
        gmx_file("Cannot add molecule to TNG molecular system.");
    }

    /* FIXME: The TNG atoms should contain mass and atomB info (for free
     * energy calculations), i.e. in when it's available in TNG (2.0). */
    for (int atomIt = 0; atomIt < atoms->nr; atomIt++)
    {
        const t_atom *at = &atoms->atom[atomIt];
        /* FIXME: Currently the TNG API can only add atoms belonging to a
         * residue and chain. Wait for TNG 2.0*/
        if (atoms->nres > 0)
        {
            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;

            if (tng_molecule_chain_find (tng, *tngMol, chainName,
                                         (gmx_int64_t)-1, &tngChain) !=
                TNG_SUCCESS)
            {
                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*/
            if (tng_chain_residue_find(tng, tngChain, *resInfo->name,
                                       at->resind + 1, &tngRes)
                != TNG_SUCCESS)
            {
                tng_chain_residue_add(tng, tngChain, *resInfo->name, &tngRes);
            }
            tng_residue_atom_add(tng, tngRes, *(atoms->atomname[atomIt]), *(atoms->atomtype[atomIt]), &tngAtom);
        }
    }
    tng_molecule_cnt_set(tng, *tngMol, numMolecules);
}