34 cout <<
"DEBUG readGROMACS: filename=" << filename << endl;
36 ifstream fgro(filename.
c_str());
38 cerr <<
"Error: File " << filename <<
" not opened!" << endl;
44 int readflag(0), atomnum, resnum, prev_resnum = -1;
45 int n(0), natom, nmol(0);
47 char restype[20], atomtype[20];
56 cout <<
"Title: " << mol->
id << endl;
59 sscanf(aline,
"%d", &natom);
62 cout <<
"Number of atoms: " << natom << endl;
68 while ( !fgro.eof() && n < natom ) {
71 i = strcspn(aline,
"\n");
72 if ( i > 0 ) aline[i] =
' ';
73 if ( i > 40 ) readflag = 1;
74 if ( strstr(aline,
"nan") || strstr(aline,
"NAN") ) {
75 cerr <<
"Warning: NAN at line number " << linenum << endl;
81 sscanf(aline,
"%5d%5c%5c%5d%8lf%8lf%8lf%8lf%8lf%8lf",
82 &resnum, restype, atomtype, &atomnum,
83 &coord[0], &coord[1], &coord[2], &vel[0], &vel[1], &vel[2]);
84 if ( resnum < 1 ) resnum = n + 1;
85 if ( atomnum < 1 ) atomnum = n + 1;
87 if ( resnum != prev_resnum ) {
90 res->
num = prev_resnum = resnum;
93 for ( i=0, j=0; i<strlen(atomtype); i++ )
94 if ( !isspace(atomtype[i]) ) atomtype[j++] = atomtype[i];
97 else atom =
atom_add(&atom, atomtype);
99 atom->
coord = coord * 10;
100 atom->
vel = vel * 10;
104 cout << atom->
num <<
" " << res->
num <<
" " << atom->
coord << endl;
117 sscanf( aline,
"%lf %lf %lf", &box[0], &box[1], &box[2]);
119 cout <<
"Box size: " << box <<
" nm" << endl;
121 molgroup->
box = box * 10;
146 cout <<
"DEBUG writeGROMACS: filename=" << filename << endl;
148 if ( !molgroup )
return -1;
150 ofstream fgro(filename.
c_str());
152 cerr <<
"Error: File " << filename <<
" not opened!" << endl;
156 long i, j, nw(0), natom(0);
158 memset(atomtype, 0, 8);
161 cout <<
"New file name: " << filename << endl;
167 for ( mol = molgroup->
mol; mol; mol = mol->
next )
168 for ( res = mol->
res; res; res = res->
next )
169 for ( atom = res->
atom; atom; atom = atom->
next )
176 comment[i] = molgroup->
comment[i];
180 fgro <<
" " << natom << endl;
183 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
185 for ( res = mol->
res; res; res = res->
next ) {
186 for ( atom = res->
atom; atom; atom = atom->
next ) {
188 memset(atomtype,
' ', 5);
189 for ( i=(
long)strlen(atom->
type)-1, j=4; i>=0 && j>=0; i-- )
190 if ( !isspace(atom->
type[i]) ) atomtype[j--] = atom->
type[i];
191 fgro << setw(5) << res->
num << setw(5) << res->
type <<
192 setw(5) << atomtype << setw(5) << atom->
num <<
193 fixed << setprecision(3) << setw(8) << 0.1*atom->
coord[0] <<
194 setw(8) << 0.1*atom->
coord[1] << setw(8) << 0.1*atom->
coord[2] <<
195 setprecision(4) << setw(8) << 0.1*atom->
vel[0] <<
196 setw(8) << 0.1*atom->
vel[1] << setw(8) << 0.1*atom->
vel[2] << endl;
201 if ( nw > 0 ) nmol++;
204 fgro << fixed << setprecision(2) << setw(9) << 0.1*molgroup->
box[0] <<
205 setw(9) << 0.1*molgroup->
box[1] << setw(9) << 0.1*molgroup->
box[2] << endl;