26 #include <sys/types.h>
55 while((c = getc(f)) !=
'\n') {
74 return(
Fopen(name,
"r"));
101 printf(
"malloc %d\n", size);
102 #ifndef NAMD_NO_STDOUT_FLUSH
107 return((
char *) NULL);
109 if ((ptr = (
char *) malloc((
unsigned)size)) == NULL) {
110 printf(
"malloc %d", size);
111 #ifndef NAMD_NO_STDOUT_FLUSH
114 NAMD_die(
"Memory allocation error in Ambertoppar::get()");
127 for (i=0; i<81; i++) {
128 if ((j = getc(file)) == EOF) {
129 NAMD_die(
"Unexpected EOF in Amber parm file");
130 printf(
"Error: unexpected EOF in %s\n", name);
132 string[i] = (char) j;
133 if (
string[i] ==
'\n') {
137 if (i == 80 &&
string[i] !=
'\n') {
138 NAMD_die(
"Line too long in Amber parm file");
139 printf(
"Error: line too long in %s:\n%.80s", name,
string);
154 int i, idum, res, ifpert;
155 int *buffer, amber7_format;
159 {
iout <<
"Duplicate parm data in one object!\n" <<
endi;
164 iout <<
"Reading parm file (" << name <<
") ...\n" <<
endi;
167 if ((file =
genopen(name)) == NULL)
179 if (strncmp(
ititl,
"%VERSION",8))
183 iout <<
"PARM file in AMBER 7 format\n" <<
endi;
184 if (!
moveto(file,
"TITLE"))
194 {
if (!
moveto(file,
"POINTERS"))
199 fscanf(file,
"%d%d%d%d%d%d%d%d%d%d%d%d",
205 fscanf(file,
"%d%d%d%d%d%d%d%d%d%d%d%d",
208 &ifpert, &idum, &idum, &idum);
210 fscanf(file,
" %d %d %d %d %d %d",
214 { buffer =
new int[30];
249 printf(
"not equipped to read perturbation prmtop\n");
257 Nttyp = Ntypes*(Ntypes+1)/2;
266 Iac = (
int *)
get(
sizeof(
int)*
Natom);
270 Ipres = (
int *)
get(
sizeof(
int)*(
Nres+1));
318 if (!
moveto(file,
"ATOM_NAME"))
322 for (i=0; i<(
Natom/20 + (
Natom%20 ? 1 : 0)); i++)
323 preadln(file,
"", &AtomNames[i*80]);
332 if (!
moveto(file,
"CHARGE"))
336 for (i=0; i<
Natom; i++)
338 fscanf(file,
" %lf", &
Charges[i]);
340 fscanf(file,
" %f", &
Charges[i]);
354 for (i=0; i<
Natom; i++)
356 fscanf(file,
" %le", &
Masses[i]);
358 fscanf(file,
" %e", &
Masses[i]);
368 {
if (!
moveto(file,
"ATOM_TYPE_INDEX"))
372 for (i=0; i<
Natom; i++)
373 fscanf(file,
" %d", &
Iac[i]);
389 {
if (!
moveto(file,
"NUMBER_EXCLUDED_ATOMS"))
393 for (i=0; i<
Natom; i++)
394 fscanf(file,
" %d", &
Iblo[i]);
410 {
if (!
moveto(file,
"NONBONDED_PARM_INDEX"))
415 fscanf(file,
" %d", &
Cno[i]);
431 if (!
moveto(file,
"RESIDUE_LABEL"))
435 for (i=0; i<(
Nres/20 + (
Nres%20 ? 1 : 0)); i++)
443 {
if (!
moveto(file,
"RESIDUE_POINTER"))
447 for (i=0; i<
Nres; i++)
448 fscanf(file,
" %d", &
Ipres[i]);
465 if (!
moveto(file,
"BOND_FORCE_CONSTANT"))
471 fscanf(file,
" %lf", &
Rk[i]);
473 fscanf(file,
" %f", &
Rk[i]);
483 if (!
moveto(file,
"BOND_EQUIL_VALUE"))
489 fscanf(file,
" %lf", &
Req[i]);
491 fscanf(file,
" %f", &
Req[i]);
501 if (!
moveto(file,
"ANGLE_FORCE_CONSTANT"))
507 fscanf(file,
" %lf", &
Tk[i]);
509 fscanf(file,
" %f", &
Tk[i]);
519 if (!
moveto(file,
"ANGLE_EQUIL_VALUE"))
525 fscanf(file,
" %lf", &
Teq[i]);
527 fscanf(file,
" %f", &
Teq[i]);
537 if (!
moveto(file,
"DIHEDRAL_FORCE_CONSTANT"))
541 for (i=0; i<
Nptra; i++)
543 fscanf(file,
" %lf", &
Pk[i]);
545 fscanf(file,
" %f", &
Pk[i]);
555 if (!
moveto(file,
"DIHEDRAL_PERIODICITY"))
559 for (i=0; i<
Nptra; i++)
561 fscanf(file,
" %lf", &
Pn[i]);
563 fscanf(file,
" %f", &
Pn[i]);
573 if (!
moveto(file,
"DIHEDRAL_PHASE"))
577 for (i=0; i<
Nptra; i++)
579 fscanf(file,
" %lf", &
Phase[i]);
581 fscanf(file,
" %f", &
Phase[i]);
591 if (!
moveto(file,
"SOLTY"))
595 for (i=0; i<
Natyp; i++)
597 fscanf(file,
" %lf", &
Solty[i]);
599 fscanf(file,
" %f", &
Solty[i]);
610 if (!
moveto(file,
"LENNARD_JONES_ACOEF"))
614 for (i=0; i<
Nttyp; i++)
616 fscanf(file,
" %lf", &
Cn1[i]);
618 fscanf(file,
" %f", &
Cn1[i]);
629 if (!
moveto(file,
"LENNARD_JONES_BCOEF"))
633 for (i=0; i<
Nttyp; i++)
635 fscanf(file,
" %lf", &
Cn2[i]);
637 fscanf(file,
" %f", &
Cn2[i]);
650 {
if (!
moveto(file,
"BONDS_INC_HYDROGEN"))
654 for (i=0; i<
Nbonh; i++)
655 fscanf(file,
" %d %d %d",
659 { buffer =
new int[3*
Nbonh];
664 for (i=0; i<
Nbonh; i++)
682 {
if (!
moveto(file,
"BONDS_WITHOUT_HYDROGEN"))
686 for (i=0; i<
Nbona; i++)
687 fscanf(file,
" %d %d %d",
691 { buffer =
new int[3*
Nbona];
696 for (i=0; i<
Nbona; i++)
715 {
if (!
moveto(file,
"ANGLES_INC_HYDROGEN"))
720 fscanf(file,
" %d %d %d %d",
725 { buffer =
new int[4*
Ntheth];
750 {
if (!
moveto(file,
"ANGLES_WITHOUT_HYDROGEN"))
755 fscanf(file,
" %d %d %d %d",
760 { buffer =
new int[4*
Ntheta];
786 {
if (!
moveto(file,
"DIHEDRALS_INC_HYDROGEN"))
790 for (i=0; i<
Nphih; i++)
791 fscanf(file,
" %d %d %d %d %d",
796 { buffer =
new int[5*
Nphih];
801 for (i=0; i<
Nphih; i++)
823 {
if (!
moveto(file,
"DIHEDRALS_WITHOUT_HYDROGEN"))
827 for (i=0; i<
Nphia; i++)
828 fscanf(file,
" %d %d %d %d %d",
833 { buffer =
new int[5*
Nphia];
838 for (i=0; i<
Nphia; i++) {
840 DihAt2[i] = buffer[5*i+1];
841 DihAt3[i] = buffer[5*i+2];
842 DihAt4[i] = buffer[5*i+3];
843 DihNum[i] = buffer[5*i+4];
855 {
if (!
moveto(file,
"EXCLUDED_ATOMS_LIST"))
859 for (i=0; i<
Nnb; i++)
860 fscanf(file,
" %d", &
ExclAt[i]);
876 if (!
moveto(file,
"HBOND_ACOEF"))
880 for (i=0; i<
Nphb; i++)
882 fscanf(file,
" %lf", &
HB12[i]);
884 fscanf(file,
" %f", &
HB12[i]);
894 if (!
moveto(file,
"HBOND_BCOEF"))
898 for (i=0; i<
Nphb; i++)
900 fscanf(file,
" %lf", &
HB6[i]);
902 fscanf(file,
" %f", &
HB6[i]);
912 if (!
moveto(file,
"HBCUT"))
917 for (i=0; i<
Nphb; i++)
919 fscanf(file,
" %lf", &H[i]);
921 fscanf(file,
" %f", &H[i]);
933 if (!
moveto(file,
"AMBER_ATOM_TYPE"))
937 for (i=0; i<(Natom/20 + (Natom%20 ? 1 : 0)); i++)
945 if (!
moveto(file,
"TREE_CHAIN_CLASSIFICATION"))
949 for (i=0; i<(Natom/20 + (Natom%20 ? 1 : 0)); i++)
957 {
if (!
moveto(file,
"JOIN_ARRAY"))
961 for (i=0; i<
Natom; i++)
980 {
if (!
moveto(file,
"IROTAT"))
984 for (i=0; i<
Natom; i++)
985 fscanf(file,
" %d", &
AtomRes[i]);
993 for (i=0; i<
Natom; i++) {
994 if (i+1 ==
Ipres[res+1])
1009 {
if (!
moveto(file,
"SOLVENT_POINTERS"))
1020 buffer =
new int[3];
1034 {
if (!
moveto(file,
"ATOMS_PER_MOLECULE"))
1038 for (i=0; i<
Nspm; i++)
1050 if (!
moveto(file,
"BOX_DIMENSIONS"))
1055 fscanf(file,
" %lf %lf %lf",
1057 fscanf(file,
" %f %f %f",
1059 &
Box[0], &Box[1], &Box[2]);
1074 if (
IfCap && !amber7_format) {
1078 fscanf(file,
" %d %lf %lf %lf %lf",
1080 fscanf(file,
" %d %f %f %f %f",
1087 printf(
"rdprm done\n");
1088 #ifndef NAMD_NO_STDOUT_FLUSH
1106 for (; restr<lastres; restr+=4) {
1107 if (!strncmp(restr,
"WAT ", 4)) {
1108 printf(
"first water: res = %d, atom = %d (%.4s)\n",
1111 #ifndef NAMD_NO_STDOUT_FLUSH
1114 return(
Ipres[res]-1);
1206 for (i=0; i<count; ++i)
1207 {
for (j=0; j<6; ++j)
1209 if (buf[j]==
'\n' || buf[j]==
'\0' || buf[j]==EOF)
1213 if (sscanf(buf,
"%d",data+i) != 1)
1215 if (i%12==11 && i<count-1)
1232 do preadln(fp,
"parm file", buf);
1233 while (strncmp(buf,
"%FLAG",5));
1236 sscanf(buf+5,
"%s",s);
1237 if (strcasecmp(s,label))
1238 iout <<
iWARN <<
"Skipping " << s <<
" in parm file while seeking " << label <<
".\n" <<
endi;
1244 preadln(fp,
"parm file", buf);
1245 if (strncmp(buf,
"%FORMAT",7))
void preadln(FILE *, const char *, char *)
std::ostream & endi(std::ostream &s)
static int readtoeoln(FILE *f)
std::ostream & iWARN(std::ostream &s)
FILE * Fopen(const char *filename, const char *mode)
FILE * genopen(const char *name)
void NAMD_die(const char *err_msg)
int read_fortran_12I6(FILE *, int *, int)
int moveto(FILE *, const char *)