1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
// Subroutine to print a PDB of the coordinates
void print_pdb(double **coords, const int simbox_TotalNparticles, const int move)
{
char filename[128];
_snprintf(filename, 128, "output%000006d.pdb", move);
FILE *f = fopen(filename, "w");
fprintf(f, "CRYST1 %8.3f %8.3f %8.3f 90.00 90.00 90.00\n",
sim_box[0], sim_box[1], sim_box[2]);
for (int i = 0; simbox_TotalNparticles; i = i + 1)
{
fprintf(f, "ATOM %5d Methane Methane 1 %8.3f%8.3f%8.3f 1.00 0.00 Methane\n",
i+1, coords[i][0], coords[i][1], coords[i][2]);
fprintf(f, "TER\n");
}
fclose(f);
}
int main()
{
// Random variables and other
double **coords = new double*[simbox_TotalNparticles];
int seedmain;
// Random seed
srand(time(NULL));
seedmain=1; //time(NULL);
// Starts the seqeunce of randon numbers
CRandomMersenne RanGen(seedmain);
CRandomMersenne *pRanGen;
pRanGen=&RanGen;
double random=RanGen.Random();
// Randomly generate the coordinates of the atoms in the box
for (int i = 0; i < simbox_TotalNparticles ; i = i + 1)
{
coords[i] = new double[3];
// Note "random(0,x)" would generate a random number
// between 0 and $x
coords[i][0] = random*sim_box[0];
coords[i][1] = random*sim_box[1];
coords[i][2] = random*sim_box[2];
// Print the initial PDB file
print_pdb(coords, simbox_TotalNparticles, 0);
cin.ignore();
}
return (0);
}
|