#include "simfront.h" /* * read and set topology */ int setup_topology(SimFront *sf) { Topo *topo = &(sf->topo); Tbuf *tbuf = &(sf->tbuf); MD_Sim *sim = sf->sim; int index_atom = 0, index_bond = 0, index_angle = 0, index_dihed = 0, index_impr = 0, index_excl = 0; int k; /* open topology file */ if (topo_open(topo, sf->topofile, TOPO_XPLOR)) { ERRMSG(sf, "call to topo_open failed"); return -1; } /* read in topology file */ /* * Here is the strangeness in the MDIO Topo interface: * * Must have some amount of initial buffer space * (this was set up in init()). Return value from * topo_read() indicates by nonzero which buffer is * full so that we can set this much of the corresponding * engine array. Unlike Param interface, writing always * starts at beginning of buffer, so need to "empty" that * buffer (make call to MD_setdata) after each return from * topo_read(). */ while ((k = topo_read(topo)) != 0) { switch (k) { case MD_ATOM: if (MD_getlen(sim, sf->id_atom) != tbuf->atom_max && (MD_setlen(sim, sf->id_atom, tbuf->atom_max) || MD_wait(sim))) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim,sf->id_atom,tbuf->atom,tbuf->atom_num,index_atom) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } index_atom += tbuf->atom_num; break; case MD_BOND: if (MD_getlen(sim, sf->id_bond) != tbuf->bond_max && (MD_setlen(sim, sf->id_bond, tbuf->bond_max) || MD_wait(sim))) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim,sf->id_bond,tbuf->bond,tbuf->bond_num,index_bond) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } index_bond += tbuf->bond_num; break; case MD_ANGLE: if (MD_getlen(sim, sf->id_angle) != tbuf->angle_max && (MD_setlen(sim, sf->id_angle, tbuf->angle_max) || MD_wait(sim))) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim,sf->id_angle,tbuf->angle,tbuf->angle_num,index_angle) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } index_angle += tbuf->angle_num; break; case MD_DIHED: if (MD_getlen(sim, sf->id_dihed) != tbuf->dihed_max && (MD_setlen(sim, sf->id_dihed, tbuf->dihed_max) || MD_wait(sim))) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim,sf->id_dihed,tbuf->dihed,tbuf->dihed_num,index_dihed) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } index_dihed += tbuf->dihed_num; break; case MD_IMPR: if (MD_getlen(sim, sf->id_impr) != tbuf->impr_max && (MD_setlen(sim, sf->id_impr, tbuf->impr_max) || MD_wait(sim))) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim,sf->id_impr,tbuf->impr,tbuf->impr_num,index_impr) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } index_impr += tbuf->impr_num; break; case MD_EXCL: if (MD_getlen(sim, sf->id_excl) != tbuf->excl_max && (MD_setlen(sim, sf->id_excl, tbuf->excl_max) || MD_wait(sim))) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim,sf->id_excl,tbuf->excl,tbuf->excl_num,index_excl) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } index_excl += tbuf->excl_num; break; default: ERRMSG(sf, "unknown return value from topo_read"); return -1; } } /* close topology file */ if (topo_close(topo)) { ERRMSG(sf, "call to topo_close failed"); return -1; } /* verify that we read and set everything */ if (index_atom != tbuf->atom_max) { ERRMSG(sf, "do not have expected number of atoms"); return -1; } if (index_bond != tbuf->bond_max) { ERRMSG(sf, "do not have expected number of bonds"); return -1; } if (index_angle != tbuf->angle_max) { ERRMSG(sf, "do not have expected number of angles"); return -1; } if (index_dihed != tbuf->dihed_max) { ERRMSG(sf, "do not have expected number of dihedrals"); return -1; } if (index_impr != tbuf->impr_max) { ERRMSG(sf, "do not have expected number of impropers"); return -1; } if (index_excl != tbuf->excl_max) { ERRMSG(sf, "do not have expected number of exclusions"); return -1; } return 0; }