Modified pdb2gmx to automatically pick the force field from the current directory
authorErik Lindahl <lindahl@cbr.su.se>
Thu, 26 Aug 2010 22:18:55 +0000 (00:18 +0200)
committerErik Lindahl <lindahl@cbr.su.se>
Thu, 26 Aug 2010 22:18:55 +0000 (00:18 +0200)
if a choice is specified with the -ff option, even if others exist. We still
print a notice about it. The full include paths were also removed from the topology,
but we now print information about where the FF was picked up from, and a notice
that this location must be included when processing it if it is a non-standard one.

include/pdb2top.h
src/kernel/pdb2gmx.c
src/kernel/pdb2top.c

index 74115463b24b73c7d3f78d5eb4ea4b557a30e549..0fc4ab5d197a6ecd9ad2e7555e79589c400f0bc4 100644 (file)
@@ -84,7 +84,7 @@ void match_atomnames_with_rtp(t_restp restp[],t_hackblock hb[],
  * add these atoms to restp.
  */
 
-void print_top_comment(FILE *out,const char *filename,const char *generator,gmx_bool bITP);
+void print_top_comment(FILE *out,const char *filename,const char *generator,const char *ffdir,gmx_bool bITP);
 
 void print_top_header(FILE *out,const char *filename,const char *title,gmx_bool bITP, 
                              const char *ffdir,real mHmult);
index c1c5cb9cffa31ab50f317075e3fbd45d9df6ce7c..ccf7b68009a96ce69f3bd74cb5a703f54ea480ca 100644 (file)
@@ -1531,11 +1531,8 @@ int main(int argc, char *argv[])
   top_fn=ftp2fn(efTOP,NFILE,fnm);
   top_file=gmx_fio_fopen(top_fn,"w");
 
-#ifdef PACKAGE_VERSION
-  sprintf(generator,"%s - version %s",ShortProgram(), PACKAGE_VERSION );
-#else
-  sprintf(generator,"%s - version %s",ShortProgram(), "unknown" );
-#endif
+  sprintf(generator,"%s - %s",ShortProgram(), GromacsVersion() );
+
   print_top_header(top_file,top_fn,generator,FALSE,ffdir,mHmult);
 
   nincl=0;
@@ -1809,7 +1806,7 @@ int main(int argc, char *argv[])
     nmol++;
 
     if (bITP)
-      print_top_comment(itp_file,itp_fn,generator,TRUE);
+      print_top_comment(itp_file,itp_fn,generator,ffdir,TRUE);
 
     if (cc->bAllWat)
       top_file2=NULL;
index 61fd2670f595e8548129c5c49e77f4da04caf0a7..e9652bf9c7feaa89c7a8440b899a1067f912d7d0 100644 (file)
 #include <stdio.h>
 #include <math.h>
 #include <ctype.h>
+
+#if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
+#include <direct.h>
+#include <io.h>
+#endif
+
+
 #include "vec.h"
 #include "copyrite.h"
 #include "smalloc.h"
@@ -133,11 +140,18 @@ choose_ff(const char *ffsel,
 {
     int  nff;
     char **ffdirs,**ffs,**ffs_dir,*ptr;
-    int  i,j,sel;
+    int  i,j,sel,cwdsel,nfound;
     char buf[STRLEN],**desc;
     FILE *fp;
     char *pret;
-
+    char thisdir[STRLEN];
+    
+#if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
+    ptr = _getcwd(thisdir,sizeof(thisdir)-1);
+#else
+    ptr =  getcwd(thisdir,sizeof(thisdir)-1);
+#endif
+    
     nff = fflib_search_file_in_dirend(fflib_forcefield_itp(),
                                       fflib_forcefield_dir_ext(),
                                       &ffdirs);
@@ -176,21 +190,48 @@ choose_ff(const char *ffsel,
 
     if (ffsel != NULL)
     {
-        sel = -1;
+        sel     = -1;
+        cwdsel  = -1;
+        nfound  = 0;
         for(i=0; i<nff; i++)
         {
-            if (strcmp(ffs[i],ffsel) == 0)
+            if ( strcmp(ffs[i],ffsel)==0 )
             {
-                if (sel >= 0)
+                /* Matching ff name */
+                sel = i;
+                nfound++;
+                
+                if( strcmp(ffs_dir[i],thisdir)==0 )
                 {
-                    gmx_fatal(FARGS,"There are multiple force field directories in your path with the name '%s'. Run without the -ff switch and select the force field interactively.",ffsel);
+                    cwdsel = i;
                 }
-                sel = i;
             }
         }
-        if (sel == -1)
+        
+        if(cwdsel != -1)
+        {
+            sel = cwdsel;
+        }
+        
+        if(nfound>1)
+        {
+            if(cwdsel!=-1)
+            {
+                fprintf(stderr,
+                        "Note: Force field '%s' occurs in %d places, using version from current directory.\n"
+                        "Use interactive selection (not the -ff option) if you prefer a different one.\n",
+                        ffsel,nfound);
+            }
+            else
+            {
+                gmx_fatal(FARGS,
+                          "Force field '%s' occurs in %d places, but not in the current directory.\n"
+                          "Run without the -ff switch and select the force field interactively.",ffsel,nfound);
+            }
+        }
+        else if (nfound==0)
         {
-            gmx_fatal(FARGS,"Could not find force field '%s'",ffsel);
+            gmx_fatal(FARGS,"Could not find force field '%s' in current directory, install tree or GMXDATA path.",ffsel);
         }
     }
     else if (nff > 1)
@@ -459,27 +500,54 @@ static void print_top_heavy_H(FILE *out, real mHmult)
            "in pdb2top\n",mHmult);
 }
 
-void print_top_comment(FILE *out,const char *filename,
-                       const char *generator,gmx_bool bITP)
+void print_top_comment(FILE *out,
+                       const char *filename,
+                       const char *generator,
+                       const char *ffdir,
+                       gmx_bool bITP)
 {
   char tmp[256]; 
-
+  char ffdir_parent[STRLEN];
+  char *p;
+        
   nice_header(out,filename);
-  fprintf(out,";\tThis is your %stopology file\n",bITP ? "include " : "");
-  fprintf(out,";\tit was generated using program:\n;\t%s\n",
+  fprintf(out,";\tThis is a %s topology file\n;\n",bITP ? "include" : "standalone");
+  fprintf(out,";\tIt was generated using program:\n;\t%s\n;\n",
           (NULL == generator) ? "unknown" : generator);
-  fprintf(out,";\twith command line:\n;\t%s\n;\n\n",command_line());
+  fprintf(out,";\tCommand line was:\n;\t%s\n;\n",command_line());
+    
+  strncpy(ffdir_parent,ffdir,STRLEN-1);
+  p=strrchr(ffdir_parent,DIR_SEPARATOR);
+
+  if(p==NULL)
+  {
+      fprintf(out,";\tForce field data was read from the standard Gromacs share directory.\n;\n\n");
+  }
+  else 
+  {
+      *p='\0';
+      
+      fprintf(out,
+              ";\tForce field data was read from:\n"
+              ";\t%s\n"
+              ";\n"
+              ";\tNote:\n"
+              ";\tThis might be a non-standard force field location. When you use this topology, the\n"
+              ";\tforce field must either be present in the current directory, or the location\n"
+              ";\tspecified in the GMXLIB path variable or with the 'include' mdp file option.\n;\n\n",
+              ffdir_parent);
+  }
 }
 
 void print_top_header(FILE *out,const char *filename, 
                       const char *title,gmx_bool bITP,const char *ffdir,real mHmult)
 {
-    print_top_comment(out,filename,title,bITP);
+    print_top_comment(out,filename,title,ffdir,bITP);
     
     print_top_heavy_H(out, mHmult);
     fprintf(out,"; Include forcefield parameters\n");
-    fprintf(out,"#include \"%s%c%s\"\n\n",
-            ffdir,DIR_SEPARATOR,fflib_forcefield_itp());
+    fprintf(out,"#include \"%s\"\n\n",
+            fflib_forcefield_itp());
 }
 
 static void print_top_posre(FILE *out,const char *pr)
@@ -495,7 +563,7 @@ static void print_top_water(FILE *out,const char *ffdir,const char *water)
     char buf[STRLEN];
 
   fprintf(out,"; Include water topology\n");
-  fprintf(out,"#include \"%s%c%s.itp\"\n",ffdir,DIR_SEPARATOR,water);
+  fprintf(out,"#include \"%s.itp\"\n",water);
   fprintf(out,"\n");
   fprintf(out,"#ifdef POSRES_WATER\n");
   fprintf(out,"; Position restraint for each water oxygen\n");
@@ -505,11 +573,11 @@ static void print_top_water(FILE *out,const char *ffdir,const char *water)
   fprintf(out,"#endif\n");
   fprintf(out,"\n");
 
-    sprintf(buf,"%s%c%s",ffdir,DIR_SEPARATOR,"ions.itp");
+    sprintf(buf,"ions.itp");
     if (fflib_fexist(buf))
     {
         fprintf(out,"; Include topology for ions\n");
-        fprintf(out,"#include \"%s%cions.itp\"\n",ffdir,DIR_SEPARATOR);
+        fprintf(out,"#include \"ions.itp\"\n");
         fprintf(out,"\n");
     }
 }