4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * GRowing Old MAkes el Chrono Sweat
29 static char *SRCID_nm2type_c
= "$Id$";
52 t_nm2type
*rd_nm2type(char *ff
,int *nnm
)
56 char libfilename
[128];
57 char format
[128],f1
[128];
58 char buf
[1024],elem
[16],type
[16],nbbuf
[16],**newbuf
;
59 int i
,n
,nb
,nnnm
,line
=1;
62 sprintf(libfilename
,"%s.n2t",ff
);
63 fp
= libopen(libfilename
);
67 /* Read a line from the file */
68 bCont
= (fgets2(buf
,1023,fp
) != NULL
);
73 if ((n
= sscanf(buf
,"%s%s%d",elem
,type
,&nb
)) == 3) {
74 /* If we can read the first three, there probably is more */
77 strcpy(format
,"%*s%*s%*d");
78 for(i
=0; (i
<nb
); i
++) {
79 /* Complicated format statement */
82 if (sscanf(buf
,f1
,nbbuf
) != 1)
83 fatal_error(0,"Error on line %d of %s",line
,libfilename
);
84 newbuf
[i
] = strdup(nbbuf
);
91 nm2t
[nnnm
].elem
= strdup(elem
);
92 nm2t
[nnnm
].type
= strdup(type
);
93 nm2t
[nnnm
].nbonds
= nb
;
94 nm2t
[nnnm
].bond
= newbuf
;
107 void dump_nm2type(FILE *fp
,int nnm
,t_nm2type nm2t
[])
111 fprintf(fp
,"; nm2type database\n");
112 for(i
=0; (i
<nnm
); i
++) {
113 fprintf(fp
,"%-8s%-8s%-4d",nm2t
[i
].elem
,nm2t
[i
].type
,nm2t
[i
].nbonds
);
114 for(j
=0; (j
<nm2t
[i
].nbonds
); j
++)
115 fprintf(fp
,"%-5s",nm2t
[i
].bond
[j
]);
120 char *nm2type(int nnm
,t_nm2type nm2t
[],char *nm
,int nbonds
)
124 /* First check for names */
125 for(i
=0; (i
<nnm
); i
++) {
126 if ((strcasecmp(nm2t
[i
].elem
,nm
) == 0) &&
127 (nm2t
[i
].nbonds
== nbonds
))
130 /* Then for element */
131 for(i
=0; (i
<nnm
); i
++) {
132 if ((nm2t
[i
].elem
[0] == nm
[0]) &&
133 (nm2t
[i
].nbonds
== nbonds
))