Exemple #1
0
static void print_rtp(const char *filenm, const char *title, t_atoms *atoms,
                      t_params plist[], gpp_atomtype_t atype, int cgnr[])
{
    FILE *fp;
    int   i, tp;
    char *tpnm;

    fp = gmx_fio_fopen(filenm, "w");
    fprintf(fp, "; %s\n", title);
    fprintf(fp, "\n");
    fprintf(fp, "[ %s ]\n", *atoms->resinfo[0].name);
    fprintf(fp, "\n");
    fprintf(fp, "[ atoms ]\n");
    for (i = 0; (i < atoms->nr); i++)
    {
        tp = atoms->atom[i].type;
        if ((tpnm = get_atomtype_name(tp, atype)) == NULL)
        {
            gmx_fatal(FARGS, "tp = %d, i = %d in print_rtp", tp, i);
        }
        fprintf(fp, "%-8s  %12s  %8.4f  %5d\n",
                *atoms->atomname[i], tpnm,
                atoms->atom[i].q, cgnr[i]);
    }
    print_pl(fp, plist, F_BONDS, "bonds", atoms->atomname);
    print_pl(fp, plist, F_ANGLES, "angles", atoms->atomname);
    print_pl(fp, plist, F_PDIHS, "dihedrals", atoms->atomname);
    print_pl(fp, plist, F_IDIHS, "impropers", atoms->atomname);

    gmx_fio_fclose(fp);
}
Exemple #2
0
static void print_resatoms(FILE *out,gpp_atomtype_t atype,t_restp *rtp)
{
  int j,tp;
  char *tpnm;
  
  /* fprintf(out,"%5s\n",rtp->resname);
     fprintf(out,"%5d\n",rtp->natom); */
  fprintf(out,"[ %s ]\n",rtp->resname);
  fprintf(out," [ atoms ]\n");
  
  for(j=0; (j<rtp->natom); j++) {
    tp = rtp->atom[j].type;
    tpnm = get_atomtype_name(tp,atype);
    if (tpnm == NULL)
      gmx_fatal(FARGS,"Incorrect atomtype (%d)",tp);
    fprintf(out,"%6s  %6s  %8.3f  %6d\n",
	    *(rtp->atomname[j]),tpnm,rtp->atom[j].q,rtp->cgnr[j]);
  }
}
Exemple #3
0
static void print_atom(FILE *out,t_atom *a,gpp_atomtype_t atype,char *newnm)
{
    fprintf(out,"\t%s\t%g\t%g\n",
            get_atomtype_name(a->type,atype),a->m,a->q);
}
void print_atoms(FILE *out, gpp_atomtype_t atype, t_atoms *at, int *cgnr,
                 gmx_bool bRTPresname)
{
    int         i, ri;
    int         tpA, tpB;
    const char *as;
    char       *tpnmA, *tpnmB;
    double      qres, qtot;

    as = dir2str(d_atoms);
    fprintf(out, "[ %s ]\n", as);
    fprintf(out, "; %4s %10s %6s %7s%6s %6s %10s %10s %6s %10s %10s\n",
            "nr", "type", "resnr", "residue", "atom", "cgnr", "charge", "mass", "typeB", "chargeB", "massB");

    qtot  = 0;

    if (debug)
    {
        fprintf(debug, "This molecule has %d atoms and %d residues\n",
                at->nr, at->nres);
    }

    if (at->nres)
    {
        /* if the information is present... */
        for (i = 0; (i < at->nr); i++)
        {
            ri = at->atom[i].resind;
            if ((i == 0 || ri != at->atom[i-1].resind) &&
                at->resinfo[ri].rtp != NULL)
            {
                qres = get_residue_charge(at, i);
                fprintf(out, "; residue %3d %-3s rtp %-4s q ",
                        at->resinfo[ri].nr,
                        *at->resinfo[ri].name,
                        *at->resinfo[ri].rtp);
                if (fabs(qres) < 0.001)
                {
                    fprintf(out, " %s", "0.0");
                }
                else
                {
                    fprintf(out, "%+3.1f", qres);
                }
                fprintf(out, "\n");
            }
            tpA = at->atom[i].type;
            if ((tpnmA = get_atomtype_name(tpA, atype)) == NULL)
            {
                gmx_fatal(FARGS, "tpA = %d, i= %d in print_atoms", tpA, i);
            }

            fprintf(out, "%6d %10s %6d%c %5s %6s %6d %10g %10g",
                    i+1, tpnmA,
                    at->resinfo[ri].nr,
                    at->resinfo[ri].ic,
                    bRTPresname ?
                    *(at->resinfo[at->atom[i].resind].rtp) :
                    *(at->resinfo[at->atom[i].resind].name),
                    *(at->atomname[i]), cgnr[i],
                    at->atom[i].q, at->atom[i].m);
            if (PERTURBED(at->atom[i]))
            {
                tpB = at->atom[i].typeB;
                if ((tpnmB = get_atomtype_name(tpB, atype)) == NULL)
                {
                    gmx_fatal(FARGS, "tpB = %d, i= %d in print_atoms", tpB, i);
                }
                fprintf(out, " %6s %10g %10g",
                        tpnmB, at->atom[i].qB, at->atom[i].mB);
            }
            qtot += (double)at->atom[i].q;
            if (fabs(qtot) < 4*GMX_REAL_EPS)
            {
                qtot = 0;
            }
            fprintf(out, "   ; qtot %.4g\n", qtot);
        }
    }
    fprintf(out, "\n");
    fflush(out);
}
void print_bt(FILE *out, directive d, gpp_atomtype_t at,
              int ftype, int fsubtype, t_params plist[],
              gmx_bool bFullDih)
{
    /* This dihp is a DIRTY patch because the dih-types do not use
     * all four atoms to determine the type.
     */
    const int    dihp[2][2] = { { 1, 2 }, { 0, 3 } };
    t_params    *bt;
    int          i, j, f, nral, nrfp;
    gmx_bool     bDih = FALSE, bSwapParity;

    bt = &(plist[ftype]);

    if (!bt->nr)
    {
        return;
    }

    f = 0;
    switch (ftype)
    {
        case F_G96ANGLES:
            f = 1;
            break;
        case F_G96BONDS:
            f = 1;
            break;
        case F_MORSE:
            f = 2;
            break;
        case F_CUBICBONDS:
            f = 3;
            break;
        case F_CONNBONDS:
            f = 4;
            break;
        case F_HARMONIC:
            f = 5;
            break;
        case F_CROSS_BOND_ANGLES:
            f = 2;
            break;
        case F_CROSS_BOND_BONDS:
            f = 3;
            break;
        case F_UREY_BRADLEY:
            f = 4;
            break;
        case F_PDIHS:
        case F_RBDIHS:
        case F_FOURDIHS:
            bDih = TRUE;
            break;
        case F_IDIHS:
            f    = 1;
            bDih = TRUE;
            break;
        case F_CONSTRNC:
            f = 1;
            break;
        case F_VSITE3FD:
            f = 1;
            break;
        case F_VSITE3FAD:
            f = 2;
            break;
        case F_VSITE3OUT:
            f = 3;
            break;
        case F_VSITE4FDN:
            f = 1;
            break;
        case F_CMAP:
            f = 1;
            break;

        default:
            bDih = FALSE;
    }
    if (bFullDih)
    {
        bDih = FALSE;
    }
    if (fsubtype)
    {
        f = fsubtype-1;
    }

    nral = NRAL(ftype);
    nrfp = NRFP(ftype);

    /* header */
    fprintf(out, "[ %s ]\n", dir2str(d));
    fprintf(out, "; ");
    if (!bDih)
    {
        fprintf (out, "%3s  %4s", "ai", "aj");
        for (j = 2; (j < nral); j++)
        {
            fprintf (out, "  %3c%c", 'a', 'i'+j);
        }
    }
    else
    {
        for (j = 0; (j < 2); j++)
        {
            fprintf (out, "%3c%c", 'a', 'i'+dihp[f][j]);
        }
    }

    fprintf (out, " funct");
    for (j = 0; (j < nrfp); j++)
    {
        fprintf (out, " %12c%1d", 'c', j);
    }
    fprintf (out, "\n");

    /* print bondtypes */
    for (i = 0; (i < bt->nr); i++)
    {
        bSwapParity = (bt->param[i].C0 == NOTSET) && (bt->param[i].C1 == -1);
        if (!bDih)
        {
            for (j = 0; (j < nral); j++)
            {
                fprintf (out, "%5s ", get_atomtype_name(bt->param[i].a[j], at));
            }
        }
        else
        {
            for (j = 0; (j < 2); j++)
            {
                fprintf (out, "%5s ", get_atomtype_name(bt->param[i].a[dihp[f][j]], at));
            }
        }
        fprintf (out, "%5d ", bSwapParity ? -f-1 : f+1);

        if (bt->param[i].s[0])
        {
            fprintf(out, "   %s", bt->param[i].s);
        }
        else
        {
            for (j = 0; (j < nrfp && (bt->param[i].c[j] != NOTSET)); j++)
            {
                fprintf (out, "%13.6e ", bt->param[i].c[j]);
            }
        }

        fprintf (out, "\n");
    }
    fprintf (out, "\n");
    fflush (out);
}
Exemple #6
0
void convert_harmonics(int nrmols, t_molinfo mols[], gpp_atomtype_t atype)
{
    int       n2m;
    t_2morse *t2m;

    int       i, j, k, last, ni, nj;
    int       nrharm, nrmorse, bb;
    real      edis, kb, b0, beta;
    gmx_bool *bRemoveHarm;

    /* First get the data */
    t2m = read_dissociation_energies(&n2m);
    if (debug)
    {
        fprintf(debug, "MORSE: read %d dissoc energies\n", n2m);
    }
    if (n2m <= 0)
    {
        fprintf(stderr, "No dissocation energies read\n");
        return;
    }

    /* For all the molecule types */
    for (i = 0; (i < nrmols); i++)
    {
        /* Check how many morse and harmonic BONDSs there are, increase size of
         * morse with the number of harmonics
         */
        nrmorse = mols[i].plist[F_MORSE].nr;

        for (bb = 0; (bb < F_NRE); bb++)
        {
            if ((interaction_function[bb].flags & IF_BTYPE) && (bb != F_MORSE))
            {
                nrharm  = mols[i].plist[bb].nr;
                pr_alloc(nrharm, &(mols[i].plist[F_MORSE]));
                snew(bRemoveHarm, nrharm);

                /* Now loop over the harmonics, trying to convert them */
                for (j = 0; (j < nrharm); j++)
                {
                    ni   = mols[i].plist[bb].param[j].AI;
                    nj   = mols[i].plist[bb].param[j].AJ;
                    edis =
                        search_e_diss(n2m, t2m,
                                      get_atomtype_name(mols[i].atoms.atom[ni].type, atype),
                                      get_atomtype_name(mols[i].atoms.atom[nj].type, atype));
                    if (edis != 0)
                    {
                        bRemoveHarm[j] = TRUE;
                        b0             = mols[i].plist[bb].param[j].c[0];
                        kb             = mols[i].plist[bb].param[j].c[1];
                        beta           = sqrt(kb/(2*edis));
                        mols[i].plist[F_MORSE].param[nrmorse].a[0] = ni;
                        mols[i].plist[F_MORSE].param[nrmorse].a[1] = nj;
                        mols[i].plist[F_MORSE].param[nrmorse].c[0] = b0;
                        mols[i].plist[F_MORSE].param[nrmorse].c[1] = edis;
                        mols[i].plist[F_MORSE].param[nrmorse].c[2] = beta;
                        nrmorse++;
                    }
                }
                mols[i].plist[F_MORSE].nr = nrmorse;

                /* Now remove the harmonics */
                for (j = last = 0; (j < nrharm); j++)
                {
                    if (!bRemoveHarm[j])
                    {
                        /* Copy it to the last position */
                        for (k = 0; (k < MAXATOMLIST); k++)
                        {
                            mols[i].plist[bb].param[last].a[k] =
                                mols[i].plist[bb].param[j].a[k];
                        }
                        for (k = 0; (k < MAXFORCEPARAM); k++)
                        {
                            mols[i].plist[bb].param[last].c[k] =
                                mols[i].plist[bb].param[j].c[k];
                        }
                        last++;
                    }
                }
                sfree(bRemoveHarm);
                fprintf(stderr, "Converted %d out of %d %s to morse bonds for mol %d\n",
                        nrharm-last, nrharm, interaction_function[bb].name, i);
                mols[i].plist[bb].nr = last;
            }
        }
    }
    sfree(t2m);
}
Exemple #7
0
static gmx_bool calc_vsite3out_param(gpp_atomtype_t atype,
				 t_param *param, t_atoms *at,
				 int nrbond, t_mybonded *bonds,
				 int nrang,  t_mybonded *angles)
{
  /* i = virtual site          |    ,k
   * j = 1st bonded heavy atom | i-j
   * k,l = 2nd bonded atoms    |    `l
   * NOTE: i is out of the j-k-l plane!
   */
  
  gmx_bool bXH3,bError,bSwapParity;
  real bij,bjk,bjl,aijk,aijl,akjl,pijk,pijl,a,b,c;
  
  /* check if this is part of a NH2-umbrella, NH3 or CH3 group,
   * i.e. if atom k and l are dummy masses (MNH* or MCH3*) */
  if (debug) {
    int i;
    for (i=0; i<4; i++)
      fprintf(debug,"atom %u type %s ",
	      param->a[i]+1,get_atomtype_name(at->atom[param->a[i]].type,atype));
    fprintf(debug,"\n");
  }
  bXH3 = 
    ( (gmx_strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MNH",3)==0) &&
      (gmx_strncasecmp(get_atomtype_name(at->atom[param->AL].type,atype),"MNH",3)==0) ) ||
    ( (gmx_strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MCH3",4)==0) &&
      (gmx_strncasecmp(get_atomtype_name(at->atom[param->AL].type,atype),"MCH3",4)==0) );
  
  /* check if construction parity must be swapped */  
  bSwapParity = ( param->C1 == -1 );
  
  bjk = get_bond_length(nrbond, bonds, param->AJ, param->AK);
  bjl = get_bond_length(nrbond, bonds, param->AJ, param->AL);
  bError = (bjk==NOTSET) || (bjl==NOTSET);
  if (bXH3) {
    /* now we get some XH3 group specific construction */
    /* note: we call the heavy atom 'C' and the X atom 'N' */
    real bMM,bCM,bCN,bNH,aCNH,dH,rH,rHx,rHy,dM,rM;
    int aN;
    
    /* check if bonds from heavy atom (j) to dummy masses (k,l) are equal: */
    bError = bError || (bjk!=bjl);
    
    /* the X atom (C or N) in the XH3 group is the first after the masses: */
    aN = max(param->AK,param->AL)+1;
    
    /* get all bondlengths and angles: */
    bMM = get_bond_length(nrbond, bonds, param->AK, param->AL);
    bCM = bjk;
    bCN = get_bond_length(nrbond, bonds, param->AJ, aN);
    bNH = get_bond_length(nrbond, bonds, aN, param->AI);
    aCNH= get_angle      (nrang, angles, param->AJ, aN, param->AI);
    bError = bError || 
      (bMM==NOTSET) || (bCN==NOTSET) || (bNH==NOTSET) || (aCNH==NOTSET);
    
    /* calculate */
    dH  = bCN - bNH * cos(aCNH);
    rH  = bNH * sin(aCNH);
    /* we assume the H's are symmetrically distributed */
    rHx = rH*cos(DEG2RAD*30);
    rHy = rH*sin(DEG2RAD*30);
    rM  = 0.5*bMM;
    dM  = sqrt( sqr(bCM) - sqr(rM) );
    a   = 0.5*( (dH/dM) - (rHy/rM) );
    b   = 0.5*( (dH/dM) + (rHy/rM) );
    c   = rHx / (2*dM*rM);
    
  } else {
    /* this is the general construction */
    
    bij = get_bond_length(nrbond, bonds, param->AI, param->AJ);
    aijk= get_angle      (nrang, angles, param->AI, param->AJ, param->AK);
    aijl= get_angle      (nrang, angles, param->AI, param->AJ, param->AL);
    akjl= get_angle      (nrang, angles, param->AK, param->AJ, param->AL);
    bError = bError || 
      (bij==NOTSET) || (aijk==NOTSET) || (aijl==NOTSET) || (akjl==NOTSET);
  
    pijk = cos(aijk)*bij;
    pijl = cos(aijl)*bij;
    a = ( pijk + (pijk*cos(akjl)-pijl) * cos(akjl) / sqr(sin(akjl)) ) / bjk;
    b = ( pijl + (pijl*cos(akjl)-pijk) * cos(akjl) / sqr(sin(akjl)) ) / bjl;
    c = - sqrt( sqr(bij) - 
		( sqr(pijk) - 2*pijk*pijl*cos(akjl) + sqr(pijl) ) 
		/ sqr(sin(akjl)) )
      / ( bjk*bjl*sin(akjl) );
  }
  
  param->C0 = a;
  param->C1 = b;
  if (bSwapParity)
    param->C2 = -c;
  else
    param->C2 =  c;
  if (debug)
    fprintf(debug,"params for vsite3out %u: %g %g %g\n",
	    param->AI+1,param->C0,param->C1,param->C2);
  return bError;
}
Exemple #8
0
static gmx_bool calc_vsite3_param(gpp_atomtype_t atype,
			      t_param *param, t_atoms *at,
			      int nrbond, t_mybonded *bonds,
			      int nrang,  t_mybonded *angles )
{
  /* i = virtual site          |    ,k
   * j = 1st bonded heavy atom | i-j
   * k,l = 2nd bonded atoms    |    `l
   */
  
  gmx_bool bXH3,bError;
  real bjk,bjl,a=-1,b=-1;
  /* check if this is part of a NH3 , NH2-umbrella or CH3 group,
   * i.e. if atom k and l are dummy masses (MNH* or MCH3*) */
  if (debug) {
    int i;
    for (i=0; i<4; i++)
      fprintf(debug,"atom %u type %s ",
	      param->a[i]+1,
	      get_atomtype_name(at->atom[param->a[i]].type,atype));
    fprintf(debug,"\n");
  }
  bXH3 = 
    ( (gmx_strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MNH",3)==0) &&
      (gmx_strncasecmp(get_atomtype_name(at->atom[param->AL].type,atype),"MNH",3)==0) ) ||
    ( (gmx_strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MCH3",4)==0) &&
      (gmx_strncasecmp(get_atomtype_name(at->atom[param->AL].type,atype),"MCH3",4)==0) );
  
  bjk = get_bond_length(nrbond, bonds, param->AJ, param->AK);
  bjl = get_bond_length(nrbond, bonds, param->AJ, param->AL);
  bError = (bjk==NOTSET) || (bjl==NOTSET);
  if (bXH3) {
    /* now we get some XH2/XH3 group specific construction */
    /* note: we call the heavy atom 'C' and the X atom 'N' */
    real bMM,bCM,bCN,bNH,aCNH,dH,rH,dM,rM;
    int aN;
    
    /* check if bonds from heavy atom (j) to dummy masses (k,l) are equal: */
    bError = bError || (bjk!=bjl);
    
    /* the X atom (C or N) in the XH2/XH3 group is the first after the masses: */
    aN = max(param->AK,param->AL)+1;
    
    /* get common bonds */
    bMM = get_bond_length(nrbond, bonds, param->AK, param->AL);
    bCM = bjk;
    bCN = get_bond_length(nrbond, bonds, param->AJ, aN);
    bError = bError || (bMM==NOTSET) || (bCN==NOTSET);
    
    /* calculate common things */
    rM  = 0.5*bMM;
    dM  = sqrt( sqr(bCM) - sqr(rM) );
    
    /* are we dealing with the X atom? */
    if ( param->AI == aN ) {
      /* this is trivial */
      a = b = 0.5 * bCN/dM;
      
    } else {
      /* get other bondlengths and angles: */
      bNH = get_bond_length(nrbond, bonds, aN, param->AI);
      aCNH= get_angle      (nrang, angles, param->AJ, aN, param->AI);
      bError = bError || (bNH==NOTSET) || (aCNH==NOTSET);
      
      /* calculate */
      dH  = bCN - bNH * cos(aCNH);
      rH  = bNH * sin(aCNH);
      
      a = 0.5 * ( dH/dM + rH/rM );
      b = 0.5 * ( dH/dM - rH/rM );
    }
  } else
    gmx_fatal(FARGS,"calc_vsite3_param not implemented for the general case "
		"(atom %d)",param->AI+1);
  
  param->C0 = a;
  param->C1 = b;
  
  if (debug)
    fprintf(debug,"params for vsite3 %u: %g %g\n",
	    param->AI+1,param->C0,param->C1);
  
  return bError;
}