-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
204 lines (168 loc) · 4.11 KB
/
main.c
File metadata and controls
204 lines (168 loc) · 4.11 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// multi.c
//
// 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.
//
#include "global.h"
#include "conformation.h"
#include "overlap.h"
#include "energy.h"
#include "random.h"
#include "sample.h"
#include "io.h"
//user specific code,var for run.
double temp; //temperature,Kelvin.
double eta0; //Solvent viscosity,poise;
double rm; //Molecular weight
double vbar; //Partial specific volume of solute,g/cm3.
double solden; //Solution density, cm3/g.
double Dt; //translational diffusion coefficients.
double ft; //translational friction coefficients.
double Dr; //rotation diffusion coefficients.
double fr; //rotation friction coefficients.
double tao[5] = {0,0,0,0,0}; //Relaxation time.
double taoh; //Harmonic mean (correlation) time.
double Rg; //Radius of gyration.
double eta; //Intrinsic viscosity.
char *title;
char *filename;
int nstep; //times of MC steps.
int nreject; //reject times;
double acceptrate; //accept rate
//user code,model data.
int ntotal,nspring,nang;
void UserData()
{
temp=293;
eta0=0.010;
rm=110000;
vbar=0.710;
solden=1.0;
Dt=0;ft=0;
Dr=0;fr=0;
tao[5]=(0,0,0,0,0);
taoh =0;
Rg = 0;
eta = 0;
title="The DNA" ;
filename="DNA-results.txt";
nstep=1000;
nreject=0;
acceptrate=0.5;
ntotal=50;
nspring=ntotal-2;
nang=nspring-2;
}
confor *confor_get(int nbd,int nsp,int nang)
//malloc a confor which have nbd beads
//and nsp springs.
{
confor *p;
p = malloc(sizeof(confor));
if (p == NULL) {
printf("out of memory\n");
exit(1);
}
p->nbd = nbd;
p->nsp = nsp;
p->nang = nang;
p->beads = malloc(sizeof(bead)*nbd);
p->springs = malloc(sizeof(spring)*nsp);
p->angs = malloc(sizeof(ang)*nang);
return p;
}
void confor_free(confor *p)
//free a confor.
{
free(p->beads);
free(p->springs);
free(p->angs);
free(p);
}
void confor_copy(confor *from,confor *to)
//copy a confor to another confor.
//both confors need to malloc first.
{
int i;
if((from->nbd != to->nbd) || (from->nsp != to->nsp) || (from->nang != to->nang)){
printf("confors don't have equal size,can't copy!\n");
exit(1);
}
for(i=0;i < from->nbd;i++){
to->beads[i].x = from->beads[i].x;
to->beads[i].y = from->beads[i].y;
to->beads[i].z = from->beads[i].z;
to->beads[i].r = from->beads[i].r;
}
for(i=0;i < from->nsp;i++){
to->springs[i].start = from->springs[i].start;
to->springs[i].end = from->springs[i].end;
to->springs[i].len = from->springs[i].len;
}
for(i=0;i < from->nang;i++){
to->angs[i].start = from->angs[i].start;
to->angs[i].end = from->angs[i].end;
to->angs[i].angle = from->angs[i].angle;
}
}
void RejectConfor(char *s)
{
printf("Conformation rejected,reason:");
printf("%s\n",s);
nreject++;
}
void AcceptConfor(confor *newconf,confor *conf)
{
confor_copy(newconf,conf); //Let old comformation = new comformation
}
int main(int argc, char** argv)
{
int i;
double Eprev,Enew,u;
confor *conf,*newconf;
UserData();
conf = confor_get(ntotal,nspring,nang);
newconf = confor_get(ntotal,nspring,nang);
InitialConfor(conf);
confor_copy(conf,newconf);
SavePDBFile(conf,"DNAInitial.pdb");
for(i=0;i<=nstep;i++){
printf("run nstep times %d\n",i);
//sample every 100 run.
//don't sample too often,or you would wait too long till stop.
if(!(i%100)){
sample(conf,i);
results_output(stdout);
}
acceptrate = (i-nreject)/(double)i;
Eprev = Energy(conf);
McMove(conf,newconf);
if(ls_overlap(newconf)){
RejectConfor("overlap");
continue;
}
Enew = Energy(newconf);
if(Enew <= Eprev){ //accept conformation.
AcceptConfor(newconf,conf);
} else {
u = rnd();
if(u<exp(-(Enew-Eprev)/(kB*temp)))
AcceptConfor(newconf,conf);
else{
RejectConfor("Energy too high");
continue;
}
}
}
SavePDBFile(conf,"DNAFinal.pdb");
printf("\naccept rate %f\n",acceptrate);
/*write results*/
results_output(stdout);
FILE *fp;
fp=fopen(filename,"w");
results_output(fp);
fclose(fp);
return 0;
}