Abstracted the t_atomtype and t_bon_atomtype data types,
authorspoel <spoel>
Sun, 3 Feb 2008 12:29:11 +0000 (12:29 +0000)
committerspoel <spoel>
Sun, 3 Feb 2008 12:29:11 +0000 (12:29 +0000)
used in grompp and pdb2gmx etc. All
access to this data is now done through function calls.
The code was tested in single and double precision (using standard tests)
and generated top and tpr files are identical.

40 files changed:
include/grompp.h
include/x2top_qgen.h
src/contrib/tune_dip.c
src/kernel/Makefile.am
src/kernel/convparm.c
src/kernel/gen_vsite.c
src/kernel/gen_vsite.h
src/kernel/gpp_atomtype.c [new file with mode: 0644]
src/kernel/gpp_atomtype.h [new file with mode: 0644]
src/kernel/gpp_bond_atomtype.c [new file with mode: 0644]
src/kernel/gpp_bond_atomtype.h [new file with mode: 0644]
src/kernel/gpp_tomorse.h [new file with mode: 0644]
src/kernel/grompp.c
src/kernel/hackblock.h
src/kernel/nm2type.c
src/kernel/pdb2gmx.c
src/kernel/pdb2top.c
src/kernel/pdb2top.h
src/kernel/resall.c
src/kernel/resall.h
src/kernel/ter_db.c
src/kernel/ter_db.h
src/kernel/tomorse.c
src/kernel/topio.c
src/kernel/topio.h
src/kernel/toppush.c
src/kernel/toppush.h
src/kernel/topshake.c
src/kernel/topshake.h
src/kernel/toputil.c
src/kernel/toputil.h
src/kernel/vsite_parm.c
src/kernel/vsite_parm.h
src/kernel/x2top.c
src/kernel/x2top_core.c
src/kernel/x2top_core.h
src/kernel/x2top_eemprops.c
src/kernel/x2top_matrix.c
src/kernel/x2top_nm2type.h
src/kernel/x2top_qgen.c

index a294a08704f2cb564f258e3763638ad2745a7b0f..f84ba2ecb070d0694dd33642ca5662aca2e69c73 100644 (file)
@@ -85,27 +85,8 @@ typedef struct {
   t_block       mols;           /* Molecules                            */
   t_blocka      excls;          /* Exclusions                           */
   t_params      plist[F_NRE];   /* Parameters in old style              */
-  
 } t_molinfo;
 
-typedef struct {
-  int           nr;            /* The number of atomtypes              */
-  t_atom       *atom;          /* Array of atoms                       */
-  char          ***atomname;   /* Names of the atomtypes               */
-  t_param      *nb;            /* Nonbonded force default params       */
-  int           *bondatomtype;  /* The bond_atomtype for each atomtype  */
-  real          *radius;        /* Radius for GBSA stuff                */
-  real          *vol;           /* Effective volume for GBSA            */
-  real          *surftens;      /* Surface tension with water, for GBSA */
-  int           *atomnumber;    /* Atomic number, used for QM/MM        */
-} t_atomtype;
-
-typedef struct {
-  int           nr;             /* Number of bond_atomtypes            */
-  char          ***atomname;    /* Names of the bond_atomtypes         */
-} t_bond_atomtype;
-
-
 typedef enum {
   d_defaults,
   d_atomtypes,
@@ -181,8 +162,6 @@ static char *ds[d_maxdir+1] = {
   "invalid"
   };
 
-extern void convert_harmonics(int nrmols,t_molinfo mols[],t_atomtype *atype);
-
 #endif /* _grompp_h */
 
 
index 1b0e2e0c27966b0c8132b3b4139741ef1488cfa9..abdc1fac0385489c6af85d4056402b7d9a152bb2 100644 (file)
@@ -41,7 +41,7 @@
 #include "grompp.h"
        
 enum { eqgNone, eqgLinear, eqgYang, eqgBultinck, 
-       eqgSM1, eqgSM2, eqgSM3, eqgSM4, eqgNR };
+       eqgSMp, eqgSMs, eqgSMps, eqgSMg, eqgSMpg, eqgNR };
 
 extern real generate_charges_sm(FILE *fp,char *molname,void *eem,
                                t_atoms *atoms,rvec x[],
index 5accb8a9f8c7559ec0a761fd4651a2294edea394..a650423cc853baff90861612de6ff3c6c5a528b1 100644 (file)
@@ -319,7 +319,7 @@ static double dipole_function(const gsl_vector *v,void *params)
       rms += sqr(chi0-md->Chi0_0);
     if (chi0 > md->Chi0_1)
       rms += sqr(chi0-md->Chi0_1);
-    if (md->eemtype != eqgSM1) {
+    if (md->eemtype != eqgSMp) {
       w = gsl_vector_get(v, k++);
       if (w < md->w_0)
        rms += sqr(w-md->w_0);
@@ -378,7 +378,7 @@ static void optimize_moldip(FILE *fp,FILE *logf,
   
   my_func.f      = &dipole_function;
   my_func.n      = md->nparam*2;
-  if (md->eemtype != eqgSM1)
+  if (md->eemtype != eqgSMp)
     my_func.n += md->nparam;
   my_func.params = (void *) md;
 
@@ -410,7 +410,7 @@ static void optimize_moldip(FILE *fp,FILE *logf,
        gsl_vector_set (dx, k++, stepsize*chi0);
        
        w = eem_get_w(md->eem,md->index[i]);
-       if (md->eemtype != eqgSM1) {
+       if (md->eemtype != eqgSMp) {
          w = guess_new_param(w,stepsize,md->w_0,md->w_1,rng,bRand);
          gsl_vector_set (x, k, w);
          gsl_vector_set (dx, k++, stepsize*w);
@@ -560,14 +560,14 @@ int main(int argc, char *argv[])
   parse_common_args(&argc,argv,PCA_CAN_VIEW,NFILE,fnm,asize(pa),pa,
                    asize(desc),desc,0,NULL);
 
-  eemtype = eqgSM1;
+  eemtype = eqgSMp;
   if (qgen[0]) {
     eemtype = name2eemtype(qgen[0]);
     if (eemtype == -1)
-      eemtype = eqgSM1;
+      eemtype = eqgSMp;
   }
-  if (eemtype > eqgSM3)
-    gmx_fatal(FARGS,"Only models SM1 and SM2 implemented so far");
+  if (eemtype > eqgSMps)
+    gmx_fatal(FARGS,"Only models SMp, SMs and SMps implemented so far");
     
   logf = fopen(opt2fn("-g",NFILE,fnm),"w");
   md = read_moldip(logf,opt2fn("-f",NFILE,fnm),
index b42589df1dc40752b063f1806ff4dbf4b209af11..e75c509852c4245883732f7572434fd0f0a1860a 100644 (file)
@@ -19,6 +19,8 @@ gen_ad.c      gen_ad.h        \
 gen_vsite.c    gen_vsite.h     \
 genhydro.c     genhydro.h      \
 gmxcpp.c       gmxcpp.h        \
+gpp_atomtype.c gpp_atomtype.h  \
+gpp_bond_atomtype.c    gpp_bond_atomtype.h     \
 h_db.c         h_db.h          \
 hackblock.c    hackblock.h     \
 hizzie.c       hizzie.h        \
@@ -30,7 +32,7 @@ resall.c      resall.h        \
 sorting.c      sorting.h       \
 specbond.c     specbond.h      \
 ter_db.c       ter_db.h        \
-tomorse.c      \
+tomorse.c      gpp_tomorse.h   \
 topcat.c       topcat.h        \
 topdirs.c      topdirs.h       \
 topexcl.c      topexcl.h       \
index 918ddb785e8e38d94e3703dd591ac2e7c6db7aef..81599eded07802699b384e0b3d3ed615347f46eb 100644 (file)
@@ -49,6 +49,7 @@
 #include "toputil.h"
 #include "convparm.h"
 #include "names.h"
+#include "gpp_atomtype.h"
 
 static int round_check(real r,int limit,int ftype,char *name)
 {
index d9fc16cb994f900e1a7ea096b2675b3cb799945b..56c3472e425cb2d196c252f792cb358b70dc9090 100644 (file)
@@ -51,6 +51,7 @@
 #include "index.h"
 #include "names.h"
 #include "futil.h"
+#include "gpp_atomtype.h"
 
 #define MAXNAME 32
 #define OPENDIR        '['     /* starting sign for directive          */
@@ -427,16 +428,15 @@ static int get_atype(int atom, t_atoms *at, int nrtp, t_restp rtp[],
   return type;
 }
 
-static int nm2type(char *name, t_atomtype *atype)
+static int vsite_nm2type(char *name, t_atomtype atype)
 {
-  int tp,j;
+  int tp;
   
-  tp=NOTSET;
-  for(j=0; (j < atype->nr) && (tp==NOTSET); j++)
-    if (strcasecmp(name,*(atype->atomname[j])) == 0)
-      tp=j;
-  if (tp==NOTSET)
-    gmx_fatal(FARGS,"Dummy mass type (%s) not found in atom type database",name);
+  tp = get_atomtype_type(name,atype);
+  if (tp == NOTSET)
+    gmx_fatal(FARGS,"Dummy mass type (%s) not found in atom type database",
+             name);
+             
   return tp;
 }
 
@@ -704,7 +704,7 @@ static void calc_vsite3_param(real xd,real yd,real xi,real yi,real xj,real yj,
 }
 
 
-static int gen_vsites_trp(t_atomtype *atype, rvec *newx[],
+static int gen_vsites_trp(t_atomtype atype, rvec *newx[],
                        t_atom *newatom[], char ***newatomname[], 
                        int *o2n[], int *newvsite_type[], int *newcgnr[],
                        t_symtab *symtab, int *nadd, rvec x[], int *cgnr[],
@@ -865,7 +865,7 @@ static int gen_vsites_trp(t_atomtype *atype, rvec *newx[],
   }
   
   /* get dummy mass type */
-  tpM=nm2type("MW",atype);
+  tpM=vsite_nm2type("MW",atype);
   /* make space for 2 masses: shift all atoms starting with CB */
   i0=ats[atCB];
   for(j=0; j<NMASS; j++)
@@ -954,7 +954,7 @@ static int gen_vsites_trp(t_atomtype *atype, rvec *newx[],
 }
 
 
-static int gen_vsites_tyr(t_atomtype *atype, rvec *newx[],
+static int gen_vsites_tyr(t_atomtype atype, rvec *newx[],
                        t_atom *newatom[], char ***newatomname[], 
                        int *o2n[], int *newvsite_type[], int *newcgnr[],
                        t_symtab *symtab, int *nadd, rvec x[], int *cgnr[],
@@ -1054,7 +1054,7 @@ static int gen_vsites_tyr(t_atomtype *atype, rvec *newx[],
   at->atom[ats[atHH]].m=at->atom[ats[atHH]].mB=0;
   
   /* get dummy mass type */
-  tpM=nm2type("MW",atype);
+  tpM=vsite_nm2type("MW",atype);
   /* make space for 1 mass: shift HH only */
   i0=ats[atHH];
   atM=i0+*nadd;
@@ -1321,7 +1321,7 @@ static bool is_vsite(int vsite_type)
 
 static char atomnamesuffix[] = "1234";
 
-void do_vsites(int nrtp, t_restp rtp[], t_atomtype *atype, 
+void do_vsites(int nrtp, t_restp rtp[], t_atomtype atype, 
                t_atoms *at, t_symtab *symtab, rvec *x[], 
                t_params plist[], int *vsite_type[], int *cgnr[], 
                real mHmult, bool bVsiteAromatics, char *ff)
@@ -1514,7 +1514,7 @@ void do_vsites(int nrtp, t_restp rtp[], t_atomtype *atype,
                  &nrbonds, &nrHatoms, Hatoms, &Heavy, &nrheavies, heavies);
       /* get Heavy atom type */
       tpHeavy=get_atype(Heavy,at,nrtp,rtp,aan);
-      strcpy(tpname,type2nm(tpHeavy,atype));
+      strcpy(tpname,get_atomtype_name(tpHeavy,atype));
 
       bWARNING=FALSE;
       bAddVsiteParam=TRUE;
@@ -1599,7 +1599,7 @@ void do_vsites(int nrtp, t_restp rtp[], t_atomtype *atype,
          (*vsite_type)[Hatoms[j]] = Hat_vsite_type[j];
        /* get dummy mass type from first char of heavy atom type (N or C) */
        
-       strcpy(nexttpname,type2nm(get_atype(heavies[0],at,nrtp,rtp,aan),atype));
+       strcpy(nexttpname,get_atomtype_name(get_atype(heavies[0],at,nrtp,rtp,aan),atype));
        ch=get_dummymass_name(vsiteconflist,nvsiteconf,tpname,nexttpname);
 
        if(ch==NULL) 
@@ -1607,7 +1607,7 @@ void do_vsites(int nrtp, t_restp rtp[], t_atomtype *atype,
        else
          strcpy(name,ch);
 
-       tpM=nm2type(name,atype);
+       tpM=vsite_nm2type(name,atype);
        /* make space for 2 masses: shift all atoms starting with 'Heavy' */
 #define NMASS 2
        i0=Heavy;
index 840cc58d186f965d9ec5294cfa9f80cfbf96bc3d..0acc73184ef5559cc1b011ac21da293985d4949c 100644 (file)
 
 #include "typedefs.h"
 #include "grompp.h"
+#include "gpp_atomtype.h"
 #include "hackblock.h"
 
 /* stuff for pdb2gmx */
 
-extern void do_vsites(int nrtp, t_restp rtp[], t_atomtype *atype, 
+extern void do_vsites(int nrtp, t_restp rtp[], t_atomtype atype, 
                      t_atoms *at, t_symtab *symtab, rvec *x[], 
                      t_params plist[], int *dummy_type[], int *cgnr[], 
                      real mHmult, bool bVSiteAromatics, char *ff);
diff --git a/src/kernel/gpp_atomtype.c b/src/kernel/gpp_atomtype.c
new file mode 100644 (file)
index 0000000..f7720e8
--- /dev/null
@@ -0,0 +1,487 @@
+/*
+ * $Id$
+ * 
+ *                This source code is part of
+ * 
+ *                 G   R   O   M   A   C   S
+ * 
+ *          GROningen MAchine for Chemical Simulations
+ * 
+ *                        VERSION 3.2.0
+ * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team,
+ * check out http://www.gromacs.org for more information.
+
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * If you want to redistribute modifications, please consider that
+ * scientific software is very special. Version control is crucial -
+ * bugs must be traceable. We will be happy to consider code for
+ * inclusion in the official distribution, but derived work must not
+ * be called official GROMACS. Details are found in the README & COPYING
+ * files - if they are missing, get the official version at www.gromacs.org.
+ * 
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the papers on the package - you can find them in the top README file.
+ * 
+ * For more info, check our website at http://www.gromacs.org
+ * 
+ * And Hey:
+ * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <math.h>
+#include "smalloc.h"
+#include "sysstuff.h"
+#include "macros.h"
+#include "string2.h"
+#include "topdirs.h"
+#include "toputil.h"
+#include "topdirs.h"
+#include "toputil.h"
+#include "symtab.h"
+#include "gmx_fatal.h"
+#include "txtdump.h"
+#include "gpp_atomtype.h"
+
+typedef struct {
+  int           nr;            /* The number of atomtypes              */
+  t_atom       *atom;          /* Array of atoms                       */
+  char          ***atomname;   /* Names of the atomtypes               */
+  t_param      *nb;            /* Nonbonded force default params       */
+  int           *bondatomtype;  /* The bond_atomtype for each atomtype  */
+  real          *radius;        /* Radius for GBSA stuff                */
+  real          *vol;           /* Effective volume for GBSA            */
+  real          *surftens;      /* Surface tension with water, for GBSA */
+  int           *atomnumber;    /* Atomic number, used for QM/MM        */
+} gpp_atomtype;
+
+int get_atomtype_type(char *str,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  int i;
+
+  for (i=0; (i<ga->nr); i++)
+    if (strcasecmp(str,*(ga->atomname[i])) == 0)
+      return i;
+  
+  return NOTSET;
+}
+
+int get_atomtype_ntypes(t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  return ga->nr;
+}
+
+char *get_atomtype_name(int nt, t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NULL;
+  
+  return *(ga->atomname[nt]);
+}
+
+real get_atomtype_massA(int nt,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+  
+  return ga->atom[nt].m;
+}
+
+real get_atomtype_massB(int nt,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+  
+  return ga->atom[nt].mB;
+}
+
+real get_atomtype_qA(int nt,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+  
+  return ga->atom[nt].q;
+}
+
+real get_atomtype_qB(int nt,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+  
+  return ga->atom[nt].qB;
+}
+
+int get_atomtype_ptype(int nt,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+  
+  return ga->atom[nt].ptype;
+}
+
+int get_atomtype_batype(int nt,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+  
+  return ga->bondatomtype[nt];
+}
+
+int get_atomtype_atomnumber(int nt,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+  
+  return ga->atomnumber[nt];
+}
+
+real get_atomtype_radius(int nt,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+  
+  return ga->radius[nt];
+}
+
+real get_atomtype_vol(int nt,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+  
+  return ga->vol[nt];
+}
+
+real get_atomtype_surftens(int nt,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+  
+  return ga->surftens[nt];
+}
+
+real get_atomtype_nbparam(int nt,int param,t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+  if ((param < 0) || (param >= MAXFORCEPARAM))
+    return NOTSET;
+  return ga->nb[nt].c[param];
+}
+
+t_atomtype init_atomtype(void)
+{
+  gpp_atomtype *ga;
+  
+  snew(ga,1);
+  
+  return (t_atomtype ) ga;
+}
+
+int set_atomtype(int nt,t_atomtype at,t_symtab *tab,
+                t_atom *a,char *name,t_param *nb,
+                int bondatomtype,
+                real radius,real vol,real surftens,int atomnumber)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NOTSET;
+    
+  ga->atom[nt] = *a;
+  ga->atomname[nt] = put_symtab(tab,name);
+  ga->nb[nt] = *nb;
+  ga->bondatomtype[nt] = bondatomtype;
+  ga->radius[nt] = radius;
+  ga->vol[nt] = vol;
+  ga->surftens[nt] = surftens;
+  ga->atomnumber[nt] = atomnumber;
+  
+  return nt;
+}
+
+int add_atomtype(t_atomtype at,t_symtab *tab,
+                t_atom *a,char *name,t_param *nb,
+                int bondatomtype,
+                real radius,real vol,real surftens,real atomnumber)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  ga->nr++;
+  srenew(ga->atom,ga->nr);
+  srenew(ga->atomname,ga->nr);
+  srenew(ga->nb,ga->nr);
+  srenew(ga->bondatomtype,ga->nr);
+  srenew(ga->radius,ga->nr);
+  srenew(ga->vol,ga->nr);
+  srenew(ga->surftens,ga->nr);
+  srenew(ga->atomnumber,ga->nr);
+  
+  return set_atomtype(ga->nr-1,at,tab,a,name,nb,bondatomtype,radius,
+                     vol,surftens,atomnumber);
+}
+
+void print_at (FILE * out, t_atomtype at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  int i;
+  t_atom     *atom = ga->atom;
+  t_param    *nb   = ga->nb;
+  
+  fprintf (out,"[ %s ]\n",dir2str(d_atomtypes));
+  fprintf (out,"; %6s  %8s  %8s  %8s  %12s  %12s\n",
+          "type","mass","charge","particle","c6","c12");
+  for (i=0; (i<ga->nr); i++) 
+    fprintf(out,"%8s  %8.3f  %8.3f  %8s  %12e  %12e\n",
+           *(ga->atomname[i]),atom[i].m,atom[i].q,"A",
+           nb[i].C0,nb[i].C1);
+  
+  fprintf (out,"\n");
+}
+
+void done_atomtype(t_atomtype *at)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) *at;
+
+  sfree(ga->atom);
+  sfree(ga->atomname);
+  sfree(ga->nb);
+  sfree(ga->bondatomtype);
+  sfree(ga->radius);
+  sfree(ga->vol);
+  sfree(ga->surftens);
+  sfree(ga->atomnumber);
+  ga->nr = 0;
+  sfree(ga);
+  *at = NULL;
+}
+
+static int search_atomtypes(t_atomtype at,int *n,int typelist[],
+                           int thistype,
+                           t_param param[],int ftype)
+{
+  int i,nn,nrfp,j,k,ntype,tli;
+  bool bFound=FALSE;
+  
+  nn    = *n;
+  nrfp  = NRFP(ftype);
+  ntype = get_atomtype_ntypes(at);
+
+  for(i=0; (i<nn); i++) 
+  {
+    if (typelist[i] == thistype)
+    {
+      /* This type number has already been added */
+      break;
+    }
+
+    /* Otherwise, check if the parameters are identical to any previously added type */
+    
+    bFound=TRUE;
+    for(j=0;j<ntype && bFound;j++) 
+    {
+      /* Check nonbonded parameters */
+      for(k=0;k<nrfp && bFound;k++) 
+      {
+        bFound=(param[ntype*typelist[i]+j].c[k]==param[ntype*thistype+j].c[k]);
+      }
+
+      /* Check radius, volume, surftens */
+      tli = typelist[i];
+      bFound = bFound && 
+       (get_atomtype_radius(tli,at) == get_atomtype_radius(thistype,at)) &&
+       (get_atomtype_vol(tli,at) == get_atomtype_vol(thistype,at)) &&
+       (get_atomtype_surftens(tli,at) == get_atomtype_surftens(thistype,at)) &&
+       (get_atomtype_atomnumber(tli,at) == get_atomtype_atomnumber(thistype,at));
+    }
+    if (bFound)
+    {
+      break;
+    }
+  }
+  
+  if (i == nn) {
+    if (debug)
+      fprintf(debug,"Renumbering atomtype %d to %d\n",thistype,nn);
+    if (nn == ntype)
+      gmx_fatal(FARGS,"Atomtype horror n = %d, %s, %d",nn,__FILE__,__LINE__);
+    typelist[nn]=thistype;
+    nn++;
+  }
+  *n = nn;
+  
+  return i;
+}
+
+void renum_atype(t_params plist[],t_topology *top,
+               int *wall_atomtype,
+               t_atomtype at,bool bVerbose)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) at;
+  
+  int      i,j,k,l,mi,mj,nat,nrfp,ftype,ntype;
+  t_param  *nbsnew;
+  int      *typelist;
+  real     *new_radius;
+  real     *new_vol;
+  real     *new_surftens;
+  int      *new_atomnumber;
+  
+  ntype = get_atomtype_ntypes(at);
+  snew(typelist,ntype);
+
+  if (bVerbose)
+    fprintf(stderr,"renumbering atomtypes...\n");
+
+  /* Since the bonded interactions have been assigned now,
+   * we want to reduce the number of atom types by merging 
+   * ones with identical nonbonded interactions, in addition
+   * to removing unused ones.
+   *
+   * With Generalized-Born electrostatics, or implicit solvent
+   * we also check that the atomtype radius, effective_volume
+   * and surface tension match.
+   *
+   * With QM/MM we also check that the atom numbers match
+   */
+  
+  /* Get nonbonded interaction type */
+  if (plist[F_LJ].nr > 0)
+    ftype=F_LJ;
+  else
+    ftype=F_BHAM;
+   
+  /* Renumber atomtypes by first making a list of which ones are actually used.
+   * We provide the list of nonbonded parameters so search_atomtypes
+   * can determine if two types should be merged. 
+   */    
+  nat=0;
+  for(i=0; (i<top->atoms.nr); i++) {
+    top->atoms.atom[i].type=
+      search_atomtypes(at,&nat,typelist,top->atoms.atom[i].type,
+                      plist[ftype].param,ftype);
+    top->atoms.atom[i].typeB=
+      search_atomtypes(at,&nat,typelist,top->atoms.atom[i].typeB,
+                      plist[ftype].param,ftype);
+  }
+
+  for(i=0; i<2; i++) {
+    if (wall_atomtype[i] >= 0)
+      wall_atomtype[i] = search_atomtypes(at,&nat,typelist,wall_atomtype[i],
+                                         plist[ftype].param,ftype);
+  }
+
+  snew(new_radius,nat);
+  snew(new_vol,nat);
+  snew(new_surftens,nat);
+  snew(new_atomnumber,nat);  
+
+  /* We now have a list of unique atomtypes in typelist */
+
+  if (debug)
+    pr_ivec(debug,0,"typelist",typelist,nat,TRUE);
+    
+  /* Renumber nlist */ 
+  nbsnew = NULL;
+  snew(nbsnew,plist[ftype].nr);
+
+  nrfp  = NRFP(ftype);
+  
+  for(i=k=0; (i<nat); i++)
+  {
+    mi=typelist[i];
+    for(j=0; (j<nat); j++,k++) 
+    {
+      mj=typelist[j];
+      for(l=0; (l<nrfp); l++)
+      {
+        nbsnew[k].c[l]=plist[ftype].param[ntype*mi+mj].c[l];
+      }
+    }  
+    new_radius[i]     = get_atomtype_radius(mi,at);
+    new_vol[i]        = get_atomtype_vol(mi,at);
+    new_surftens[i]   = get_atomtype_surftens(mi,at);
+    new_atomnumber[i] = get_atomtype_atomnumber(mi,at);
+  }
+  
+  for(i=0; (i<nat*nat); i++) {
+    for(l=0; (l<nrfp); l++)
+      plist[ftype].param[i].c[l]=nbsnew[i].c[l];
+  }
+  plist[ftype].nr=i;
+  top->idef.atnr = nat;
+  
+  sfree(ga->radius);
+  sfree(ga->vol);
+  sfree(ga->surftens);
+  sfree(ga->atomnumber);
+  
+  ga->radius     = new_radius;
+  ga->vol        = new_vol;
+  ga->surftens   = new_surftens;
+  ga->atomnumber = new_atomnumber;
+  
+  ga->nr=nat;
+
+  sfree(nbsnew);
+  sfree(typelist);
+}
+
+void copy_atomtype_atomtypes(t_atomtype atype,t_atomtypes *atomtypes)
+{
+  gpp_atomtype *ga = (gpp_atomtype *) atype;
+  int i,ntype;
+  
+  /* Copy the atomtype data to the topology atomtype list */
+  ntype = get_atomtype_ntypes(atype);
+  atomtypes->nr=ntype;
+  snew(atomtypes->radius,ntype);
+  snew(atomtypes->vol,ntype);
+  snew(atomtypes->surftens,ntype);
+  snew(atomtypes->atomnumber,ntype);
+
+
+  for(i=0; i<ntype; i++) {
+    atomtypes->radius[i]     = ga->radius[i];
+    atomtypes->vol[i]        = ga->vol[i];
+    atomtypes->surftens[i]   = ga->surftens[i];
+    atomtypes->atomnumber[i] = ga->atomnumber[i];
+  }
+}
+
diff --git a/src/kernel/gpp_atomtype.h b/src/kernel/gpp_atomtype.h
new file mode 100644 (file)
index 0000000..e03f01b
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * $Id$
+ * 
+ *                This source code is part of
+ * 
+ *                 G   R   O   M   A   C   S
+ * 
+ *          GROningen MAchine for Chemical Simulations
+ * 
+ *                        VERSION 3.2.0
+ * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team,
+ * check out http://www.gromacs.org for more information.
+
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * If you want to redistribute modifications, please consider that
+ * scientific software is very special. Version control is crucial -
+ * bugs must be traceable. We will be happy to consider code for
+ * inclusion in the official distribution, but derived work must not
+ * be called official GROMACS. Details are found in the README & COPYING
+ * files - if they are missing, get the official version at www.gromacs.org.
+ * 
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the papers on the package - you can find them in the top README file.
+ * 
+ * For more info, check our website at http://www.gromacs.org
+ * 
+ * And Hey:
+ * Gromacs Runs On Most of All Computer Systems
+ */
+
+#ifndef _gpp_atomtype_h
+#define _gpp_atomtype_h
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include "typedefs.h"
+#include "macros.h"
+
+typedef struct gpp_atomtype *t_atomtype;
+
+extern int get_atomtype_type(char *str,t_atomtype at);
+/* Return atomtype corresponding to case-insensitive str
+   or NOTSET if not found */
+
+extern int get_atomtype_ntypes(t_atomtype at);
+/* Return number of atomtypes */
+
+extern char *get_atomtype_name(int nt, t_atomtype at);
+/* Return name corresponding to atomtype nt, or NULL if not found */
+
+extern real get_atomtype_massA(int nt,t_atomtype at);
+extern real get_atomtype_massB(int nt,t_atomtype at);
+extern real get_atomtype_qA(int nt,t_atomtype at);
+extern real get_atomtype_qB(int nt,t_atomtype at);
+extern real get_atomtype_radius(int nt,t_atomtype at);
+extern real get_atomtype_vol(int nt,t_atomtype at);
+extern real get_atomtype_surftens(int nt,t_atomtype at);
+extern int get_atomtype_ptype(int nt,t_atomtype at);
+extern int get_atomtype_batype(int nt,t_atomtype at);
+extern int get_atomtype_atomnumber(int nt,t_atomtype at);
+
+/* Return the above variable for atomtype nt, or NOTSET if not found */
+
+extern real get_atomtype_nbparam(int nt,int param,t_atomtype at);
+/* Similar to the previous but returns the paramth parameter or NOTSET */
+
+extern t_atomtype init_atomtype(void);
+/* Return a new atomtype structure */
+
+extern void done_atomtype(t_atomtype *at);
+/* Free the memory in the structure */
+
+extern int set_atomtype(int nt,t_atomtype at,t_symtab *tab,
+                       t_atom *a,char *name,t_param *nb,
+                       int bondatomtype,
+                       real radius,real vol,real surftens,int atomnumber);
+/* Set the values of an existing atom type nt. Returns nt on success or
+   NOTSET on error. */ 
+
+extern int add_atomtype(t_atomtype at,t_symtab *tab,
+                       t_atom *a,char *name,t_param *nb,
+                       int bondatomtype,
+                       real radius,real vol,real surftens,real atomnumber);
+/* Add a complete new atom type to an existing atomtype structure. Returns
+   the number of the atom type. */
+
+extern void print_at (FILE * out, t_atomtype at);
+/* Print an atomtype record to a text file */
+
+extern void renum_atype(t_params plist[],t_topology *top,
+                       int *wall_atomtype,
+                       t_atomtype at,bool bVerbose);
+                       
+extern void copy_atomtype_atomtypes(t_atomtype atype,t_atomtypes *atypes);
+/* Copy from one structure to another */
+#endif /* _gpp_atomtype_h */
+
+
+
+
+
+
+
+
diff --git a/src/kernel/gpp_bond_atomtype.c b/src/kernel/gpp_bond_atomtype.c
new file mode 100644 (file)
index 0000000..134971e
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * $Id$
+ * 
+ *                This source code is part of
+ * 
+ *                 G   R   O   M   A   C   S
+ * 
+ *          GROningen MAchine for Chemical Simulations
+ * 
+ *                        VERSION 3.2.0
+ * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team,
+ * check out http://www.gromacs.org for more information.
+
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * If you want to redistribute modifications, please consider that
+ * scientific software is very special. Version control is crucial -
+ * bugs must be traceable. We will be happy to consider code for
+ * inclusion in the official distribution, but derived work must not
+ * be called official GROMACS. Details are found in the README & COPYING
+ * files - if they are missing, get the official version at www.gromacs.org.
+ * 
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the papers on the package - you can find them in the top README file.
+ * 
+ * For more info, check our website at http://www.gromacs.org
+ * 
+ * And Hey:
+ * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "smalloc.h"
+#include "sysstuff.h"
+#include "macros.h"
+#include "symtab.h"
+#include "string2.h"
+#include "gpp_bond_atomtype.h"
+
+typedef struct {
+  int           nr;            /* The number of atomtypes              */
+  char          ***atomname;   /* Names of the atomtypes               */
+} gpp_bond_atomtype;
+
+int get_bond_atomtype_type(char *str,t_bond_atomtype at)
+{
+  gpp_bond_atomtype *ga = (gpp_bond_atomtype *) at;
+  
+  int i;
+
+  for (i=0; (i<ga->nr); i++)
+    if (strcasecmp(str,*(ga->atomname[i])) == 0)
+      return i;
+  
+  return NOTSET;
+}
+
+char *get_bond_atomtype_name(int nt, t_bond_atomtype at)
+{
+  gpp_bond_atomtype *ga = (gpp_bond_atomtype *) at;
+  
+  if ((nt < 0) || (nt >= ga->nr))
+    return NULL;
+  
+  return *(ga->atomname[nt]);
+}
+
+t_bond_atomtype init_bond_atomtype(void)
+{
+  gpp_bond_atomtype *ga;
+  
+  snew(ga,1);
+  
+  return (t_bond_atomtype ) ga;
+}
+
+void add_bond_atomtype(t_bond_atomtype at,t_symtab *tab,
+                      char *name)
+{
+  gpp_bond_atomtype *ga = (gpp_bond_atomtype *) at;
+  
+  ga->nr++;
+  srenew(ga->atomname,ga->nr); 
+  ga->atomname[ga->nr-1] = put_symtab(tab,name);
+}
+
+void done_bond_atomtype(t_bond_atomtype *at)
+{
+  gpp_bond_atomtype *ga = (gpp_bond_atomtype *) *at;
+
+  sfree(ga->atomname);
+  ga->nr = 0;
+  sfree(ga);
+  
+  *at = NULL;
+}
diff --git a/src/kernel/gpp_bond_atomtype.h b/src/kernel/gpp_bond_atomtype.h
new file mode 100644 (file)
index 0000000..c6546f9
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * $Id$
+ * 
+ *                This source code is part of
+ * 
+ *                 G   R   O   M   A   C   S
+ * 
+ *          GROningen MAchine for Chemical Simulations
+ * 
+ *                        VERSION 3.2.0
+ * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team,
+ * check out http://www.gromacs.org for more information.
+
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * If you want to redistribute modifications, please consider that
+ * scientific software is very special. Version control is crucial -
+ * bugs must be traceable. We will be happy to consider code for
+ * inclusion in the official distribution, but derived work must not
+ * be called official GROMACS. Details are found in the README & COPYING
+ * files - if they are missing, get the official version at www.gromacs.org.
+ * 
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the papers on the package - you can find them in the top README file.
+ * 
+ * For more info, check our website at http://www.gromacs.org
+ * 
+ * And Hey:
+ * Gromacs Runs On Most of All Computer Systems
+ */
+
+#ifndef _gpp_bondatomtype_h
+#define _gpp_bondatomtype_h
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include "typedefs.h"
+#include "macros.h"
+
+typedef struct gpp_bondatomtype *t_bond_atomtype;
+
+extern int get_bond_atomtype_type(char *str,t_bond_atomtype at);
+/* Return atomtype corresponding to case-insensitive str
+   or NOTSET if not found */
+
+extern char *get_bond_atomtype_name(int nt, t_bond_atomtype at);
+/* Return name corresponding to atomtype nt, or NULL if not found */
+
+extern t_bond_atomtype init_bond_atomtype(void);
+/* Return a new atomtype structure */
+
+extern void done_bond_atomtype(t_bond_atomtype *at);
+/* Free the memory in the structure */
+
+extern void add_bond_atomtype(t_bond_atomtype at,t_symtab *tab,
+                             char *name);
+/* Add a complete new atom type to an existing atomtype structure */
+
+#endif /* _gpp_bond_atomtype_h */
+
+
+
+
+
+
+
+
diff --git a/src/kernel/gpp_tomorse.h b/src/kernel/gpp_tomorse.h
new file mode 100644 (file)
index 0000000..68f051e
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * $Id$
+ * 
+ *                This source code is part of
+ * 
+ *                 G   R   O   M   A   C   S
+ * 
+ *          GROningen MAchine for Chemical Simulations
+ * 
+ *                        VERSION 3.2.0
+ * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team,
+ * check out http://www.gromacs.org for more information.
+
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * If you want to redistribute modifications, please consider that
+ * scientific software is very special. Version control is crucial -
+ * bugs must be traceable. We will be happy to consider code for
+ * inclusion in the official distribution, but derived work must not
+ * be called official GROMACS. Details are found in the README & COPYING
+ * files - if they are missing, get the official version at www.gromacs.org.
+ * 
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the papers on the package - you can find them in the top README file.
+ * 
+ * For more info, check our website at http://www.gromacs.org
+ * 
+ * And Hey:
+ * Gromacs Runs On Most of All Computer Systems
+ */
+
+#ifndef _tomorse_h
+#define _tomorse_h
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include "typedefs.h"
+#include "macros.h"
+
+extern void convert_harmonics(int nrmols,t_molinfo mols[],t_atomtype atype);
+
+#endif /* _grompp_h */
+
+
+
+
+
+
+
+
index 5e6680da802857cd4bb9b1640e54b8a9c4c8418d..2be0149a78469e68f5a4e6359cbd11dd7a7cfe7b 100644 (file)
@@ -76,6 +76,8 @@
 #include "enxio.h"
 #include "perf_est.h"
 #include "compute_io.h"
+#include "gpp_atomtype.h"
+#include "gpp_tomorse.h"
 
 static int rm_interactions(int ifunc,int nrmols,t_molinfo mols[])
 {
@@ -159,41 +161,6 @@ static void check_cg_sizes(char *topfn,t_topology *sys)
   }
 }
 
-static void check_pairs(int nrmols,t_molinfo mi[],int ntype,t_param *nb)
-{
-  int      i,j,jj,k,ai,aj,taiA,tajA,taiB,tajB,bLJ;
-  t_params *p;
-  
-  for(i=0; (i<nrmols); i++) {
-    p = &(mi[i].plist[F_LJ14]);
-    for(j=jj=0; (j<p->nr); j++) {
-      /* Extract atom types and hence the index in the nbf matrix */
-      ai = p->param[j].a[0];
-      aj = p->param[j].a[1];
-      taiA = mi[i].atoms.atom[ai].type;
-      tajA = mi[i].atoms.atom[aj].type;
-      taiB = mi[i].atoms.atom[ai].typeB;
-      tajB = mi[i].atoms.atom[aj].typeB;
-      
-      bLJ  = FALSE;
-      for(k=0; (k<MAXFORCEPARAM); k++)
-       bLJ = bLJ || (((nb[taiA].c[k]*nb[tajA].c[k]) != 0) || 
-                     ((nb[taiB].c[k]*nb[tajB].c[k]) != 0));
-      if (bLJ) {
-       cp_param(&(p->param[jj]),&(p->param[j]));
-       jj++;
-      }
-      else if (debug) {
-       fprintf(debug,"Removed 1-4 interaction between atoms %d and %d (within mol %s)\n",
-               ai+1,aj+1,*(mi[i].name));
-      }
-    }
-    fprintf(stderr,"Removed %d 1-4 interactions for molecule %s\n",
-           p->nr-jj,*(mi[i].name));
-    p->nr = jj;
-  }
-}
-
 static void check_vel(t_atoms *atoms,rvec v[])
 {
   int i;
@@ -226,10 +193,10 @@ static void
 new_status(char *topfile,char *topppfile,char *confin,
           t_gromppopts *opts,t_inputrec *ir,bool bZero,
           bool bGenVel,bool bVerbose,t_state *state,
-          t_atomtype *atype,t_topology *sys,
+          t_atomtype atype,t_topology *sys,
           t_molinfo *msys,t_params plist[],int *comb,real *reppow,
           bool bEnsemble,bool bMorse,
-          bool bCheckPairs,int *nerror)
+          int *nerror)
 {
   t_molinfo   *molinfo=NULL;
   t_simsystem *Sims=NULL;
@@ -244,9 +211,6 @@ new_status(char *topfile,char *topppfile,char *confin,
   msys->name=do_top(bVerbose,topfile,topppfile,opts,bZero,&(sys->symtab),
                    plist,comb,reppow,atype,&nrmols,&molinfo,ir,&Nsim,&Sims);
   
-  if (bCheckPairs)
-    check_pairs(nrmols,molinfo,atype->nr,atype->nb);
-  
   if (bMorse)
     convert_harmonics(nrmols,molinfo,atype);
 
@@ -481,171 +445,7 @@ static void gen_posres(t_params *pr, char *fnA, char *fnB,
   }
 }
 
-static int search_atomtypes(t_atomtype *at,int *n,int typelist[],int thistype,
-                           t_param param[],int ftype)
-{
-  int i,nn,nrfp,j,k,found;
-
-  nn    = *n;
-  nrfp  = NRFP(ftype);
-
-  for(i=0; (i<nn); i++) 
-  {
-    if (typelist[i] == thistype)
-    {
-      /* This type number has already been added */
-      break;
-    }
-
-    /* Otherwise, check if the parameters are identical to any previously added type */
-    
-    found=1;
-    for(j=0;j<at->nr && found;j++) 
-    {
-      /* Check nonbonded parameters */
-      for(k=0;k<nrfp && found;k++) 
-      {
-        found=(param[at->nr*typelist[i]+j].c[k]==param[at->nr*thistype+j].c[k]);
-      }
-
-      /* Check radius, volume, surftens */
-      found = found && 
-          ((at->radius[typelist[i]] == at->radius[thistype]) &&
-           (at->vol[typelist[i]] == at->vol[thistype]) &&
-           (at->surftens[typelist[i]] == at->surftens[thistype]) &&    
-           (at->atomnumber[typelist[i]] ==     at->atomnumber[thistype]));
-    }
-    if (found)
-    {
-      break;
-    }
-  }
-  
-  if (i == nn) {
-    if (debug)
-      fprintf(debug,"Renumbering atomtype %d to %d\n",thistype,nn);
-    if (nn == at->nr)
-      gmx_fatal(FARGS,"Atomtype horror n = %d, %s, %d",nn,__FILE__,__LINE__);
-    typelist[nn]=thistype;
-    nn++;
-  }
-  *n = nn;
-  
-  return i;
-}
-
-static int renum_atype(t_params plist[],t_topology *top,int *wall_atomtype,
-                      t_atomtype *at,bool bVerbose)
-{
-  int      i,j,k,l,mi,mj,nat,nrfp,ftype;
-  t_param  *nbsnew;
-  int      *typelist;
-  real     *new_radius;
-  real     *new_vol;
-  real     *new_surftens;
-  int      *new_atomnumber;
-  
-  snew(typelist,at->nr);
-
-  if (bVerbose)
-    fprintf(stderr,"renumbering atomtypes...\n");
-
-  /* Since the bonded interactions have been assigned now,
-   * we want to reduce the number of atom types by merging 
-   * ones with identical nonbonded interactions, in addition
-   * to removing unused ones.
-   *
-   * With Generalized-Born electrostatics, or implicit solvent
-   * we also check that the atomtype radius, effective_volume
-   * and surface tension match.
-   *
-   * With QM/MM we also check that the atom numbers match
-   */
-  
-  /* Get nonbonded interaction type */
-  if (plist[F_LJ].nr > 0)
-    ftype=F_LJ;
-  else
-    ftype=F_BHAM;
-   
-  /* Renumber atomtypes by first making a list of which ones are actually used.
-   * We provide the list of nonbonded parameters so search_atomtypes
-   * can determine if two types should be merged. 
-   */    
-  nat=0;
-  for(i=0; (i<top->atoms.nr); i++) {
-    top->atoms.atom[i].type=
-      search_atomtypes(at,&nat,typelist,top->atoms.atom[i].type,
-                      plist[ftype].param,ftype);
-    top->atoms.atom[i].typeB=
-      search_atomtypes(at,&nat,typelist,top->atoms.atom[i].typeB,
-                      plist[ftype].param,ftype);
-  }
-
-  for(i=0; i<2; i++) {
-    if (wall_atomtype[i] >= 0)
-      wall_atomtype[i] = search_atomtypes(at,&nat,typelist,wall_atomtype[i],
-                                         plist[ftype].param,ftype);
-  }
-
-  snew(new_radius,nat);
-  snew(new_vol,nat);
-  snew(new_surftens,nat);
-  snew(new_atomnumber,nat);  
-
-  /* We now have a list of unique atomtypes in typelist */
-
-  if (debug)
-    pr_ivec(debug,0,"typelist",typelist,nat,TRUE);
-    
-  /* Renumber nlist */ 
-  nbsnew = NULL;
-  snew(nbsnew,plist[ftype].nr);
-
-  nrfp  = NRFP(ftype);
-  
-  for(i=k=0; (i<nat); i++)
-  {
-    mi=typelist[i];
-    for(j=0; (j<nat); j++,k++) 
-    {
-      mj=typelist[j];
-      for(l=0; (l<nrfp); l++)
-      {
-        nbsnew[k].c[l]=plist[ftype].param[at->nr*mi+mj].c[l];
-      }
-    }  
-    new_radius[i]     = at->radius[mi];
-    new_vol[i]        = at->vol[mi];
-    new_surftens[i]   = at->surftens[mi];
-    new_atomnumber[i] = at->atomnumber[mi];
-  }
-  
-  for(i=0; (i<nat*nat); i++) {
-    for(l=0; (l<nrfp); l++)
-      plist[ftype].param[i].c[l]=nbsnew[i].c[l];
-  }
-  plist[ftype].nr=i;
-  
-  sfree(at->radius);
-  sfree(at->vol);
-  sfree(at->surftens);
-  sfree(at->atomnumber);
-  
-  at->radius     = new_radius;
-  at->vol        = new_vol;
-  at->surftens   = new_surftens;
-  at->atomnumber = new_atomnumber;
-  
-  at->nr=nat;
-
-  sfree(nbsnew);
-  sfree(typelist);
-  
-  return nat;
-}
-
-static void set_wall_atomtype(t_atomtype *at,t_gromppopts *opts,
+static void set_wall_atomtype(t_atomtype at,t_gromppopts *opts,
                              t_inputrec *ir)
 {
   int i;
@@ -653,7 +453,7 @@ static void set_wall_atomtype(t_atomtype *at,t_gromppopts *opts,
   if (ir->nwall > 0)
     fprintf(stderr,"Searching the wall atom type(s)\n");
   for(i=0; i<ir->nwall; i++)
-    ir->wall_atomtype[i] = at2type(opts->wall_atomtype[i],at);
+    ir->wall_atomtype[i] = get_atomtype_type(opts->wall_atomtype[i],at);
 }
 
 static int count_constraints(t_params plist[])
@@ -756,7 +556,7 @@ int main (int argc, char *argv[])
   t_gromppopts *opts;
   t_topology   *sys;
   t_molinfo    msys;
-  t_atomtype   *atype;
+  t_atomtype   atype;
   t_inputrec   *ir;
   int          natoms,nvsite,comb;
   t_params     *plist;
@@ -764,7 +564,7 @@ int main (int argc, char *argv[])
   matrix       box;
   real         max_spacing,reppow;
   char         fn[STRLEN],fnB[STRLEN],*mdparin;
-  int          nerror;
+  int          nerror,ntype;
   bool         bNeedVel,bGenVel;
   bool         have_radius,have_vol,have_surftens;
   bool         have_atomnumber;
@@ -786,7 +586,7 @@ int main (int argc, char *argv[])
 
   /* Command line options */
   static bool bVerbose=TRUE,bRenum=TRUE;
-  static bool bRmVSBds=TRUE,bCheckPairs=FALSE,bZero=FALSE;
+  static bool bRmVSBds=TRUE,bZero=FALSE;
   static int  i,maxwarn=0;
   static real fr_time=-1;
   t_pargs pa[] = {
@@ -798,8 +598,6 @@ int main (int argc, char *argv[])
       "Remove constant bonded interactions with virtual sites" },
     { "-maxwarn", FALSE, etINT,  {&maxwarn},
       "Number of allowed warnings during input processing" },
-    { "-check14", FALSE, etBOOL, {&bCheckPairs},
-      "Remove 1-4 interactions without Van der Waals" },
     { "-zero",    FALSE, etBOOL, {&bZero},
       "Set parameters for bonded interactions without defaults to zero instead of generating an error" },
     { "-renum",   FALSE, etBOOL, {&bRenum},
@@ -840,7 +638,7 @@ int main (int argc, char *argv[])
   snew(plist,F_NRE);
   init_plist(plist);
   snew(sys,1);
-  snew(atype,1);
+  atype = init_atomtype();
   if (debug)
     pr_symtab(debug,0,"Just opened",&sys->symtab);
     
@@ -851,7 +649,7 @@ int main (int argc, char *argv[])
             opts,ir,bZero,bGenVel,bVerbose,&state,
             atype,sys,&msys,plist,&comb,&reppow,
             (opts->eDisre==edrEnsemble),opts->bMorse,
-            bCheckPairs,&nerror);
+            &nerror);
   
   if (debug)
     pr_symtab(debug,0,"After new_status",&sys->symtab);
@@ -873,12 +671,13 @@ int main (int argc, char *argv[])
 
   /* If we are doing GBSA, check that we got the parameters we need */
   have_radius=have_vol=have_surftens=TRUE;
-  for(i=0;i<atype->nr;i++) {
-    have_radius=have_radius && (atype->radius[i]>0);
-    have_vol=have_vol && (atype->vol[i]>0);
-    have_surftens=have_surftens && (atype->surftens[i]>=0);
+  ntype = get_atomtype_ntypes(atype);
+  for(i=0; (i<ntype); i++) {
+    have_radius   = have_radius && (get_atomtype_radius(i,atype) > 0);
+    have_vol      = have_vol && (get_atomtype_vol(i,atype) > 0);
+    have_surftens = have_surftens && (get_atomtype_surftens(i,atype) >= 0);
   }
-  if(!have_radius && ir->coulombtype==eelGB) {
+  if (!have_radius && ir->coulombtype==eelGB) {
     fprintf(stderr,"Can't do GB electrostatics; the forcefield is missing values for\n"
                "atomtype radii, or they might be zero.");
     nerror++;
@@ -896,8 +695,8 @@ int main (int argc, char *argv[])
   
   /* If we are doing QM/MM, check that we got the atom numbers */
   have_atomnumber = TRUE;
-  for (i=0;i<atype->nr;i++) {
-    have_atomnumber = have_atomnumber && (atype->atomnumber[i]>=0);
+  for (i=0; i<ntype; i++) {
+    have_atomnumber = have_atomnumber && (get_atomtype_atomnumber(i,atype) >= 0);
   }
   if (!have_atomnumber && ir->bQMMM)
   {
@@ -947,30 +746,20 @@ int main (int argc, char *argv[])
     clean_vsite_bondeds(msys.plist,sys->atoms.nr,bRmVSBds);
   
   set_wall_atomtype(atype,opts,ir);
-  if (bRenum) 
-    atype->nr = renum_atype(plist, sys, ir->wall_atomtype, atype, bVerbose);
+  if (bRenum) {
+    renum_atype(plist, sys, ir->wall_atomtype, atype, bVerbose);
+    ntype = get_atomtype_ntypes(atype);
+  }
   
   /* Copy the atomtype data to the topology atomtype list */
-  sys->atomtypes.nr=atype->nr;
-  snew(sys->atomtypes.radius,atype->nr);
-  snew(sys->atomtypes.vol,atype->nr);
-  snew(sys->atomtypes.surftens,atype->nr);
-  snew(sys->atomtypes.atomnumber,atype->nr);
-
-
-  for(i=0;i<atype->nr;i++) {
-    sys->atomtypes.radius[i]=atype->radius[i];
-    sys->atomtypes.vol[i]=atype->vol[i];
-    sys->atomtypes.surftens[i]=atype->surftens[i];
-    sys->atomtypes.atomnumber[i] = atype->atomnumber[i];
-  }
+  copy_atomtype_atomtypes(atype,&(sys->atomtypes));
 
   if (debug)
     pr_symtab(debug,0,"After renum_atype",&sys->symtab);
 
   if (bVerbose) 
     fprintf(stderr,"converting bonded parameters...\n");
-  convert_params(atype->nr, plist, msys.plist, comb, reppow, &sys->idef);
+  convert_params(ntype, plist, msys.plist, comb, reppow, &sys->idef);
   
   if (debug)
     pr_symtab(debug,0,"After convert_params",&sys->symtab);
index 88bcf858a124e5f20932c418a991e4281b7e156b..b4db7cf268f5e6ed6e9d8c3ee641e62feed6d922 100644 (file)
@@ -40,6 +40,7 @@
 #include "typedefs.h"
 #include "pdbio.h"
 #include "grompp.h"
+#include "gpp_atomtype.h"
 
 /* Used for reading .rtp/.tdb */
 /* ebtsBONDS must be the first, new types can be added to the end */
@@ -117,7 +118,7 @@ typedef struct {
   int         nah;
   t_symtab    tab;
   int         *rN, *rC;
-  t_atomtype  *atype;
+  t_atomtype  atype;
   /* protonated topology: */
   t_atoms     *patoms;
   /* unprotonated topology: */
index 6d0d1447120eda6044045f507052fab4f9402e50..829574bad6354ff1ca302b5e85819960f26c8f8f 100644 (file)
@@ -168,16 +168,21 @@ static int match_str(char *atom,char *template)
 }
 
 int nm2type(x2top_nm2t nm2t,t_symtab *tab,t_atoms *atoms,
-           t_atomtype *atype,int *nbonds,t_params *bonds)
+           t_atomtype atype,int *nbonds,t_params *bonds)
 {
   x2top_nm2type *nm2type = (x2top_nm2type *) nm2t;
-  int cur = 0;
-#define prev (1-cur)
-  int i,j,k,m,n,nresolved,nb,maxbond,ai,aj,best,im,nqual[2][ematchNR];
-  int *bbb,*n_mask,*m_mask,**match,**quality;
-  char *aname_i,*aname_m,*aname_n,*type;
-  double qq,mm;
-      
+  int     cur = 0;
+#define   prev (1-cur)
+  int     i,j,k,m,n,nresolved,nb,maxbond;
+  int     ai,aj,best,im,nqual[2][ematchNR];
+  int     *bbb,*n_mask,*m_mask,**match,**quality;
+  char    *aname_i,*aname_m,*aname_n,*type;
+  double  alpha,mm;
+  t_atom  *atom;
+  t_param *param;
+  
+  snew(atom,1);
+  snew(param,1);
   maxbond = 0;
   for(i=0; (i<atoms->nr); i++) 
     maxbond = max(maxbond,nbonds[i]);
@@ -268,35 +273,25 @@ int nm2type(x2top_nm2t nm2t,t_symtab *tab,t_atoms *atoms,
       }
     }
     if (best != -1) {
-      qq   = nm2type->nm2t[best].alpha;
-      mm   = nm2type->nm2t[best].m;
-      type = nm2type->nm2t[best].type;
-      
-      for(k=0; (k<atype->nr); k++) {
-       if (strcasecmp(*atype->atomname[k],type) == 0)
-         break;
+      alpha = nm2type->nm2t[best].alpha;
+      mm    = nm2type->nm2t[best].m;
+      type  = nm2type->nm2t[best].type;
+
+      if ((k = get_atomtype_type(type,atype)) == NOTSET) {
+       atom->type = atom->typeB = get_atomtype_ntypes(atype);
+       atom->qB = alpha;
+       atom->m = atom->mB = mm;
+       add_atomtype(atype,tab,atom,type,param,
+                    atom->type,0,0,0,0);
+      }
+      else {
+       atoms->atom[i].type  = k;
+       atoms->atom[i].typeB = k;
+       atoms->atom[i].q  = 0;
+       atoms->atom[i].qB = alpha;
+       atoms->atom[i].m  = mm;
+       atoms->atom[i].mB = mm;
       }
-      if (k == atype->nr) {
-       /* New atomtype */
-       atype->nr++;
-       srenew(atype->atomname,atype->nr);
-       srenew(atype->atom,atype->nr);
-       srenew(atype->bondatomtype,atype->nr);
-       atype->atomname[k]   = put_symtab(tab,type);
-       atype->bondatomtype[k] = k; /* Set bond_atomtype identical to atomtype */
-       atype->atom[k].type  = k;
-       atype->atom[k].typeB = k;
-       atype->atom[k].q     = 0;
-       atype->atom[k].qB    = qq;
-       atype->atom[k].m     = mm;
-       atype->atom[k].mB    = mm;
-      }      
-      atoms->atom[i].type  = k;
-      atoms->atom[i].typeB = k;
-      atoms->atom[i].q  = 0;
-      atoms->atom[i].qB = qq;
-      atoms->atom[i].m  = mm;
-      atoms->atom[i].mB = mm;
       nresolved++;
     }
     else {
@@ -306,8 +301,13 @@ int nm2type(x2top_nm2t nm2t,t_symtab *tab,t_atoms *atoms,
   }
   sfree(bbb);
   sfree(n_mask);
+  for(i=0; (i<maxbond); i++)
+    sfree(match[i]);
+  sfree(match);
   sfree(m_mask);
-    
+  sfree(atom);
+  sfree(param);
+      
   return nresolved;
 }
 
index db1e987c1c70feb398d624de96493611590e4d2a..028c63bb5fe944a2228a0ce6346f3a2731407793 100644 (file)
@@ -659,7 +659,7 @@ int main(int argc, char *argv[])
   t_restp    *restp;
   t_hackblock *ah;
   t_symtab   symtab;
-  t_atomtype *atype;
+  t_atomtype atype;
   t_aa_names *aan;
   char       fn[256],*top_fn,itp_fn[STRLEN],posre_fn[STRLEN],buf_fn[STRLEN];
   char       molname[STRLEN],title[STRLEN],resname[STRLEN],quote[STRLEN];
index f2e4a0fd5d2a6f1ac1d15e4432ba65b174b4ad1f..5c407f5458da714b2222dc0d9733722f9f1f3662 100644 (file)
@@ -157,7 +157,7 @@ choose_ff(char *forcefield, int maxlen)
 }
 
 
-static int name2type(t_atoms *at, int **cgnr, t_atomtype *atype, 
+static int name2type(t_atoms *at, int **cgnr, t_atomtype atype, 
                     t_restp restp[])
 {
   int     i,j,prevresnr,resnr,i0,prevcg,cg,curcg;
@@ -204,7 +204,8 @@ static int name2type(t_atoms *at, int **cgnr, t_atomtype *atype,
       j=search_jtype(&restp[resnr],name,bNterm);
       at->atom[i].type = restp[resnr].atom[j].type;
       at->atom[i].q    = restp[resnr].atom[j].q;
-      at->atom[i].m    = atype->atom[restp[resnr].atom[j].type].m;
+      at->atom[i].m    = get_atomtype_massA(restp[resnr].atom[j].type,
+                                           atype);
       cg = restp[resnr].cgnr[j];
       if ( (cg != prevcg) || (resnr != prevresnr) )
        curcg++;
@@ -320,7 +321,7 @@ void print_top_mols(FILE *out, char *title, char *water,
 
 void write_top(FILE *out, char *pr,char *molname,
               t_atoms *at,int bts[],t_params plist[],t_excls excls[],
-              t_atomtype *atype,int *cgnr, int nrexcl)
+              t_atomtype atype,int *cgnr, int nrexcl)
      /* NOTE: nrexcl is not the size of *excl! */
 {
   if (at && atype && cgnr) {
@@ -646,7 +647,7 @@ void get_hackblocks_rtp(t_hackblock **hb, t_restp **restp,
 }
 
 void pdb2top(FILE *top_file, char *posre_fn, char *molname,
-            t_atoms *atoms, rvec **x, t_atomtype *atype, t_symtab *tab,
+            t_atoms *atoms, rvec **x, t_atomtype atype, t_symtab *tab,
             int bts[], int nrtp, t_restp   rtp[],
             int nterpairs,t_hackblock **ntdb, t_hackblock **ctdb,
             int *rn, int *rc, bool bMissing,
index fff3e97a0f953916808db3cada17cf2ea0bbdf7e..9a0209019995d01a9ec9b684feb11b654e55e705 100644 (file)
@@ -70,7 +70,7 @@ extern void print_top_mols(FILE *out, char *title, char *water,
 
 extern void pdb2top(FILE *top_file, char *posre_fn, char *molname,
                    t_atoms *atoms,rvec **x,
-                   t_atomtype *atype,t_symtab *tab,
+                   t_atomtype atype,t_symtab *tab,
                    int bts[],
                    int nrtp, t_restp rtp[],
                    int nterpairs, t_hackblock **ntdb, t_hackblock **ctdb,
@@ -88,7 +88,7 @@ extern void print_sums(t_atoms *atoms, bool bSystem);
 
 extern void write_top(FILE *out, char *pr,char *molname,
                      t_atoms *at,int bts[],t_params plist[],t_excls excls[],
-                     t_atomtype *atype,int *cgnr, int nrexcl);
+                     t_atomtype atype,int *cgnr, int nrexcl);
 /* NOTE: nrexcl is not the size of *excl! */
 
 #endif /* _pdb2top_h */
index bb821cbc1c3509f4a13a57665783440de13bc67c..4e51fa7d0294d736a66449412713426f715dd184 100644 (file)
 #include "resall.h"
 #include "pgutil.h"
 
-t_atomtype *read_atype(char *adb,t_symtab *tab)
+t_atomtype read_atype(char *adb,t_symtab *tab)
 {
-#define MAXAT 5000
   FILE       *in;
   char       aadb[STRLEN];
   char       buf[STRLEN],name[STRLEN];
   double     m;
-  int        nratt;
-  t_atomtype *at;
-
-  sprintf(aadb,"%s.atp",adb);
-  in=libopen(aadb);
+  int        nratt=0;
+  t_atomtype at;
+  t_atom     *a;
+  t_param    *nb;
   
-  snew(at,1);
-  snew(at->atom,MAXAT);
-  snew(at->atomname,MAXAT);
+  sprintf(aadb,"%s.atp",adb);
+  in = libopen(aadb);
+  at = init_atomtype();
+  snew(a,1);
+  snew(nb,1);
   
-  for(nratt=0; ; nratt++) {
-    if (nratt >= MAXAT)
-      gmx_fatal(FARGS,"nratt >= MAXAT(%d). Increase the latter",MAXAT);
-    if (feof(in))
-      break;
-
+  while(!feof(in)) {
     /* Skip blank or comment-only lines */
     do {
       fgets2(buf,STRLEN,in);
-      if(buf) {
+      if (buf) {
        strip_comment(buf);
        trim(buf);
       }
     } while (buf && strlen(buf)==0);
-
-    if(buf==NULL)
-      break;
     
-    if (sscanf(buf,"%s%lf",name,&m) != 2)
-      break;
-    set_at(&(at->atom[nratt]),m,0.0,nratt,0);
-    at->atomname[nratt]=put_symtab(tab,name);
-    fprintf(stderr,"\rAtomtype %d",nratt+1);
+    if ((buf != NULL) && (sscanf(buf,"%s%lf",name,&m) == 2)) {
+      a->m = m;
+      add_atomtype(at,tab,a,name,nb,0,0,0,0,0);
+      fprintf(stderr,"\rAtomtype %d",nratt+1);
+    }
   }
   fclose(in);
   fprintf(stderr,"\n");
-  at->nr=nratt;
   
   return at;
 }
 
-static void print_resatoms(FILE *out,t_atomtype *atype,t_restp *rtp)
+static void print_resatoms(FILE *out,t_atomtype atype,t_restp *rtp)
 {
   int j,tp;
+  char *tpnm;
   
   /* fprintf(out,"%5s\n",rtp->resname);
      fprintf(out,"%5d\n",rtp->natom); */
@@ -107,17 +99,17 @@ static void print_resatoms(FILE *out,t_atomtype *atype,t_restp *rtp)
   fprintf(out," [ atoms ]\n");
   
   for(j=0; (j<rtp->natom); j++) {
-    tp=rtp->atom[j].type;
-    if ((tp < 0) || (tp >= atype->nr))
-      gmx_fatal(FARGS,"tp (%d) out of range (0 .. %d)",tp,atype->nr);
+    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]),*(atype->atomname[tp]),
-           rtp->atom[j].q,rtp->cgnr[j]);
+           *(rtp->atomname[j]),tpnm,rtp->atom[j].q,rtp->cgnr[j]);
   }
 }
 
 static bool read_atoms(FILE *in,char *line,
-                      t_restp *r0,t_symtab *tab,t_atomtype *atype)
+                      t_restp *r0,t_symtab *tab,t_atomtype atype)
 {
   int    i,j,cg,maxentries;
   char   buf[256],buf1[256];
@@ -141,14 +133,12 @@ static bool read_atoms(FILE *in,char *line,
     r0->atomname[i]=put_symtab(tab,buf);
     r0->atom[i].q=q;
     r0->cgnr[i]=cg;
-    for(j=0; (j<atype->nr); j++)
-      if (strcasecmp(buf1,*(atype->atomname[j])) == 0)
-       break;
-    if (j == atype->nr)
+    j = get_atomtype_type(buf1,atype);
+    if (j == NOTSET)
       gmx_fatal(FARGS,"Atom type %s (residue %s) not found in atomtype "
                  "database",buf1,r0->resname);
     r0->atom[i].type=j;
-    r0->atom[i].m=atype->atom[j].m;
+    r0->atom[i].m=get_atomtype_massA(j,atype);
     i++;
   }
   r0->natom=i;
@@ -247,7 +237,7 @@ void clear_t_restp(t_restp *rrtp)
 }
 
 int read_resall(char *ff, int bts[], t_restp **rtp, 
-               t_atomtype *atype, t_symtab *tab, bool *bAlldih, int *nrexcl,
+               t_atomtype atype, t_symtab *tab, bool *bAlldih, int *nrexcl,
                bool *HH14, bool *bRemoveDih)
 {
   FILE      *in;
@@ -383,7 +373,7 @@ int read_resall(char *ff, int bts[], t_restp **rtp,
 }
 
 void print_resall(FILE *out, int bts[], int nrtp, t_restp rtp[],
-                 t_atomtype *atype, bool bAlldih, int nrexcl, 
+                 t_atomtype atype, bool bAlldih, int nrexcl, 
                  bool HH14, bool bRemoveDih)
 {
   int i,bt;
index d2f6dd733792aa432af223be9be704942cbf5ee8..b567c26d5bb8497158239778ede90a3cea9d554b 100644 (file)
 
 #include "typedefs.h"
 #include "hackblock.h"
+#include "gpp_atomtype.h"
 #include "grompp.h"
 
 extern t_restp *search_rtp(char *key,int nrtp,t_restp rtp[]);
 /* Search for an entry in the rtp database */
 
-extern t_atomtype *read_atype(char *adb,t_symtab *tab);
+extern t_atomtype read_atype(char *adb,t_symtab *tab);
 /* read atom type database */
 
 extern int read_resall(char *resdb, int bts[], t_restp **rtp, 
-                      t_atomtype *atype, t_symtab *tab, bool *bAlldih, int *nrexcl,
+                      t_atomtype atype, t_symtab *tab, bool *bAlldih, int *nrexcl,
                       bool *HH14, bool *bRemoveDih);
 /* read rtp database */
 
 extern void print_resall(FILE *out, int bts[], int nrtp, t_restp rtp[], 
-                        t_atomtype *atype, bool bAlldih, int nrexcl,
+                        t_atomtype atype, bool bAlldih, int nrexcl,
                         bool HH14, bool remove_dih);
 /* write rtp database */
 
index ff813c4ad800646505251bd56183434a9bb7acb0..cf5d2ea7bac1597ad19204841e3478f9e9323b24 100644 (file)
@@ -75,7 +75,7 @@ int find_kw(char *keyw)
 
 #define FATAL() gmx_fatal(FARGS,"Reading Termini Database: not enough items on line\n%s",line)
 
-static void read_atom(char *line, t_atom *a, t_atomtype *atype, int *cgnr)
+static void read_atom(char *line, t_atom *a, t_atomtype atype, int *cgnr)
 {
   int    i, n;
   char   type[12];
@@ -85,18 +85,18 @@ static void read_atom(char *line, t_atom *a, t_atomtype *atype, int *cgnr)
     gmx_fatal(FARGS,"Reading Termini Database: expected %d items of atom data in stead of %d on line\n%s", 3, i, line);
   a->m=m;
   a->q=q;
-  a->type=at2type(type,atype);
+  a->type=get_atomtype_type(type,atype);
   if ( sscanf(line+n,"%d", cgnr) != 1 )
     *cgnr = NOTSET;
 }
 
-static void print_atom(FILE *out,t_atom *a,t_atomtype *atype,char *newnm)
+static void print_atom(FILE *out,t_atom *a,t_atomtype atype,char *newnm)
 {
   fprintf(out,"\t%s\t%g\t%g\n",
-         type2nm(a->type,atype),a->m,a->q);
+         get_atomtype_name(a->type,atype),a->m,a->q);
 }
 
-static void print_ter_db(char *ff,char C,int nb,t_hackblock tb[],t_atomtype *atype) 
+static void print_ter_db(char *ff,char C,int nb,t_hackblock tb[],t_atomtype atype) 
 {
   FILE *out;
   int i,j,k,bt,nrepl,nadd,ndel;
@@ -159,7 +159,7 @@ static void print_ter_db(char *ff,char C,int nb,t_hackblock tb[],t_atomtype *aty
   fclose(out);
 }
 
-int read_ter_db(char *FF,char ter,t_hackblock **tbptr,t_atomtype *atype)
+int read_ter_db(char *FF,char ter,t_hackblock **tbptr,t_atomtype atype)
 {
   FILE       *in;
   char       inf[STRLEN],header[STRLEN],buf[STRLEN],line[STRLEN];
index 573f33215a19a290903fa4a31667fd63bcceed2c..133c83d649d0f380c8994be891569422c024814a 100644 (file)
@@ -42,7 +42,7 @@
 #include "grompp.h"
 
 extern int read_ter_db(char *FF,char ter,
-                      t_hackblock **tbptr,t_atomtype *atype);
+                      t_hackblock **tbptr,t_atomtype atype);
 /* Read database for N&C terminal hacking */
 
 extern t_hackblock **filter_ter(int nb,t_hackblock tb[],char *resname,int *nret);
index 7bd13c7ebc38807d31adc5f3034d640ec6419820..fcd7b8a1adeeece51e19c9e83fc0dfafd8f69264 100644 (file)
@@ -48,6 +48,8 @@
 #include "smalloc.h"
 #include "toputil.h"
 #include "gmx_fatal.h"
+#include "gpp_atomtype.h"
+#include "gpp_tomorse.h"
 
 typedef struct {
   char *ai,*aj;
@@ -170,7 +172,7 @@ static real search_e_diss(int n2m,t_2morse t2m[],char *ai,char *aj)
   }
 }
 
-void convert_harmonics(int nrmols,t_molinfo mols[],t_atomtype *atype)
+void convert_harmonics(int nrmols,t_molinfo mols[],t_atomtype atype)
 {
   int      n2m;
   t_2morse *t2m;
@@ -206,9 +208,10 @@ void convert_harmonics(int nrmols,t_molinfo mols[],t_atomtype *atype)
        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,
-                              *atype->atomname[mols[i].atoms.atom[ni].type],
-                              *atype->atomname[mols[i].atoms.atom[nj].type]);
+         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];
index 1da900b643d9e92fa7e099464138a3d7d2f61abd..6741ba46d12af9845e9a3288f0d599b7f4c2ce1c 100644 (file)
@@ -65,6 +65,7 @@
 #include "topio.h"
 #include "topshake.h"
 #include "gmxcpp.h"
+#include "gpp_bond_atomtype.h"
 
 #define CPPMARK        '#'     /* mark from cpp                        */
 #define OPENDIR        '['     /* starting sign for directive          */
@@ -279,7 +280,7 @@ static char **cpp_opts(char *define,char *include,char *infile)
 static char **read_topol(char *infile,char *outfile,
                         char *define,char *include,
                         t_symtab    *symtab,
-                        t_atomtype  *atype,
+                        t_atomtype  atype,
                         int         *nrmols,
                         t_molinfo   **molinfo,
                         t_params    plist[],
@@ -311,7 +312,7 @@ static char **read_topol(char *infile,char *outfile,
   real       fudgeLJ=-1;    /* Multiplication factor to generate 1-4 from LJ */
   bool       bReadDefaults,bReadMolType,bGenPairs,bWarn_copy_A_B;
   double     qt=0,qBt=0; /* total charge */
-  t_bond_atomtype *batype;
+  t_bond_atomtype batype;
   int        lastcg=-1;
   /* File handling variables */
   int        status,done;
@@ -339,8 +340,7 @@ static char **read_topol(char *infile,char *outfile,
   
   bWarn_copy_A_B = bFEP;
 
-  snew(batype,1);
-  init_bond_atomtype(batype);
+  batype = init_bond_atomtype();
   /* parse the actual file */
   bReadDefaults = FALSE;
   bGenPairs     = FALSE;
@@ -448,27 +448,26 @@ static char **read_topol(char *infile,char *outfile,
                    &nbparam,bGenPairs ? &pair : NULL);
            break;
            
-#define PUSHBT(nral) push_bt(d,plist,nral,batype->atomname,batype->nr,pline)
          case d_bondtypes:
-           PUSHBT(2);
+           push_bt(d,plist,2,NULL,batype,pline);
            break;
          case d_constrainttypes:
-           PUSHBT(2);
+           push_bt(d,plist,2,NULL,batype,pline);
            break;
          case d_pairtypes:
            if (bGenPairs)
              push_nbt(d,pair,atype,pline,F_LJ14);
            else
-             push_bt(d,plist,2,atype->atomname,atype->nr,pline);
+             push_bt(d,plist,2,atype,NULL,pline);
              break;
          case d_angletypes:
-           PUSHBT(3);
+           push_bt(d,plist,3,NULL,batype,pline);
            break;
          case d_dihedraltypes:
            /* Special routine that can read both 2 and 4 atom dihedral definitions. */
-           push_dihedraltype(d,plist,batype->atomname,batype->nr,pline);
+           push_dihedraltype(d,plist,batype,pline);
            break;
-#undef PUSHBT
+
          case d_nonbond_params:
            push_nbt(d,nbparam,atype,pline,nb_funct);
            break;
@@ -486,18 +485,19 @@ static char **read_topol(char *infile,char *outfile,
            */
          case d_moleculetype: {
            if (!bReadMolType) {
-             ncombs = atype->nr*(atype->nr+1)/2;
+             int ntype = get_atomtype_ntypes(atype);
+             ncombs = (ntype*(ntype+1))/2;
              generate_nbparams(comb,nb_funct,&(plist[nb_funct]),atype);
              ncopy = copy_nbparams(nbparam,nb_funct,&(plist[nb_funct]),
-                                   atype->nr);
+                                   ntype);
              fprintf(stderr,"Generated %d of the %d non-bonded parameter combinations\n",ncombs-ncopy,ncombs);
-             free_nbparam(nbparam,atype->nr);
+             free_nbparam(nbparam,ntype);
              if (bGenPairs) {
                gen_pairs(&(plist[nb_funct]),&(plist[F_LJ14]),fudgeLJ,comb,bVerbose);
                ncopy = copy_nbparams(pair,nb_funct,&(plist[F_LJ14]),
-                                     atype->nr);
+                                     ntype);
                fprintf(stderr,"Generated %d of the %d 1-4 parameter combinations\n",ncombs-ncopy,ncombs);
-               free_nbparam(pair,atype->nr);
+               free_nbparam(pair,ntype);
              }
              /* Copy GBSA parameters to atomtype array */
              
@@ -605,6 +605,9 @@ static char **read_topol(char *infile,char *outfile,
   for(i=0; i<nmol; i++)
     done_block2(&(block2[i]));
   free(block2);
+  
+  done_bond_atomtype(&batype);
+  
   *nrmols=nmol;
   
   *nsim=Nsim;
@@ -622,7 +625,7 @@ char **do_top(bool         bVerbose,
              t_params     plist[],
              int          *combination_rule,
              real         *repulsion_power,
-             t_atomtype   *atype,
+             t_atomtype   atype,
              int          *nrmols,
              t_molinfo    **molinfo,
              t_inputrec   *ir,
@@ -633,8 +636,6 @@ char **do_top(bool         bVerbose,
   char *tmpfile;
   char **title;
   
-  init_atomtype(atype);
-
   if (topppfile)
     tmpfile = topppfile;
   else 
index 7f04ff40668ef963c3630fc8886e27c658cc78a3..925320886be05be502576f602b978627dfbbeaba 100644 (file)
@@ -40,6 +40,7 @@
 #include "typedefs.h"
 #include "readir.h"
 #include "grompp.h"
+#include "gpp_atomtype.h"
 
 typedef struct {
   int whichmol;
@@ -58,7 +59,7 @@ extern char **do_top(bool         bVerbose,
                     t_params     plist[],
                     int          *combination_rule,
                     real         *repulsion_power,
-                    t_atomtype   *atype,
+                    t_atomtype   atype,
                     int          *nrmols,
                     t_molinfo    **molinfo,
                     t_inputrec   *ir,
index f4cd2933a6df135d50c1e2629fa3d644bdb41c37..4cd1bd0c091673a0041b21029294612c99ed456c 100644 (file)
 #include "topdirs.h"
 #include "symtab.h"
 #include "gmx_fatal.h"
+#include "gpp_atomtype.h"
+#include "gpp_bond_atomtype.h"
 
-
-void generate_nbparams(int comb,int ftype,t_params *plist,t_atomtype *atype)
+void generate_nbparams(int comb,int ftype,t_params *plist,t_atomtype atype)
 {
   int   i,j,k=-1,nf;
   int   nr,nrfp;
-  real  c,bi,bj;
+  real  c,bi,bj,ci,cj,ci0,ci1,ci2,cj0,cj1,cj2;
   char  errbuf[256];
 
   /* Lean mean shortcuts */
-  nr   = atype->nr;
+  nr   = get_atomtype_ntypes(atype);
   nrfp = NRFP(ftype);
   snew(plist->param,nr*nr);
   plist->nr=nr*nr;
@@ -71,20 +72,28 @@ void generate_nbparams(int comb,int ftype,t_params *plist,t_atomtype *atype)
     switch (comb) {
     case eCOMB_GEOMETRIC:
       /* Gromos rules */
-      for(i=k=0; (i<nr); i++)
-       for(j=0; (j<nr); j++,k++)
+      for(i=k=0; (i<nr); i++) {
+       for(j=0; (j<nr); j++,k++) {
          for(nf=0; (nf<nrfp); nf++) {
-           c = sqrt(atype->nb[i].c[nf] * atype->nb[j].c[nf]);
+           ci = get_atomtype_nbparam(i,nf,atype);
+           cj = get_atomtype_nbparam(j,nf,atype);
+           c = sqrt(ci * cj);
            plist->param[k].c[nf]      = c;
          }
+       }
+      }
       break;
     
     case eCOMB_ARITHMETIC:
       /* c0 and c1 are epsilon and sigma */
       for (i=k=0; (i < nr); i++)
        for (j=0; (j < nr); j++,k++) {
-         plist->param[k].c[0] = (atype->nb[i].C0+atype->nb[j].C0)*0.5;
-         plist->param[k].c[1] = sqrt(atype->nb[i].C1*atype->nb[j].C1);
+         ci0 = get_atomtype_nbparam(i,0,atype);
+         cj0 = get_atomtype_nbparam(j,0,atype);
+         ci1 = get_atomtype_nbparam(i,1,atype);
+         cj1 = get_atomtype_nbparam(j,1,atype);
+         plist->param[k].c[0] = (ci0+cj0)*0.5;
+         plist->param[k].c[1] = sqrt(ci1*cj1);
        }
       
       break;
@@ -92,8 +101,12 @@ void generate_nbparams(int comb,int ftype,t_params *plist,t_atomtype *atype)
       /* c0 and c1 are epsilon and sigma */
       for (i=k=0; (i < nr); i++)
        for (j=0; (j < nr); j++,k++) {
-         plist->param[k].c[0] = sqrt(atype->nb[i].C0*atype->nb[j].C0);
-         plist->param[k].c[1] = sqrt(atype->nb[i].C1*atype->nb[j].C1);
+         ci0 = get_atomtype_nbparam(i,0,atype);
+         cj0 = get_atomtype_nbparam(j,0,atype);
+         ci1 = get_atomtype_nbparam(i,1,atype);
+         cj1 = get_atomtype_nbparam(j,1,atype);
+         plist->param[k].c[0] = sqrt(ci0*cj0);
+         plist->param[k].c[1] = sqrt(ci1*ci1);
        }
       
       break;
@@ -108,14 +121,18 @@ void generate_nbparams(int comb,int ftype,t_params *plist,t_atomtype *atype)
     /* Buckingham rules */
     for(i=k=0; (i<nr); i++)
       for(j=0; (j<nr); j++,k++) {
-       plist->param[k].c[0] = sqrt(atype->nb[i].c[0] * atype->nb[j].c[0]);
-       bi = atype->nb[i].c[1];
-       bj = atype->nb[j].c[1];
+       ci0 = get_atomtype_nbparam(i,0,atype);
+       cj0 = get_atomtype_nbparam(j,0,atype);
+       ci2 = get_atomtype_nbparam(i,2,atype);
+       cj2 = get_atomtype_nbparam(j,2,atype);
+       bi = get_atomtype_nbparam(i,1,atype);
+       bj = get_atomtype_nbparam(j,1,atype);
+       plist->param[k].c[0] = sqrt(ci0 * cj0);
        if ((bi == 0) || (bj == 0))
          plist->param[k].c[1] = 0;
        else
          plist->param[k].c[1] = 2.0/(1/bi+1/bj);
-       plist->param[k].c[2] = sqrt(atype->nb[i].c[2] * atype->nb[j].c[2]);
+       plist->param[k].c[2] = sqrt(ci2 * cj2);
       }
     
     break;
@@ -126,7 +143,7 @@ void generate_nbparams(int comb,int ftype,t_params *plist,t_atomtype *atype)
   }
 }
 
-void push_at (t_symtab *symtab, t_atomtype *at, t_bond_atomtype *bat,
+void push_at (t_symtab *symtab, t_atomtype at, t_bond_atomtype bat,
              char *line,int nb_funct,
              t_nbparam ***nbparam,t_nbparam ***pair)
 {
@@ -150,10 +167,15 @@ void push_at (t_symtab *symtab, t_atomtype *at, t_bond_atomtype *bat,
   double radius,vol,surftens;
   char   tmpfield[12][100]; /* Max 12 fields of width 100 */
   char   errbuf[256];
+  t_atom  *atom;
+  t_param *param;
   int    atomnr;
   bool   have_atomic_number;
   bool   have_bonded_type;
   
+  snew(atom,1);
+  snew(param,1);
+  
   /* First assign input line to temporary array */
   nfields=sscanf(line,"%s%s%s%s%s%s%s%s%s%s%s%s",
                 tmpfield[0],tmpfield[1],tmpfield[2],tmpfield[3],tmpfield[4],tmpfield[5],
@@ -382,62 +404,40 @@ void push_at (t_symtab *symtab, t_atomtype *at, t_bond_atomtype *bat,
   pt=xl[j].ptype;
   if (debug)
     fprintf(debug,"ptype: %s\n",ptype_str[pt]);
-  
-  nr = bat->nr;
-  /* First test if we have a new bond_atomtype */
-  for (i=0; ((i<nr) && (strcasecmp(*(bat->atomname[i]),btype) != 0)); i++)
-    ;
-  if ((i==nr) || (nr==0)) {
-    /* New bond_atomtype */
-    srenew(bat->atomname,nr+1);
-    bat->nr++; 
-    bat->atomname[nr] = put_symtab(symtab,btype);
-  } 
-  batype_nr=i;
 
-  nr = at->nr;
-  /* Test if this atomtype overwrites another */
-  for (i=0; ((i<nr) && (strcasecmp(*(at->atomname[i]),type) != 0)); i++)
-    ;
-
-  if ((i==nr) || (nr==0)) {
-    /* New atomtype, get new space for arrays */
-    srenew(at->atom,nr+1);
-    srenew(at->atomname,nr+1);
-    srenew(at->bondatomtype,nr+1);
-    srenew(at->nb,nr+1);
-    srenew(at->radius,nr+1);
-    srenew(at->vol,nr+1);
-    srenew(at->surftens,nr+1);
-    srenew(at->atomnumber,nr+1);
-    at->nr++;
+  atom->q = q;
+  atom->m = m;
+  atom->ptype = pt;
+  for (i=0; (i<MAXFORCEPARAM); i++)
+    param->c[i] = c[i];
+  
+  if ((batype_nr = get_bond_atomtype_type(btype,bat)) == NOTSET)
+    add_bond_atomtype(bat,symtab,btype);
+  batype_nr = get_bond_atomtype_type(btype,bat);
+  
+  if ((nr = get_atomtype_type(type,at)) != NOTSET) {
+    sprintf(errbuf,"Overriding atomtype %s",type);
+    warning(errbuf);
+    if ((nr = set_atomtype(nr,at,symtab,atom,type,param,batype_nr,
+                          radius,vol,surftens,atomnr)) == NOTSET)
+      gmx_fatal(FARGS,"Replacing atomtype %s failed",type);
+  }
+  else if ((nr = add_atomtype(at,symtab,atom,type,param,
+                             batype_nr,radius,vol,
+                             surftens,atomnr)) == NOTSET)
+    gmx_fatal(FARGS,"Adding atomtype %s failed",type);
+  else {  
     /* Add space in the non-bonded parameters matrix */
-    srenew(*nbparam,at->nr);
-    snew((*nbparam)[at->nr-1],at->nr);
+    int atnr = get_atomtype_ntypes(at);
+    srenew(*nbparam,atnr);
+    snew((*nbparam)[atnr-1],atnr);
     if (pair) {
-      srenew(*pair,at->nr);
-      snew((*pair)[at->nr-1],at->nr);
+      srenew(*pair,atnr);
+      snew((*pair)[atnr-1],atnr);
     }
   }
-  else {
-    sprintf(errbuf,"Overriding atomtype %s",type);
-    warning(errbuf);
-    nr = i;
-  } 
-
-  /* fill the arrays */
-  at->atomname[nr] = put_symtab(symtab,type);
-  at->bondatomtype[nr] = batype_nr;
-  at->atom[nr].ptype = pt;
-  at->atom[nr].m = m;
-  at->atom[nr].q = q;
-  at->radius[nr] = radius;
-  at->vol[nr] = vol;
-  at->surftens[nr] = surftens;
-  at->atomnumber[nr] = atomnr;
-
-  for (i=0; (i<MAXFORCEPARAM); i++)
-    at->nb[nr].c[i] = c[i];
+  sfree(atom);
+  sfree(param);
 }
 
 static void push_bondtype(t_params *bt,t_param *b,int nral,int ftype,
@@ -498,7 +498,9 @@ static void push_bondtype(t_params *bt,t_param *b,int nral,int ftype,
   }
 }
 
-void push_bt(directive d,t_params bt[],int nral,char ***typenames, int ntypes,char *line)
+void push_bt(directive d,t_params bt[],int nral,
+            t_atomtype at,
+            t_bond_atomtype bat,char *line)
 {
   const char *formal[MAXATOMLIST+1] = {
     "%s",
@@ -525,6 +527,9 @@ void push_bt(directive d,t_params bt[],int nral,char ***typenames, int ntypes,ch
   t_param  p;
   char  errbuf[256];
 
+  if ((bat && at) || (!bat && !at)) 
+    gmx_incons("You should pass either bat or at to push_bt");
+  
   /* Make format string (nral ints+functype) */
   if ((nn=sscanf(line,formal[nral],
                 alc[0],alc[1],alc[2],alc[3],alc[4],alc[5])) != nral+1) {
@@ -558,15 +563,20 @@ void push_bt(directive d,t_params bt[],int nral,char ***typenames, int ntypes,ch
        c[i] = 0.0;
     }
   }
-  for(i=0; (i<nral); i++)
-    p.a[i]=name2index(alc[i],typenames,ntypes); 
+  for(i=0; (i<nral); i++) {
+    if (at && ((p.a[i]=get_atomtype_type(alc[i],at)) == NOTSET))
+      gmx_fatal(FARGS,"Unknown atomtype %s\n",alc[i]);
+    else if (bat && ((p.a[i]=get_bond_atomtype_type(alc[i],bat)) == NOTSET))
+      gmx_fatal(FARGS,"Unknown bond_atomtype %s\n",alc[i]);
+  }
   for(i=0; (i<nrfp); i++)
     p.c[i]=c[i];
   push_bondtype (&(bt[ftype]),&p,nral,ftype,line);
 }
 
 
-void push_dihedraltype(directive d,t_params bt[],char ***typenames,int ntypes,char *line)
+void push_dihedraltype(directive d,t_params bt[],
+                      t_bond_atomtype bat,char *line)
 {
   const char *formal[MAXATOMLIST+1] = {
     "%s",
@@ -672,8 +682,10 @@ void push_dihedraltype(directive d,t_params bt[],char ***typenames,int ntypes,ch
   for(i=0; (i<4); i++) {
     if(!strcmp(alc[i],"X"))
       p.a[i]=-1;
-    else
-    p.a[i]=name2index(alc[i],typenames,ntypes); 
+    else {
+      if ((p.a[i]=get_bond_atomtype_type(alc[i],bat)) == NOTSET)
+       gmx_fatal(FARGS,"Unknown bond_atomtype %s",alc[i]);
+    }
   }
   for(i=0; (i<nrfp); i++)
     p.c[i]=c[i];
@@ -684,7 +696,7 @@ void push_dihedraltype(directive d,t_params bt[],char ***typenames,int ntypes,ch
 }
 
 
-void push_nbt(directive d,t_nbparam **nbt,t_atomtype *atype,
+void push_nbt(directive d,t_nbparam **nbt,t_atomtype atype,
              char *pline,int nb_funct)
 {
   /* swap the atoms */
@@ -749,8 +761,10 @@ void push_nbt(directive d,t_nbparam **nbt,t_atomtype *atype,
     cr[i] = c[i];
 
   /* Put the parameters in the matrix */
-  ai = at2type (a0,atype);
-  aj = at2type (a1,atype);
+  if ((ai = get_atomtype_type (a0,atype)) == NOTSET)
+    gmx_fatal(FARGS,"Atomtype %s not found",a0);
+  if ((aj = get_atomtype_type (a1,atype)) == NOTSET)
+    gmx_fatal(FARGS,"Atomtype %s not found",a1);
   nbp = &(nbt[max(ai,aj)][min(ai,aj)]);
   
   if (nbp->bSet) {
@@ -834,7 +848,7 @@ void push_cg(t_block *block, int *lastindex, int index, int a)
 }
 
 void push_atom(t_symtab *symtab,t_block *cgs,
-              t_atoms *at,t_atomtype *atype,char *line,int *lastcg)
+              t_atoms *at,t_atomtype atype,char *line,int *lastcg)
 {
   int          nr,ptype;
   int          resnumber,cgnumber,atomnr,type,typeB,nscan;
@@ -853,19 +867,20 @@ void push_atom(t_symtab *symtab,t_block *cgs,
     return;
   }
   sscanf(id,"%d",&atomnr);
-  type  = at2type(ctype,atype);
-  ptype = atype->atom[type].ptype;
+  if ((type  = get_atomtype_type(ctype,atype)) == NOTSET)
+    gmx_fatal(FARGS,"Atomtype %s not found",ctype);
+  ptype = get_atomtype_ptype(type,atype);
 
   /* Set default from type */  
-  q0    = atype->atom[type].q;
-  m0    = atype->atom[type].m;
+  q0    = get_atomtype_qA(type,atype);
+  m0    = get_atomtype_massA(type,atype);
   typeB = type;
   qB    = q0;
   mB    = m0;
   
   /* Optional parameters */
-  nscan=sscanf(line,"%*s%*s%*s%*s%*s%*s%lf%lf%s%lf%lf%s",
-              &q,&m,ctypeB,&qb,&mb,check);
+  nscan = sscanf(line,"%*s%*s%*s%*s%*s%*s%lf%lf%s%lf%lf%s",
+                &q,&m,ctypeB,&qb,&mb,check);
   
   /* Nasty switch that falls thru all the way down! */
   if (nscan > 0) {
@@ -873,9 +888,9 @@ void push_atom(t_symtab *symtab,t_block *cgs,
     if (nscan > 1) {
       m0 = mB = m;
       if (nscan > 2) {
-       typeB=at2type(ctypeB,atype);
-       qB = atype->atom[typeB].q;
-       mB = atype->atom[typeB].m;
+       typeB=get_atomtype_type(ctypeB,atype);
+       qB = get_atomtype_qA(typeB,atype);
+       mB = get_atomtype_massA(typeB,atype);
        if (nscan > 3) {
          qB = qb;
          if (nscan > 4) {
@@ -992,7 +1007,7 @@ static bool default_nb_params(int ftype,t_params bt[],t_atoms *at,
 
 
 static bool default_params(int ftype,t_params bt[],
-                          t_atoms *at,t_atomtype *atype,
+                          t_atoms *at,t_atomtype atype,
                           t_param *p,bool bB,
                           t_param **param_def)
 {
@@ -1003,7 +1018,6 @@ static bool default_params(int ftype,t_params bt[],
   int      nral = NRAL(ftype);
   int      nrfpA= interaction_function[ftype].nrfpA;
   int      nrfpB= interaction_function[ftype].nrfpB;
-  int     *batype=atype->bondatomtype;
 
   if ((!bB && nrfpA == 0) || (bB && nrfpB == 0))
     return TRUE;
@@ -1021,18 +1035,30 @@ static bool default_params(int ftype,t_params bt[],
     if (bB) {
       for (i=0; ((i < nr) && !bFound); i++) {
        pi=&(bt[ftype].param[i]);
-       bFound=( ((pi->AI==-1) || (batype[at->atom[p->AI].typeB]==pi->AI)) &&
-                ((pi->AJ==-1) || (batype[at->atom[p->AJ].typeB]==pi->AJ)) &&
-                ((pi->AK==-1) || (batype[at->atom[p->AK].typeB]==pi->AK)) &&
-                ((pi->AL==-1) || (batype[at->atom[p->AL].typeB]==pi->AL)) );
+       bFound=
+         (((pi->AI==-1) || 
+           (get_atomtype_batype(at->atom[p->AI].typeB,atype)==pi->AI)) &&
+          ((pi->AJ==-1) || 
+           (get_atomtype_batype(at->atom[p->AJ].typeB,atype)==pi->AJ)) &&
+          ((pi->AK==-1) || 
+           (get_atomtype_batype(at->atom[p->AK].typeB,atype)==pi->AK)) &&
+          ((pi->AL==-1) || 
+           (get_atomtype_batype(at->atom[p->AL].typeB,atype)==pi->AL))
+          );
       }
     } else {
       for (i=0; ((i < nr) && !bFound); i++) {
        pi=&(bt[ftype].param[i]);
-       bFound=( ((pi->AI==-1) || (batype[at->atom[p->AI].type]==pi->AI)) &&
-                ((pi->AJ==-1) || (batype[at->atom[p->AJ].type]==pi->AJ)) &&
-                ((pi->AK==-1) || (batype[at->atom[p->AK].type]==pi->AK)) &&
-                ((pi->AL==-1) || (batype[at->atom[p->AL].type]==pi->AL)) );
+       bFound=
+         (((pi->AI==-1) || 
+           (get_atomtype_batype(at->atom[p->AI].typeB,atype)==pi->AI)) &&        
+          ((pi->AJ==-1) || 
+           (get_atomtype_batype(at->atom[p->AJ].typeB,atype)==pi->AJ)) &&
+          ((pi->AK==-1) || 
+           (get_atomtype_batype(at->atom[p->AK].typeB,atype)==pi->AK)) &&
+          ((pi->AL==-1) || 
+           (get_atomtype_batype(at->atom[p->AL].typeB,atype)==pi->AL))
+          );
       }
     }
   } else { /* Not a dihedral */
@@ -1040,10 +1066,12 @@ static bool default_params(int ftype,t_params bt[],
       pi=&(bt[ftype].param[i]);
       if (bB)
        for (j=0; ((j < nral) && 
-                  (atype->bondatomtype[at->atom[p->a[j]].typeB] == pi->a[j])); j++);
+                  (get_atomtype_batype(at->atom[p->a[j]].typeB,atype)==pi->a[j])); j++)
+         ;
       else
        for (j=0; ((j < nral) && 
-                  (atype->bondatomtype[at->atom[p->a[j]].type] == pi->a[j])); j++);
+                  (get_atomtype_batype(at->atom[p->a[j]].type,atype)==pi->a[j])); j++)
+         ;
       bFound=(j==nral);
     }
   }
@@ -1076,7 +1104,7 @@ void push_bondnow(t_params *bond, t_param *b)
 }
 
 void push_bond(directive d,t_params bondtype[],t_params bond[],
-              t_atoms *at,t_atomtype *atype,char *line,
+              t_atoms *at,t_atomtype atype,char *line,
               bool bBonded,bool bGenPairs,bool bZero,bool *bWarn_copy_A_B)
 {
   const char *aaformat[MAXATOMLIST]= {
@@ -1326,7 +1354,7 @@ void push_bond(directive d,t_params bondtype[],t_params bond[],
 }
 
 void push_vsitesn(directive d,t_params bondtype[],t_params bond[],
-                 t_atoms *at,t_atomtype *atype,char *line)
+                 t_atoms *at,t_atomtype atype,char *line)
 {
   char *ptr;
   int  type,ftype,j,n,ret,nj,a;
index 31bce147362db2beb1d0fe42f95951fab1dea9ad..e9643a14be67ece05a7a705d763ce3473695f6cd 100644 (file)
@@ -39,6 +39,8 @@
 
 #include "typedefs.h"
 #include "toputil.h"
+#include "gpp_atomtype.h"
+#include "gpp_bond_atomtype.h"
 
 typedef struct {
   int     nr;  /* The number of entries in the list                    */
@@ -49,36 +51,37 @@ typedef struct {
 } t_block2;
 
 extern void generate_nbparams(int comb,int funct,t_params plist[],
-                             t_atomtype *atype);
+                             t_atomtype atype);
                              
-extern void push_at (t_symtab *symtab,t_atomtype *at,t_bond_atomtype *bat,char *line,int nb_funct,
+extern void push_at (t_symtab *symtab,t_atomtype at,
+                    t_bond_atomtype bat,char *line,int nb_funct,
                     t_nbparam ***nbparam,t_nbparam ***pair);
 
-extern void push_bt(directive d,t_params bt[], int nral, 
-                   char ***typenames, int ntypes, char *line);
+extern void push_bt(directive d,t_params bt[], int nral,
+                   t_atomtype at,t_bond_atomtype bat,char *line);
 
 extern void push_dihedraltype(directive d,t_params bt[],
-                             char ***typenames, int ntypes,char *line);
+                             t_bond_atomtype bat,char *line);
 
-extern void push_nbt(directive d,t_nbparam **nbt,t_atomtype *atype,
+extern void push_nbt(directive d,t_nbparam **nbt,t_atomtype atype,
                     char *plines,int nb_funct);
 
 extern void push_atom(t_symtab   *symtab, 
                      t_block    *cgs,
                      t_atoms    *at,
-                     t_atomtype *atype,
+                     t_atomtype atype,
                      char       *line,
                      int        *lastcg);
 
 extern void push_bondnow (t_params *bond, t_param *b);
 
 extern void push_bond(directive d,t_params bondtype[],t_params bond[],
-                     t_atoms *at,t_atomtype *atype,char *line,
+                     t_atoms *at,t_atomtype atype,char *line,
                      bool bBonded,bool bGenPairs,
                      bool bZero,bool *bWarn_copy_A_B);
 
 extern void push_vsitesn(directive d,t_params bondtype[],t_params bond[],
-                        t_atoms *at,t_atomtype *atype,char *line);
+                        t_atoms *at,t_atomtype atype,char *line);
 
 extern void push_mol(int nrmols,t_molinfo mols[],char *pline,
                     int *whichmol,int *nrcopies);
index 34257b5c3926a01b1fedaca8416f37a16e72e378..d9d7e1a6445e1e0e7f83ed54048ef9b2f7ff5b43 100644 (file)
@@ -76,7 +76,7 @@ static int count_hydrogens (char ***atomname, int nra, atom_id a[])
   return nh;
 }
 
-void make_shake (t_params plist[],t_atoms *atoms,t_atomtype *at,int nshake)
+void make_shake (t_params plist[],t_atoms *atoms,t_atomtype at,int nshake)
 {
   char         ***info=atoms->atomname;
   t_params     *pr;
index 590e6a4c4d6128378d4c176801505104e9f15b54..986bcacdbc30843bcd2b826aa6a68244a16968d2 100644 (file)
@@ -39,6 +39,6 @@
 
 #include "topio.h"
 
-void make_shake (t_params plist[],t_atoms *atoms,t_atomtype *at,int nshake);
+void make_shake (t_params plist[],t_atoms *atoms,t_atomtype at,int nshake);
 
 #endif /* _topshake_h */
index 0183894842e9ca54ce3412683d89d5f0c54b89f8..7d302f3e1e2ee7311ec6d4f17abb982010e01968 100644 (file)
@@ -37,6 +37,7 @@
 #include <config.h>
 #endif
 
+#include <math.h>
 #include "smalloc.h"
 #include "sysstuff.h"
 #include "macros.h"
 #include "toputil.h"
 #include "symtab.h"
 #include "gmx_fatal.h"
-#include <math.h>
+#include "gpp_atomtype.h"
 
 /* UTILITIES */
 
-int at2type(char *str,t_atomtype *at)
-{
-  int i;
-
-  for (i=0; (i<at->nr) && strcasecmp(str,*(at->atomname[i])); i++)
-    ;
-  if (i == at->nr) 
-    gmx_fatal(FARGS,"Atomtype '%s' not found!",str);
-  
-  return i;
-}
-
-
-int name2index(char *str, char ***typenames, int ntypes)
-{
-  int i;
-
-  for (i=0; (i<ntypes) && strcasecmp(str,*(typenames[i])); i++)
-    ;
-  if (i == ntypes) 
-    gmx_fatal(FARGS,"Bonded/nonbonded atom type '%s' not found!",str);
-  
-  return i;
-}
-
-
-char *type2nm(int nt, t_atomtype *at)
-{
-  if ((nt < 0) || (nt >= at->nr))
-    gmx_fatal(FARGS,"nt out of range: %d",nt);
-  
-  return *(at->atomname[nt]);
-}
-
 void set_p_string(t_param *p,char *s)
 {
   if (s) {
@@ -123,28 +90,6 @@ void pr_alloc (int extra, t_params *pr)
   }
 }
 
-/* INIT STRUCTURES */
-
-void init_atomtype (t_atomtype *at)
-{
-  at->nr           = 0;
-  at->atom         = NULL;
-  at->atomname     = NULL;
-  at->nb           = NULL;
-  at->bondatomtype = NULL;
-  at->radius       = NULL;
-  at->vol          = NULL;
-  at->surftens     = NULL;
-  at->atomnumber   = NULL;
-}
-
-void init_bond_atomtype (t_bond_atomtype *bat)
-{
-  bat->nr   = 0;
-  bat->atomname = NULL;
-}
-
-
 void init_plist(t_params plist[])
 {
   int i;
@@ -187,27 +132,10 @@ void done_mi(t_molinfo *mi)
 
 /* PRINTING STRUCTURES */
 
-void print_at (FILE * out, t_atomtype *at)
-{
-  int i;
-  t_atom     *atom = at->atom;
-  t_param    *nb   = at->nb;
-  
-  fprintf (out,"[ %s ]\n",dir2str(d_atomtypes));
-  fprintf (out,"; %6s  %8s  %8s  %8s  %12s  %12s\n",
-          "type","mass","charge","particle","c6","c12");
-  for (i=0; (i<at->nr); i++) 
-    fprintf(out,"%8s  %8.3f  %8.3f  %8s  %12e  %12e\n",
-           *(at->atomname[i]),atom[i].m,atom[i].q,"A",
-           nb[i].C0,nb[i].C1);
-  
-  fprintf (out,"\n");
-}
-
-static void print_nbt (FILE *out,char *title,t_atomtype *at,
+static void print_nbt (FILE *out,char *title,t_atomtype at,
                       int ftype,t_params *nbt)
 {
-  int f,i,j,k,l,nrfp;
+  int f,i,j,k,l,nrfp,ntype;
   
   if (ftype == F_LJ)
     f=1;
@@ -226,10 +154,11 @@ static void print_nbt (FILE *out,char *title,t_atomtype *at,
     fprintf (out,"\n");
     
     /* print non-bondtypes */
-    for (i=k=0; (i<at->nr); i++)
-      for(j=0; (j<at->nr); j++,k++) {
+    ntype = get_atomtype_ntypes(at);
+    for (i=k=0; (i<ntype); i++)
+      for(j=0; (j<ntype); j++,k++) {
        fprintf (out,"%8s  %8s  %8d",
-                *(at->atomname[i]),*(at->atomname[j]),f);
+                get_atomtype_name(i,at),get_atomtype_name(f,at),f);
        for(l=0; (l<nrfp); l++)
          fprintf (out,"  %12.5e",nbt->param[k].c[l]);
        fprintf (out,"\n");
@@ -238,7 +167,7 @@ static void print_nbt (FILE *out,char *title,t_atomtype *at,
   fprintf (out,"\n");
 }
 
-void print_bt(FILE *out, directive d, t_atomtype *at,
+void print_bt(FILE *out, directive d, t_atomtype at,
              int ftype,int fsubtype,t_params plist[],
              bool bFullDih)
 {
@@ -341,10 +270,10 @@ void print_bt(FILE *out, directive d, t_atomtype *at,
     bSwapParity = (bt->param[i].C0==NOTSET) && (bt->param[i].C1==-1);
     if (!bDih)
       for (j=0; (j<nral); j++)
-       fprintf (out,"%5s ",*(at->atomname[bt->param[i].a[j]]));
+       fprintf (out,"%5s ",get_atomtype_name(bt->param[i].a[j],at));
     else 
       for(j=0; (j<2); j++)
-       fprintf (out,"%5s ",*(at->atomname[bt->param[i].a[dihp[f][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])
@@ -403,11 +332,11 @@ void print_excl(FILE *out, int natoms, t_excls excls[])
   }
 }
 
-void print_atoms(FILE *out,t_atomtype *atype,t_atoms *at,int *cgnr)
+void print_atoms(FILE *out,t_atomtype atype,t_atoms *at,int *cgnr)
 {
   int  i;
-  int  itype;
-  char *as;
+  int  tpA,tpB;
+  char *as,*tpnmA,*tpnmB;
   double qtot;
   
   as=dir2str(d_atoms);
@@ -424,20 +353,21 @@ void print_atoms(FILE *out,t_atomtype *atype,t_atoms *at,int *cgnr)
   if (at->nres) {
     /* if the information is present... */
     for (i=0; (i < at->nr); i++) {
-      itype=at->atom[i].type;
-      if ((itype < 0) || (itype > atype->nr))
-       gmx_fatal(FARGS,"itype = %d, i= %d in print_atoms",itype,i);
-       
+      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 %6s %6s %6d %10g %10g",
-             i+1,*(atype->atomname[itype]),
-             at->atom[i].resnr+1,  
+             i+1,tpnmA,at->atom[i].resnr+1,  
              *(at->resname[at->atom[i].resnr]),
              *(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",
-               *(atype->atomname[at->atom[i].typeB]),
-               at->atom[i].qB,at->atom[i].mB);
+               tpnmB,at->atom[i].qB,at->atom[i].mB);
       }
       qtot += (double)at->atom[i].q;
       if ( fabs(qtot) < 4*GMX_REAL_EPS ) 
@@ -454,20 +384,24 @@ void print_bondeds(FILE *out,int natoms,directive d,
 {
   t_symtab   stab;
   t_atomtype atype;
+  t_param    *param;
+  t_atom     *a;
   int i;
     
-  snew(atype.atom,natoms);
-  snew(atype.atomname,natoms);
+  atype = init_atomtype();
+  snew(a,1);
+  snew(param,1);
   open_symtab(&stab);
   for (i=0; (i < natoms); i++) {
     char buf[12];
     sprintf(buf,"%4d",(i+1));
-    atype.atomname[i]=put_symtab(&stab,buf);
+    add_atomtype(atype,&stab,a,buf,param,0,0,0,0,0);
   }
-  print_bt(out,d,&atype,ftype,fsubtype,plist,TRUE);
+  print_bt(out,d,atype,ftype,fsubtype,plist,TRUE);
     
   done_symtab(&stab);
-  sfree(atype.atom);
-  sfree(atype.atomname);
+  sfree(a);
+  sfree(param);
+  done_atomtype(&atype);
 }
 
index 570f3f5a1e44b5b03104dc3640b9d77ebd08fec7..58b1195a7be60d839b190552d011babc309b0538 100644 (file)
 #define _toputil_h
 
 #include "grompp.h"
+#include "gpp_atomtype.h"
 
 /* UTILITIES */
 
-extern int at2type(char *str, t_atomtype *at);
-
 extern int name2index(char *str, char ***typenames, int ntypes);
 
-extern char *type2nm(int nt, t_atomtype *at);
-
 extern void pr_alloc (int extra, t_params *pr);
 
 extern void set_p_string(t_param *p,char *s);
@@ -55,10 +52,6 @@ extern void set_p_string(t_param *p,char *s);
 
 extern void init_plist(t_params plist[]);
 
-extern void init_atomtype (t_atomtype *at);
-
-extern void init_bond_atomtype (t_bond_atomtype *bat);
-
 extern void init_molinfo(t_molinfo *mol);
 
 extern void init_top  (t_topology *top);
@@ -79,7 +72,7 @@ extern void done_mi(t_molinfo *mi);
 extern void print_blocka(FILE *out,char *szName,char *szIndex, 
                         char *szA,t_blocka *block);
 
-extern void print_atoms(FILE *out,t_atomtype *atype,t_atoms *at,int *cgnr);
+extern void print_atoms(FILE *out,t_atomtype atype,t_atoms *at,int *cgnr);
 
 extern void print_bondeds(FILE *out,int natoms,directive d,
                          int ftype,int fsubtype,t_params plist[]);
index c9e8df969904918c045d045aab82d769cae9ba7b..245e9427ca5f460c5b525414a45abc80b3fd6c94 100644 (file)
@@ -318,7 +318,7 @@ static real get_angle(int nrang, t_mybonded angles[],
   return angle;
 }
 
-static bool calc_vsite3_param(t_atomtype *atype,
+static bool calc_vsite3_param(t_atomtype atype,
                              t_param *param, t_atoms *at,
                              int nrbond, t_mybonded *bonds,
                              int nrang,  t_mybonded *angles )
@@ -336,14 +336,15 @@ static bool calc_vsite3_param(t_atomtype *atype,
     int i;
     for (i=0; i<4; i++)
       fprintf(debug,"atom %u type %s ",
-             param->a[i]+1,type2nm(at->atom[param->a[i]].type,atype));
+             param->a[i]+1,
+             get_atomtype_name(at->atom[param->a[i]].type,atype));
     fprintf(debug,"\n");
   }
   bXH3 = 
-    ( (strncasecmp(type2nm(at->atom[param->AK].type,atype),"MNH",3)==0) &&
-      (strncasecmp(type2nm(at->atom[param->AL].type,atype),"MNH",3)==0) ) ||
-    ( (strncasecmp(type2nm(at->atom[param->AK].type,atype),"MCH3",4)==0) &&
-      (strncasecmp(type2nm(at->atom[param->AL].type,atype),"MCH3",4)==0) );
+    ( (strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MNH",3)==0) &&
+      (strncasecmp(get_atomtype_name(at->atom[param->AL].type,atype),"MNH",3)==0) ) ||
+    ( (strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MCH3",4)==0) &&
+      (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);
@@ -464,7 +465,7 @@ static bool calc_vsite3fad_param(t_param *param,
   return bError;
 }
 
-static bool calc_vsite3out_param(t_atomtype *atype,
+static bool calc_vsite3out_param(t_atomtype atype,
                                 t_param *param, t_atoms *at,
                                 int nrbond, t_mybonded *bonds,
                                 int nrang,  t_mybonded *angles)
@@ -484,14 +485,14 @@ static bool calc_vsite3out_param(t_atomtype *atype,
     int i;
     for (i=0; i<4; i++)
       fprintf(debug,"atom %u type %s ",
-             param->a[i]+1,type2nm(at->atom[param->a[i]].type,atype));
+             param->a[i]+1,get_atomtype_name(at->atom[param->a[i]].type,atype));
     fprintf(debug,"\n");
   }
   bXH3 = 
-    ( (strncasecmp(type2nm(at->atom[param->AK].type,atype),"MNH",3)==0) &&
-      (strncasecmp(type2nm(at->atom[param->AL].type,atype),"MNH",3)==0) ) ||
-    ( (strncasecmp(type2nm(at->atom[param->AK].type,atype),"MCH3",4)==0) &&
-      (strncasecmp(type2nm(at->atom[param->AL].type,atype),"MCH3",4)==0) );
+    ( (strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MNH",3)==0) &&
+      (strncasecmp(get_atomtype_name(at->atom[param->AL].type,atype),"MNH",3)==0) ) ||
+    ( (strncasecmp(get_atomtype_name(at->atom[param->AK].type,atype),"MCH3",4)==0) &&
+      (strncasecmp(get_atomtype_name(at->atom[param->AL].type,atype),"MCH3",4)==0) );
   
   /* check if construction parity must be swapped */  
   bSwapParity = ( param->C1 == -1 );
@@ -682,7 +683,7 @@ calc_vsite4fdn_param(t_param *param,
 
 
 
-int set_vsites(bool bVerbose, t_atoms *atoms, t_atomtype *atype,
+int set_vsites(bool bVerbose, t_atoms *atoms, t_atomtype atype,
                t_params plist[])
 {
   int i,j,ftype;
index bb2eb594e60e8205026398189383d7ac0825bfa8..5034d051fb9053bba9dedfae6cfc755be3069f3e 100644 (file)
@@ -39,8 +39,9 @@
 
 #include "typedefs.h"
 #include "grompp.h"
+#include "gpp_atomtype.h"
 
-extern int set_vsites(bool bVerbose, t_atoms *atoms,  t_atomtype *atype,
+extern int set_vsites(bool bVerbose, t_atoms *atoms,  t_atomtype atype,
                      t_params plist[]);
 /* set parameters for vritual sites, return number of virtual sites */
 
index ecc5affc550ffd64962ab03b0ec7c45d39deb7da..0af7bb3bc60d67f76de825fd607fe07ea86b36d2 100644 (file)
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
   t_params   plist[F_NRE];
   t_excls    *excls;
   t_atoms    *atoms;       /* list with all atoms */
-  t_atomtype *atype;
+  t_atomtype atype;
   t_nextnb   nnb;
   x2top_nm2t nm2t;
   x2top_qat  qa;
@@ -146,7 +146,7 @@ int main(int argc, char *argv[])
   static char *molnm = "ICE";
   static char *ff = "select";
   static char *qgen[] = { NULL, "None", "Linear", "Yang", "Bultinck", 
-                         "SM1", "SM2", "SM3", "SM4", NULL };
+                         "SMp", "SMs", "SMps", "SMg", "SMgs", NULL };
   t_pargs pa[] = {
     { "-ff",     FALSE, etSTR, {&ff},
       "Select the force field for your simulation." },
@@ -256,13 +256,15 @@ int main(int argc, char *argv[])
   mk_bonds(nm2t,atoms,x,&(plist[F_BONDS]),nbonds,forcefield,
           bPBC,box,atomprop,btol);
 
+  /* Setting the atom types: this depends on the bonding */
   open_symtab(&symtab);
   atype = set_atom_type(&symtab,atoms,&(plist[F_BONDS]),nbonds,nm2t);
   
-  /* Read charges */
+  /* Read charges and polarizabilities, if provided */
   if (opt2bSet("-d",NFILE,fnm))
     qa = rd_q_alpha(opt2fn("-d",NFILE,fnm));
 
+  /* Check which algorithm to use for charge generation */
   alg = eqgNone;
   if (qgen[0]) {
     alg = name2eemtype(qgen[0]); 
@@ -285,9 +287,9 @@ int main(int argc, char *argv[])
                   maxiter,atomprop,qtotref);
 
   if (bPolarize)
-    add_shells(nm2t,atoms,atype,&(plist[F_BONDS]),&(plist[F_POLARIZATION]),
-              &x,&symtab);
-      
+    add_shells(nm2t,&atoms,atype,&(plist[F_BONDS]),
+              &(plist[F_POLARIZATION]),&x,&symtab);
+  
   /* Make Angles and Dihedrals */
   snew(excls,atoms->nr);
   printf("Generating angles and dihedrals from bonds...\n");
@@ -296,7 +298,7 @@ int main(int argc, char *argv[])
   print_nnb(&nnb,"NNB");
   gen_pad(&nnb,atoms,bH14,nexcl,plist,excls,NULL,
          bAllDih,bRemoveDih,TRUE);
-  delete_shell_interactions(plist,atoms,atype,&nnb,excls);
+  /*delete_shell_interactions(plist,atoms,atype,&nnb,excls);*/
   done_nnb(&nnb);
   mu = calc_dip(atoms,x);
   
index bbae92211a34b7ba7ca78417d0b7b01c8ab270f9..6b99ccb5ffc163bd4f889d3448f4eb5fffd577ad 100644 (file)
@@ -67,6 +67,7 @@
 #include "grompp.h"
 #include "add_par.h"
 #include "gmx_random.h"
+#include "gpp_atomtype.h"
 
 void mk_bonds(x2top_nm2t nmt,
              t_atoms *atoms,rvec x[],t_params *bond,int nbond[],char *ff,
@@ -135,13 +136,13 @@ int *set_cgnr(t_atoms *atoms,bool bUsePDBcharge,real *qtot,real *mtot)
   return cgnr;
 }
 
-t_atomtype *set_atom_type(t_symtab *tab,t_atoms *atoms,t_params *bonds,
-                         int *nbonds,x2top_nm2t nm2t)
+t_atomtype set_atom_type(t_symtab *tab,t_atoms *atoms,t_params *bonds,
+                        int *nbonds,x2top_nm2t nm2t)
 {
-  t_atomtype *atype;
+  t_atomtype atype;
   int nresolved;
   
-  snew(atype,1);
+  atype = init_atomtype();
   snew(atoms->atomtype,atoms->nr);
   nresolved = nm2type(nm2t,tab,atoms,atype,nbonds,bonds);
   if (nresolved != atoms->nr)
@@ -149,7 +150,7 @@ t_atomtype *set_atom_type(t_symtab *tab,t_atoms *atoms,t_params *bonds,
              nresolved,atoms->nr);
   
   fprintf(stderr,"There are %d different atom types in your sample\n",
-         atype->nr);
+         get_atomtype_ntypes(atype));
     
   return atype;
 }
@@ -382,7 +383,7 @@ static void clean_thole(t_params *ps)
 }
 
 void delete_shell_interactions(t_params plist[F_NRE],t_atoms *atoms,
-                              t_atomtype *atype,t_nextnb *nnb,
+                              t_atomtype atype,t_nextnb *nnb,
                               t_excls excls[])
 {
   int atp,jtp,jid,i,j,k,l,m,ftype,nb,nra,npol=0;
@@ -400,7 +401,7 @@ void delete_shell_interactions(t_params plist[F_NRE],t_atoms *atoms,
     for(j=0; (j<plist[ftype].nr); j++) {
       for(k=0; (k<nra); k++) {
        atp = atoms->atom[p[j].a[k]].type;
-       if (strcasecmp(*atype->atomname[atp],"SHELL") == 0) {
+       if (get_atomtype_ptype(atp,atype) == eptShell) {
          bRemove[j] = TRUE;
          if (ftype == F_BONDS) {
            memcpy(&plist[F_POLARIZATION].param[npol],
@@ -427,8 +428,7 @@ void delete_shell_interactions(t_params plist[F_NRE],t_atoms *atoms,
   /* now for all atoms */
   for (i=0; (i < atoms->nr); i++) {
     atp = atoms->atom[i].type;
-    if (strcasecmp(*atype->atomname[atp],"SHELL") == 0) {
-      
+    if (get_atomtype_ptype(atp,atype) == eptShell) {
       for(m=3; (m<=4); m++) {
        /* for all fifth bonded atoms of atom i */
        for (j=0; (j < nnb->nrexcl[i][m]); j++) {
@@ -436,7 +436,7 @@ void delete_shell_interactions(t_params plist[F_NRE],t_atoms *atoms,
          /* store the 1st neighbour in nb */
          nb = nnb->a[i][m][j];
          jtp = atoms->atom[nb].type;
-         if ((i != nb) && (strcasecmp(*atype->atomname[jtp],"SHELL") == 0)) {
+         if ((i != nb) && (strcasecmp(get_atomtype_name(jtp,atype),"SHELL") == 0)) {
            srenew(excls[i].e,excls[i].nr+1);
            excls[i].e[excls[i].nr++] = nb;
            fprintf(stderr,"Excluding %d from %d\n",nb+1,i+1);
@@ -456,7 +456,7 @@ void delete_shell_interactions(t_params plist[F_NRE],t_atoms *atoms,
       jid = nnb->a[i][1][j];
       atp = atoms->atom[jid].type;
     
-      if (strcasecmp(*atype->atomname[atp],"SHELL") == 0) {
+      if (get_atomtype_ptype(atp,atype) == eptShell) {
        bHaveShell[i] = TRUE;
        shell_index[i] = jid;
       }
@@ -529,62 +529,70 @@ void reset_q(t_atoms *atoms)
     atoms->atom[i].qB = atoms->atom[i].q;
 }
 
-void add_shells(x2top_nm2t nm2t,t_atoms *atoms,
-               t_atomtype *atype,
+void add_shells(x2top_nm2t nm2t,t_atoms **atoms,
+               t_atomtype atype,
                t_params *bonds,t_params *pols,
                rvec **x,t_symtab *symtab)
 {
   int  i,j,iat,shell,atp,ns=0;
   int  *renum;
-  char **ptr;
   char buf[32];
   t_param p;
+  t_atom  *shell_atom;
+  t_atoms *newa;
+  rvec    *newx;
   
+  snew(shell_atom,1);
   memset(&p,0,sizeof(p));
-  snew(renum,atoms->nr*2);
-  for(i=0; (i<atoms->nr); i++) {
-    atp = atoms->atom[i].type;
+  snew(renum,(*atoms)->nr*2);
+  for(i=0; (i<(*atoms)->nr); i++) {
+    atp = (*atoms)->atom[i].type;
     renum[i] = i+ns;
-    if (atype->atom[atp].qB != 0) {
+    if (get_atomtype_qB(atp,atype) != 0) {
       ns++;
       p.AI = renum[i];
       p.AJ = renum[i]+1;
-      p.C0 = atype->atom[atp].qB;
+      p.C0 = get_atomtype_qB(atp,atype);
       push_bondnow(pols,&p);
     }
   }
-  shell = atype->nr - 1;
+  shell_atom->ptype = eptShell;
+  shell = add_atomtype(atype,symtab,shell_atom,"SHELL",&p,
+                      0,0,0,0,0);
+  
   if (ns > 0) {
-    srenew(atoms->atom,atoms->nr+ns);
-    srenew(atoms->atomname,atoms->nr+ns);
-    srenew((*x),atoms->nr+ns);
-    for(i=atoms->nr; (i<atoms->nr+ns); i++) {
-      memset(&(atoms->atom[i]),0,sizeof(atoms->atom[i]));
-      atoms->atomname[i] = NULL;
-      clear_rvec((*x)[i]);
+    snew(newa,1);
+    init_t_atoms(newa,(*atoms)->nr+ns,TRUE);
+    newa->nres = (*atoms)->nres;
+    snew(newx,(*atoms)->nr+ns);
+
+    for(i=0; (i<(*atoms)->nr); i++) {
+      newa->atom[renum[i]]     = (*atoms)->atom[i];
+      newa->atomname[renum[i]] = put_symtab(symtab,*(*atoms)->atomname[i]);
+      copy_rvec(newx[renum[i]],(*x)[i]);
     }
-    for(i=atoms->nr-1; (i>=0); i--) {
-      atoms->atom[renum[i]]     = atoms->atom[i];
-      atoms->atomname[renum[i]] = atoms->atomname[i];
-      copy_rvec((*x)[renum[i]],(*x)[i]);
+    for(i=0; (i<(*atoms)->nres); i++) {
+      newa->resname[i] = put_symtab(symtab,*(*atoms)->resname[i]);
     }
-    for(i=0; (i<atoms->nr); i++) {
+    
+    for(i=0; (i<(*atoms)->nr); i++) {
       iat = renum[i];
       for(j=iat+1; (j<renum[i+1]); j++) {
-       atoms->atom[j]      = atoms->atom[iat];
-       atoms->atom[iat].q  = 0;
-       atoms->atom[iat].qB = 0;
-       atoms->atom[j].m    = 0;
-       atoms->atom[j].mB   = 0;
-       atoms->atom[j].type = shell;
-       sprintf(buf,"S%s",*(atoms->atomname[iat]));
-       snew(ptr,1);
-       *ptr = strdup(buf);
-       atoms->atomname = *ptr;/*put_symtab(symtab,ptr);*/
+       newa->atom[j]       = (*atoms)->atom[iat];
+       newa->atom[iat].q   = 0;
+       newa->atom[iat].qB  = 0;
+       newa->atom[j].m     = 0;
+       newa->atom[j].mB    = 0;
+       newa->atom[j].type  = shell;
+       newa->atom[j].resnr = (*atoms)->atom[i].resnr;
+       sprintf(buf,"S%s",*((*atoms)->atomname[i]));
+       newa->atomname[j] = put_symtab(symtab,buf);
        copy_rvec((*x)[j],(*x)[iat]);
       }
     }
+    *atoms = newa;
+    *x = newx;
   }
-  atoms->nr += ns;
   sfree(renum);
+  sfree(shell_atom);
 }
index db4f0406cad371a6ae07201b47b067f371b71275..0089b64e085e528ad1245f2e3d7f480fe1dda865 100644 (file)
@@ -52,7 +52,7 @@ extern int *set_cgnr(t_atoms *atoms,bool bUsePDBcharge,real *qtot,real *mtot);
 extern real calc_dip(t_atoms *atoms,rvec x[]);
 
 extern void delete_shell_interactions(t_params plist[F_NRE],t_atoms *atoms,
-                                     t_atomtype *atype,t_nextnb *nnb,
+                                     t_atomtype atype,t_nextnb *nnb,
                                      t_excls excls[]);
                                      
 extern void dump_hybridization(FILE *fp,t_atoms *atoms,int nbonds[]);
@@ -66,11 +66,11 @@ extern void mk_bonds(x2top_nm2t nmt,
                     t_atoms *atoms,rvec x[],t_params *bond,int nbond[],char *ff,
                     bool bPBC,matrix box,void *atomprop,real tol);
                     
-extern t_atomtype *set_atom_type(t_symtab *tab,t_atoms *atoms,t_params *bonds,
-                                int *nbonds,x2top_nm2t nm2t);
+extern t_atomtype set_atom_type(t_symtab *tab,t_atoms *atoms,t_params *bonds,
+                               int *nbonds,x2top_nm2t nm2t);
                     
-extern void add_shells(x2top_nm2t nm2t,t_atoms *atoms,
-                      t_atomtype *atype,
+extern void add_shells(x2top_nm2t nm2t,t_atoms **atoms,
+                      t_atomtype atype,
                       t_params *bonds,t_params *pols,
                       rvec **x,t_symtab *symtab);
 
index 6f33e5d1fd7b642cd977636ee61097135028cea4..590aa9730730e3ce50e43029124669aea85ed09d 100644 (file)
@@ -78,7 +78,7 @@ typedef struct {
 } t_eemrecord;
 
 static char *eemtype_name[eqgNR] = { 
-  "None", "Linear", "Yang", "Bultinck", "SM1", "SM2", "SM3", "SM4" 
+  "None", "Linear", "Yang", "Bultinck", "SMp", "SMs", "SMps", "SMg", "SMpg", 
 };
 
 int name2eemtype(char *name)
@@ -205,9 +205,10 @@ real lo_get_j00(void *eem,int index,real *wj,real q)
     else 
       *wj = (3/(4*er->eep[index].w));
   }
-  else if ((er->eep[index].eemtype == eqgSM2) || 
-          (er->eep[index].eemtype == eqgSM3) ||
-          (er->eep[index].eemtype == eqgSM4)) {
+  else if ((er->eep[index].eemtype == eqgSMs) || 
+          (er->eep[index].eemtype == eqgSMps) ||
+          (er->eep[index].eemtype == eqgSMg) ||
+          (er->eep[index].eemtype == eqgSMpg)) {
     Z = er->eep[index].elem;
     *wj = 1.0/er->eep[index].w;
     /**wj = (Z-q)/(Z*er->eep[index].w);*/
index 8a96ee756fe6692d3493069732d91ede88a3965b..3aaa48a10cda2bc5f26f2a635dfefce50306fbd2 100644 (file)
@@ -49,7 +49,7 @@ void matrix_multiply(FILE *fp,int n,int m,double **x,double **y,double **z)
 void matrix_invert(FILE *fp,int n,double **a)
 {
   int i,j,m,lda,*ipiv,lwork,info;
-  double **test,**id,*work;
+  double **test=NULL,**id,*work;
   
   if (fp) {
     fprintf(fp,"Inverting %d square matrix\n",n);
index 5b757bfd5b16ecfacac8ad3d61c5fe9c34e17891..83e402003ec7cdcc5798b3fa9c68dff36e47ba88 100644 (file)
@@ -51,7 +51,7 @@ extern void dump_nm2type(FILE *fp,x2top_nm2t nm2t);
 /* Dump the database for debugging. Can be reread by the program */
 
 extern int nm2type(x2top_nm2t nm2t,t_symtab *tab,t_atoms *atoms,
-                  t_atomtype *atype,int *nbonds,t_params *bond);
+                  t_atomtype atype,int *nbonds,t_params *bond);
 /* Try to determine the atomtype (force field dependent) for the atoms 
  * with help of the bond list 
  */
index 572b88f3aca50fa6ff28233a624911e9f21c85ca..a0061a7b9310c74096d3e09eb30c99b2c6bfc084 100644 (file)
@@ -115,12 +115,10 @@ static real calc_jab(rvec xi,rvec xj,real wi,real wj,int eemtype)
  
   switch (eemtype) {
   case eqgBultinck:
-  case eqgSM1:
+  case eqgSMp:
     eNN = coul_nucl_nucl(0,r);
     break;
-  case eqgSM2:
-  case eqgSM3:
-  case eqgSM4:
+  case eqgSMs:
     if ((wi > 0) && (wj > 0)) {
       wij = 2*(wi + wj)/(wi*wj);
       eSS = coul_slater_slater(wij,r);
@@ -129,6 +127,9 @@ static real calc_jab(rvec xi,rvec xj,real wi,real wj,int eemtype)
       eNN = coul_nucl_nucl(0,r);
     }
     break;
+  case eqgSMps:
+  case eqgSMg:
+  case eqgSMpg:
   case eqgYang:
   default:
     gmx_fatal(FARGS,"Can not treat algorithm %d yet in calc_jab",eemtype);
@@ -222,8 +223,9 @@ static void qgen_calc_Jab(t_qgen *qgen,void *eem,int eemtype)
       if (i != j) {
        wj = qgen->wj[j];
        qgen->Jab[i][j] = calc_jab(qgen->x[i],qgen->x[j],wi,wj,qgen->eemtype);
-       if ((eemtype == eqgSM3) || (eemtype == eqgSM4))
-         qgen->rhs[i] -= qgen->elem[j]*calc_j1(qgen->x[i],qgen->x[j],wi,wj,qgen->eemtype);
+       if ((eemtype == eqgSMps) || (eemtype == eqgSMpg))
+         qgen->rhs[i] -= qgen->elem[j]*calc_j1(qgen->x[i],qgen->x[j],
+                                               wi,wj,qgen->eemtype);
       }
     }
   }
@@ -472,10 +474,11 @@ void assign_charges(char *molname,
     please_cite(stdout,"Bultinck2002a");
     generate_charges_bultinck(eem,atoms,x,tol,maxiter,atomprop);
     break;
-  case eqgSM1:
-  case eqgSM2:
-  case eqgSM3:
-  case eqgSM4:
+  case eqgSMp:
+  case eqgSMs:
+  case eqgSMps:
+  case eqgSMg:
+  case eqgSMpg:
     (void) generate_charges_sm(debug,molname,eem,atoms,x,tol,maxiter,atomprop,
                               qtotref,eemtype);
     break;