コード例 #1
0
ファイル: tngplugin.C プロジェクト: tmd-gpat/MOLding
static int read_tng_structure(void *v, int *optflags,
                               molfile_atom_t *atoms)
{
    tngdata *tng = (tngdata *)v;
    char long_name[16], short_name[2];
    int64_t id;

    *optflags = MOLFILE_NOOPTIONS;
    for(int i = 0; i < tng->natoms; i++)
    {
        molfile_atom_t *atom = atoms+i;
        tng_atom_name_of_particle_nr_get(tng->tng_traj, i, long_name, 16);
        strcpy(atom->name, long_name);
        tng_atom_type_of_particle_nr_get(tng->tng_traj, i, long_name, 16);
        strcpy(atom->type, long_name);
        tng_residue_name_of_particle_nr_get(tng->tng_traj, i, long_name, 16);
        strcpy(atom->resname, long_name);
        tng_global_residue_id_of_particle_nr_get(tng->tng_traj, i, &id);
        atom->resid = (int)id;
//         fprintf(stderr, "resid: %d\n", (int)id);
        tng_chain_name_of_particle_nr_get(tng->tng_traj, i, short_name, 2);
        strcpy(atom->chain, short_name);
        atom->segid[0] = '\0';
    }
//     fprintf(stderr, "Structure opened\n");
    return MOLFILE_SUCCESS;
}
コード例 #2
0
void gmx_tng_setup_atom_subgroup(tng_trajectory_t tng,
                                 const int        nind,
                                 const int       *ind,
                                 const char      *name)
{
#if GMX_USE_TNG
    gmx_int64_t              nAtoms, cnt, nMols;
    tng_molecule_t           mol, iterMol;
    tng_chain_t              chain;
    tng_residue_t            res;
    tng_atom_t               atom;
    tng_function_status      stat;

    tng_num_particles_get(tng, &nAtoms);

    if (nAtoms == nind)
    {
        return;
    }

    stat = tng_molecule_find(tng, name, -1, &mol);
    if (stat == TNG_SUCCESS)
    {
        tng_molecule_num_atoms_get(tng, mol, &nAtoms);
        tng_molecule_cnt_get(tng, mol, &cnt);
        if (nAtoms == nind)
        {
            stat = TNG_SUCCESS;
        }
        else
        {
            stat = TNG_FAILURE;
        }
    }
    if (stat == TNG_FAILURE)
    {
        /* The indexed atoms are added to one separate molecule. */
        tng_molecule_alloc(tng, &mol);
        tng_molecule_name_set(tng, mol, name);
        tng_molecule_chain_add(tng, mol, "", &chain);

        for (int i = 0; i < nind; i++)
        {
            char        temp_name[256], temp_type[256];

            /* Try to retrieve the residue name of the atom */
            stat = tng_residue_name_of_particle_nr_get(tng, ind[i], temp_name, 256);
            if (stat != TNG_SUCCESS)
            {
                temp_name[0] = '\0';
            }
            /* Check if the molecule of the selection already contains this residue */
            if (tng_chain_residue_find(tng, chain, temp_name, -1, &res)
                != TNG_SUCCESS)
            {
                tng_chain_residue_add(tng, chain, temp_name, &res);
            }
            /* Try to find the original name and type of the atom */
            stat = tng_atom_name_of_particle_nr_get(tng, ind[i], temp_name, 256);
            if (stat != TNG_SUCCESS)
            {
                temp_name[0] = '\0';
            }
            stat = tng_atom_type_of_particle_nr_get(tng, ind[i], temp_type, 256);
            if (stat != TNG_SUCCESS)
            {
                temp_type[0] = '\0';
            }
            tng_residue_atom_w_id_add(tng, res, temp_name, temp_type, ind[i], &atom);
        }
        tng_molecule_existing_add(tng, &mol);
    }
    /* Set the count of the molecule containing the selected atoms to 1 and all
     * other molecules to 0 */
    tng_molecule_cnt_set(tng, mol, 1);
    tng_num_molecule_types_get(tng, &nMols);
    for (gmx_int64_t k = 0; k < nMols; k++)
    {
        tng_molecule_of_index_get(tng, k, &iterMol);
        if (iterMol == mol)
        {
            continue;
        }
        tng_molecule_cnt_set(tng, iterMol, 0);
    }
#else
    GMX_UNUSED_VALUE(tng);
    GMX_UNUSED_VALUE(nind);
    GMX_UNUSED_VALUE(ind);
    GMX_UNUSED_VALUE(name);
#endif
}
コード例 #3
0
int main(int argc, char **argv)
{
    tng_trajectory_t traj;
    union data_values ***positions = 0; /* A 3-dimensional array to be populated */
    int64_t n_particles, n_values_per_frame, n_frames, tot_n_frames;
    char data_type;
    int i, j;
    int particle = 0;
    /* Set a default frame range */
    int first_frame = 0, last_frame = 50;
    char atom_name[64], res_name[64], chain_name[64];

    if(argc <= 1)
    {
        printf("No file specified\n");
        printf("Usage:\n");
        printf("tng_io_read_pos <tng_file> [particle number = %d] "
               "[first_frame = %d] [last_frame = %d]\n",
               particle, first_frame, last_frame);
        exit(1);
    }

    /* A reference must be passed to allocate memory */
    if(tng_trajectory_init(&traj) != TNG_SUCCESS)
    {
        tng_trajectory_destroy(&traj);
        exit(1);
    }
    tng_input_file_set(traj, argv[1]);

    /* Read the file headers */
    tng_file_headers_read(traj, TNG_USE_HASH);

    if(argc >= 3)
    {
        particle = strtol(argv[2], 0, 10);
        if(argc >= 4)
        {
            first_frame = strtol(argv[3], 0, 10);
            if(argc >= 5)
            {
                last_frame = strtol(argv[4], 0, 10);
            }
        }
    }

    if(tng_num_frames_get(traj, &tot_n_frames) != TNG_SUCCESS)
    {
        printf("Cannot determine the number of frames in the file\n");
        tng_trajectory_destroy(&traj);
        exit(1);
    }

    printf("%"PRId64" frames in file\n", tot_n_frames);

    if(last_frame > tot_n_frames - 1)
    {
        last_frame = tot_n_frames - 1;
    }

    n_frames = last_frame - first_frame + 1;

    if(tng_atom_name_of_particle_nr_get(traj, particle, atom_name,
                                        sizeof(atom_name)) ==
       TNG_SUCCESS &&
       tng_residue_name_of_particle_nr_get(traj, particle, res_name,
                                           sizeof(res_name)) ==
       TNG_SUCCESS &&
       tng_chain_name_of_particle_nr_get(traj, particle, chain_name,
                                         sizeof(chain_name)) ==
       TNG_SUCCESS)
    {
        printf("Particle: %s (%s: %s)\n", atom_name, chain_name, res_name);
    }
    else
    {
        printf("Particle name not found\n");
    }

    /* Get the positions of all particles in the requested frame range.
       The positions are stored in the positions array.
       N.B. No proper error checks. */
    if(tng_particle_data_interval_get(traj, TNG_TRAJ_POSITIONS, first_frame,
       last_frame, TNG_USE_HASH, &positions, &n_particles, &n_values_per_frame,
       &data_type) == TNG_SUCCESS)
    {
        if(particle >= n_particles)
        {
            printf("Chosen particle out of range. Only %"PRId64" particles in trajectory.\n", n_particles);
        }
        else
        {
            /* Print the positions of the wanted particle (zero based) */
            for(i=0; i<n_frames; i++)
            {
                printf("%d", first_frame + i);
                for(j=0; j<n_values_per_frame; j++)
                {
                    switch(data_type)
                    {
                    case TNG_INT_DATA:
                        printf("\t%"PRId64"", positions[i][particle][j].i);
                        break;
                    case TNG_FLOAT_DATA:
                        printf("\t%f", positions[i][particle][j].f);
                        break;
                    case TNG_DOUBLE_DATA:
                        printf("\t%f", positions[i][particle][j].d);
                        break;
                    default:
                        break;
                    }
                    printf("\n");
                }
            }
        }
    }
    else
    {
        printf("Cannot read positions\n");
    }

    /* Free memory */
    if(positions)
    {
        tng_particle_data_values_free(traj, positions, n_frames, n_particles,
                                      n_values_per_frame, data_type);
    }
    tng_trajectory_destroy(&traj);

    return(0);
}