[gmx-users] template.c

Mark Abraham Mark.Abraham at anu.edu.au
Tue Sep 8 04:16:25 CEST 2009


Chih-Ying Lin wrote:
> Hi :
> I have difficulties to understand the following three files, which are
> in Gromacs Package.
> 1.  template.c

This is a template you can modify to make a GROMACS utility that does 
something new and interesting.

> 2.  README

This is to read to help you understand.

> 3.  Makefile.x86_64-unknown-linux-gnu

As the README says, this is a Makefile for your architecture, intended 
to compile template.c and link to the GROMACS libraries correctly.

> 
> Please tell me if I have to do part 3 to compile template.c.

Do which "part 3"?

Mark

> Thank you
> Lin
> 
> 
> ============= [ TEMPLATE.C ]
> ===================================================================
> /*
>  * $Id: template.c,v 1.5 2008/05/29 08:36:53 hess Exp $
>  *
>  *                This source code is part of
>  *
>  *                 G   R   O   M   A   C   S
>  *
>  *          GROningen MAchine for Chemical Simulations
>  *
>  *                        VERSION 3.0
>  *
>  * Copyright (c) 1991-2001
>  * BIOSON Research Institute, Dept. of Biophysical Chemistry
>  * University of Groningen, The Netherlands
>  *
>  * 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.
>  *
>  * Do check out http://www.gromacs.org , or mail us at gromacs at gromacs.org .
>  *
>  * And Hey:
>  * Gyas ROwers Mature At Cryogenic Speed
>  */
> 
> /* This line is only for CVS version info */
> static char *SRCID_template_c = "$Id: template.c,v 1.5 2008/05/29 08:36:53 hess
> Exp $";
> 
> #include "statutil.h"
> #include "typedefs.h"
> #include "smalloc.h"
> #include "vec.h"
> #include "copyrite.h"
> #include "statutil.h"
> #include "tpxio.h"
> 
> 
> int main(int argc,char *argv[])
> {
>   static char *desc[] = {
>     "this is a small test program meant to serve as a template ",
>     "when writing your own analysis tools. The advantage of ",
>     "using gromacs for this is that you have access to all ",
>     "information in the topology, and your program will be ",
>     "able to handle all types of coordinates and trajectory ",
>     "files supported by gromacs. Go ahead and try it! ",
>     "This test version just writes the coordinates of an ",
>     "arbitrary atom to standard out for each frame. You can ",
>     "select which atom you want to examine with the -n argument."
>   };
> 
>   static int n=1;
> 
>   /* Extra arguments - but note how you always get the begin/end
>    * options when running the program, without mentioning them here!
>    */
> 
>   t_pargs pa[] = {
>     { "-n", FALSE, etINT, {&n},
>       "Plot data for atom number n (starting on 1)"
>     }
>   };
> 
>   t_topology top;
>   int        ePBC;
>   char       title[STRLEN];
>   t_trxframe fr;
>   rvec       *xtop;
>   matrix     box;
>   int        status;
>   int        flags = TRX_READ_X;
> 
>   t_filenm fnm[] = {
>     { efTPS,  NULL,  NULL, ffREAD },   /* this is for the topology */
>     { efTRX, "-f", NULL, ffREAD }      /* and this for the trajectory */
>   };
> 
> #define NFILE asize(fnm)
> 
>   CopyRight(stderr,argv[0]);
> 
>   /* This is the routine responsible for adding default options,
>    * calling the X/motif interface, etc. */
>   parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_CAN_VIEW,
>                     NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL);
> 
>   /* We don't need any topology information to write the coordinates,
>    * but to show how it works we start by writing the name and
>    * charge of the selected atom. It returns a boolean telling us
>    * whether the topology was found and could be read
>    */
> 
>   read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&ePBC,&xtop,NULL,box,TRUE);
>   sfree(xtop);
> 
>   n=n-1; /* Our enumeration started on 1, but C starts from 0 */
>   /* check that this atom exists */
>   if(n<0 || n>(top.atoms.nr))
>   {
>     printf("Error: Atom number %d is out of range.\n",n);
>     exit(1);
>   }
> 
>   printf("Atom name: %s\n",*(top.atoms.atomname[n]));
>   printf("Atom charge: %f\n",top.atoms.atom[n].q);
> 
>   /* The first time we read data is a little special */
>   read_first_frame(&status,ftp2fn(efTRX,NFILE,fnm),&fr,flags);
> 
>   /* This is the main loop over frames */
>   do {
>     /* coordinates are available in the vector fr.x
>      * you can find this and all other structures in
>      * the types directory under the gromacs include dir.
>      * Note how flags determines wheter to read x/v/f!
>      */
>     printf("Coordinates at t=%8.3f : %8.5f %8.5f %8.5f\n",fr.time,fr.x[n][XX],fr
> .x[n][YY],fr.x[n][ZZ]);
>   } while(read_next_frame(status,&fr));
> 
>   thanx(stderr);
> 
>   return 0;
> }
> 
> 
> 
> 
> 
> 
> 
> ======================= [ README ]
> =================================================================
> 
> [chihying at hpc-login2 template]$ more README
> Once installed, this directory contains a Makefile and
> a small program that you could use as a template when
> writing your own analysis software.
> 
> A Makefile.arch is created for each architecture you install
> with the correct paths and libraries. You will have to link
> (or copy) the correct makefile to "Makefile" or use the -f
> option to gmake in order to select a makefile.
> 
> ----------------------------------------------------------
> 
> If you are reading this in the distribution directory,
> there will be a Makefile.am which automake uses to
> create a Makefile.in which in turn is converted to
> a Makefile by the configure script. Note that this is
> NOT the template makefile - it is called Template.mak,
> and used to create Makefile.arch at build time.
> 
> You should NOT touch or copy Makefile.in unless you
> really know what you are doing - it is a template file
> used by the configure script to create the real Makefile.
> 
> If you want to use automake and autoconf yourself, look
> in the contrib directory of the distribution.
> 
> 
> 
> 
> 
> 
> =================== [ Makefile.x86_64-unknown-linux-gnu  ]
> =======================================================
> 
> [chihying at hpc-login2 template]$ more Makefile.x86_64-unknown-linux-gnu
> # Generated automatically from Makefile.in by configure.
> #
> # This is a Gromacs 3.0 template makefile for your own utility programs.
> #
> # Copy this file to whatever directory you are using for your own
> # software and add more targets like the template one below.
> #
> # If you are using gmake it is relatively straightforward to add
> # an include based on environment variables (like previous Gromacs versions)
> # to select compiler flags and stuff automatically, but below it is static:
> #
> 
> # Variables set by the configuration script:
> LIBS         = -lmd_mpi -lgmx_mpi  -L/usr/lib64 -lnsl -lsrfftw -lsfftw
> -lm   -lSM -lICE -
> lX11
> LDFLAGS      = -L/usr/usc/gromacs/4.0.5//lib
> CFLAGS       = -O3 -fomit-frame-pointer -finline-functions -Wall
> -Wno-unused -funroll-all
> -loops -std=gnu99   -I/usr/usc/gromacs/4.0.5//include
> -I/usr/usc/gromacs/4.0.5//include/g
> romacs
> CC           = mpicc
> LD           = $(CC)
> 
> # The real make targets - note that most make programs support
> # the shortcut $^ instead of listing all object files a second
> # time, but we cannot count on it...
> 
> template:       template.o
>                 $(LD) $(LDFLAGS) -o $@ template.o $(LIBS)
> _______________________________________________
> gmx-users mailing list    gmx-users at gromacs.org
> http://lists.gromacs.org/mailman/listinfo/gmx-users
> Please search the archive at http://www.gromacs.org/search before posting!
> Please don't post (un)subscribe requests to the list. Use the 
> www interface or send it to gmx-users-request at gromacs.org.
> Can't post? Read http://www.gromacs.org/mailing_lists/users.php
> 



More information about the gromacs.org_gmx-users mailing list