#include #include #include #include "simfront.h" /* * read and set force field parameters */ int setup_params(SimFront *sf) { Param *param = &(sf->param); Pbuf *pbuf = &(sf->pbuf); MD_Sim *sim = sf->sim; MD_Int paramtype; int k; /* read in each param file in the order listed in config file */ for (k = 0; k < sf->paramfilelistnum; k++) { if (param_open(param, sf->paramfilelist[k], PARAM_XPLOR)) { ERRMSG(sf, "call to param_open failed"); return -1; } /* * Here is the strangeness in the MDIO Param interface: * * Must have some amount of initial buffer space * (this was set up in init()). Return value from * param_read() indicates by nonzero which buffer is * full so that we need to resize in case any additional * space is needed. * * As params are read in, atom strings for each bond type * are hashed with the array index for that bond. This * allows fast lookup for index when reading topology. * Any params that are redefined are still placed in next * additional pbuf array space, but the index value that * the hashed string returns is silently overwritten to * the new index (but no warning message is given). */ while ((paramtype = param_read(param)) != 0) { void *vp; switch (paramtype) { case MD_ATOM_PARAM: vp = (void *) pbuf->atomp; vp = realloc(vp, (pbuf->atomp_len + INITLEN) * sizeof(MD_Atom_Param)); if (vp == NULL) { ERRMSG(sf, strerror(errno)); return -1; } pbuf->atomp = (MD_Atom_Param *) vp; pbuf->atomp_len += INITLEN; break; case MD_BOND_PARAM: vp = (void *) pbuf->bondp; vp = realloc(vp, (pbuf->bondp_len + INITLEN) * sizeof(MD_Bond_Param)); if (vp == NULL) { ERRMSG(sf, strerror(errno)); return -1; } pbuf->bondp = (MD_Bond_Param *) vp; pbuf->bondp_len += INITLEN; break; case MD_ANGLE_PARAM: vp = (void *) pbuf->anglep; vp = realloc(vp, (pbuf->anglep_len + INITLEN) * sizeof(MD_Angle_Param)); if (vp == NULL) { ERRMSG(sf, strerror(errno)); return -1; } pbuf->anglep = (MD_Angle_Param *) vp; pbuf->anglep_len += INITLEN; break; case MD_DIHED_PARAM: vp = (void *) pbuf->dihedp; vp = realloc(vp, (pbuf->dihedp_len + INITLEN) * sizeof(MD_Dihed_Param)); if (vp == NULL) { ERRMSG(sf, strerror(errno)); return -1; } pbuf->dihedp = (MD_Dihed_Param *) vp; pbuf->dihedp_len += INITLEN; break; case MD_IMPR_PARAM: vp = (void *) pbuf->imprp; vp = realloc(vp, (pbuf->imprp_len + INITLEN) * sizeof(MD_Impr_Param)); if (vp == NULL) { ERRMSG(sf, strerror(errno)); return -1; } pbuf->imprp = (MD_Impr_Param *) vp; pbuf->imprp_len += INITLEN; break; case MD_NBFIX_PARAM: vp = (void *) pbuf->nbfixp; vp = realloc(vp, (pbuf->nbfixp_len + INITLEN) * sizeof(MD_Nbfix_Param)); if (vp == NULL) { ERRMSG(sf, strerror(errno)); return -1; } pbuf->nbfixp = (MD_Nbfix_Param *) vp; pbuf->nbfixp_len += INITLEN; break; default: ERRMSG(sf, "unknown return value from param_read"); return -1; } } /* end while loop read param file */ if (param_close(param)) { ERRMSG(sf, "call to param_close failed"); return -1; } } /* end for loop process all param files */ /* set engine force field param data arrays */ if (MD_setlen(sim, sf->id_atomparam, pbuf->atomp_num) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim, sf->id_atomparam, pbuf->atomp, pbuf->atomp_num, 0) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setlen(sim, sf->id_bondparam, pbuf->bondp_num) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim, sf->id_bondparam, pbuf->bondp, pbuf->bondp_num, 0) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setlen(sim, sf->id_angleparam, pbuf->anglep_num) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim, sf->id_angleparam, pbuf->anglep, pbuf->anglep_num, 0) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setlen(sim, sf->id_dihedparam, pbuf->dihedp_num) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim, sf->id_dihedparam, pbuf->dihedp, pbuf->dihedp_num, 0) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setlen(sim, sf->id_imprparam, pbuf->imprp_num) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim, sf->id_imprparam, pbuf->imprp, pbuf->imprp_num, 0) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setlen(sim, sf->id_nbfixparam, pbuf->nbfixp_num) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_setdata(sim, sf->id_nbfixparam, pbuf->nbfixp, pbuf->nbfixp_num, 0) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } return 0; }