summaryrefslogtreecommitdiff
path: root/sim/src/globals.c
blob: d7982ce1f4fc55be5f4678cccfdc6dfad159da82 (plain)
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// Copyright 2005-2007 Nanorex, Inc.  See LICENSE file for details. 
#include "simulator.h"

// Everything in here has to be updated in 6 places:
//
// The top of this file, where the actual symbol is defined.
// The bottom of this file, where the initial value is set.
// In globals.h, where others pick up the definitions.
// The top of sim.pyx, where these symbols are linked to python code.
// In __getattr__ in sim.pyx, to let python get them.
// In __setattr__ in sim.pyx, to let python set them.
//
// Sure would be nice to do it all just once...
//
// That could be done if sim.pyx can have cpp macros in it...

static char const rcsid[] = "$Id$";

int debug_flags;

int Interrupted; /* set to 1 when a SIGTERM is received */

struct xyz Center, Bbox[2];

int Iteration;

char *CommandLine;

// definitions for command line args

int ToMinimize;
int IterPerFrame;
int NumFrames;
int DumpAsText;
int DumpIntermediateText;
int PrintFrameNums;
int OutputFormat;
int KeyRecordInterval;
int DirectEvaluate;
int QuadraticStretchPotential;
int PrintPotentialEnergy;
float ExcessiveEnergyLevel;
char *IDKey;
char *InputFileName;
char *OutputFileName;
char *TraceFileName;
char *BaseFileName;
char *GromacsOutputBaseName;
char *PathToCpp;
char *SystemParametersFileName;
char *AmberBondedParametersFileName;
char *AmberNonbondedParametersFileName;
char *AmberChargesFileName;
int QualityWarningLevel;
float SimpleMovieForceScale;
double MinimizeThresholdCutoverRMS;
double MinimizeThresholdCutoverMax;
double MinimizeThresholdEndRMS;
double MinimizeThresholdEndMax;
int TimeReversal;
double ThermostatGamma;
double ThermostatG1;
int UseAMBER;
int TypeFeedback;

// absolute distance in nm beyond which gromacs will consider vdW
// forces to be exactly zero.  If less than zero, user defined tables
// will not be used, and a default value of 1.0 nm will be used.
double VanDerWaalsCutoffRadius;

// multiple of rvdW where interpolation table ends, and van der Waals
// force is considered exactly zero beyond this point.
double VanDerWaalsCutoffFactor;

int EnableElectrostatic;
int NeighborSearching;

// these are not reset by reinit_globals, but rather in
// readBondTableOverlay.
int LoadedSystemParameters;
char *UserParametersFileName;
int LoadedUserParameters;

FILE *OutputFile;
FILE *TraceFile;

int Count;

int ExcessiveEnergyWarning;
int ExcessiveEnergyWarningThisFrame;
int ComputedParameterWarning;
int InterruptionWarning;

// set to one in dynamics when processing the last iteration within a
// frame.  For debugging, hence the leading _.  Doesn't need
// initialization here.
int _last_iteration;

/** constants: timestep (.1 femtosecond), scale of distance (picometers) */
double Dt;              // seconds
double Dx;              // meters
double Dmass;           // units of mass vs. kg

double Temperature;	// Kelvins

const double Boltz = 1.3806503e-23;	/* k, in J/K */
const double Pi = 3.14159265358979323846;

// permittivity constant, epsilon_naught = 8.854187818 * 10^-12 F/m (Halliday&Resnick, third edition, 1978, p. A23)
// F/m is C/(V m) is A^2 s^4 kg^-1 m^-3
// elementary charge, e = 1.6021892 * 10^-19 C (H&R)
// C is A s

// mksCoulomb = 1/(4 pi epsilon_naught) in kg m^3 A^-2 s^-4
// mksCoulomb e^2 in kg m^3 e^-2 s^-2
// mksCoulomb e^2 10^12 in kg pm m^2 e^-2 s^-2 or J pm e^-2
// mksCoulomb e^2 10^12 10^18 in aJ pm e^-2
// COULOMB = 1e12 * 1e18 * 1.6021892e-19 * 1.6021892e-19 / (4 * Pi * 8.854187818e-12);

// Constant for electrostatic Coulomb force.  Multiply by the charge
// in elementary units, and divide by the separation in pm to get the
// potential in aJ

// aJ pm e^-2
const double COULOMB = 230.711374295;

const double MinElectrostaticSensitivity = 0.0015; // aJ

const double DielectricConstant = 160;

double totClipped;  // internal thermostat for numerical stability


void
reinit_globals(void)
{
    debug_flags = 0;
    Interrupted = 0;
    Iteration = 0;
    CommandLine = NULL;
    ToMinimize = 0;
    IterPerFrame = 10;
    NumFrames = 100;
    DumpAsText = 0;
    DumpIntermediateText = 0;
    PrintFrameNums = 0;
    OutputFormat = 1;
    KeyRecordInterval = 32;
    DirectEvaluate = 0;
    QuadraticStretchPotential = 0;
    PrintPotentialEnergy = 0;
    ExcessiveEnergyLevel = 0.1; // attoJoules
    IDKey = "";
    InputFileName = NULL;
    OutputFileName = NULL;
    TraceFileName = NULL;
    BaseFileName = NULL;
    GromacsOutputBaseName = NULL;
    PathToCpp = NULL;
    SystemParametersFileName = NULL;
    AmberBondedParametersFileName = NULL;
    AmberNonbondedParametersFileName = NULL;
    AmberChargesFileName = NULL;
    QualityWarningLevel = 5;
    SimpleMovieForceScale = 1.0;
    TimeReversal = 0;
    ThermostatGamma = 0.01;
    UseAMBER = 0;
    TypeFeedback = 0;
    
    MinimizeThresholdCutoverRMS = 50.0; // pN
    MinimizeThresholdCutoverMax = 0.0; // set by constrainGlobals, below
    MinimizeThresholdEndRMS = 1.0;
    MinimizeThresholdEndMax = 0.0; // set by constrainGlobals, below

    VanDerWaalsCutoffRadius = -1.0; // use gromacs built in functions
    VanDerWaalsCutoffFactor = 1.7;

    EnableElectrostatic = 1;
    NeighborSearching = 1;
    
    OutputFile = NULL;
    TraceFile = NULL;

    Count = 0;

    ExcessiveEnergyWarning = 0;
    ExcessiveEnergyWarningThisFrame = 0;
    ComputedParameterWarning = 0;
    InterruptionWarning = 0;

    Dt = 1e-16; // seconds
    Dx = 1e-12; // meters
    Dmass = 1e-27; // mass units in kg
    Temperature = 300.0; // Kelvins
    totClipped = 0.0;

    reInitializeBondTable();
}

void
constrainGlobals()
{
    if (MinimizeThresholdEndRMS > MinimizeThresholdCutoverRMS) {
        MinimizeThresholdCutoverRMS = MinimizeThresholdEndRMS;
        MinimizeThresholdCutoverMax = MinimizeThresholdEndMax;
    }
    if (MinimizeThresholdCutoverMax < MinimizeThresholdCutoverRMS) {
        MinimizeThresholdCutoverMax = 5.0 * MinimizeThresholdCutoverRMS;
    }
    if (MinimizeThresholdEndMax < MinimizeThresholdEndRMS) {
        MinimizeThresholdEndMax = 5.0 * MinimizeThresholdEndRMS;
    }
    if (VanDerWaalsCutoffFactor < 1.2) {
        VanDerWaalsCutoffFactor = 1.2;
    }
    if (VanDerWaalsCutoffFactor > 10.0) {
        VanDerWaalsCutoffFactor = 10.0;
    }

    ThermostatG1 = (1.01 - 0.27 * ThermostatGamma) * 1.4 * sqrt(ThermostatGamma);
}

void
printGlobals()
{
    write_traceline("#\n");
    write_traceline("# debug_flags: 0x%x\n", debug_flags);
    write_traceline("# IterPerFrame: %d\n", IterPerFrame);
    write_traceline("# NumFrames: %d\n", NumFrames);
    write_traceline("# DumpAsText: %d\n", DumpAsText);
    write_traceline("# DumpIntermediateText: %d\n", DumpIntermediateText);
    write_traceline("# PrintFrameNums: %d\n", PrintFrameNums);
    write_traceline("# OutputFormat: %d\n", OutputFormat);
    write_traceline("# KeyRecordInterval: %d\n", KeyRecordInterval);
    write_traceline("# DirectEvaluate: %d\n", DirectEvaluate);
    write_traceline("# ExcessiveEnergyLevel: %f aJ\n", ExcessiveEnergyLevel);
    write_traceline("# QualityWarningLevel: %d\n", QualityWarningLevel);
    if (ToMinimize) {
        write_traceline("# MinimizeThresholdCutoverRMS: %f\n", MinimizeThresholdCutoverRMS);
        write_traceline("# MinimizeThresholdCutoverMax: %f\n", MinimizeThresholdCutoverMax);
        write_traceline("# MinimizeThresholdEndRMS: %f\n", MinimizeThresholdEndRMS);
        write_traceline("# MinimizeThresholdEndMax: %f\n", MinimizeThresholdEndMax);
    }
    write_traceline("# VanDerWaalsCutoffRadius: %f\n", VanDerWaalsCutoffRadius);
    write_traceline("# VanDerWaalsCutoffFactor: %f\n", VanDerWaalsCutoffFactor);
    write_traceline("# EnableElectrostatic: %d\n", EnableElectrostatic);
    write_traceline("# NeighborSearching: %d\n", NeighborSearching);
    write_traceline("# ThermostatGamma: %f\n", ThermostatGamma);
    write_traceline("# UseAMBER: %d\n", UseAMBER);
    if (SystemParametersFileName != NULL && LoadedSystemParameters) {
        write_traceline("# SystemParametersFileName: %s\n", SystemParametersFileName);
    }
    if (AmberBondedParametersFileName != NULL) {
        write_traceline("# AmberBondedParametersFileName: %s\n", AmberBondedParametersFileName);
    }        
    if (AmberNonbondedParametersFileName != NULL) {
        write_traceline("# AmberNonbondedParametersFileName: %s\n", AmberNonbondedParametersFileName);
    }        
    if (AmberChargesFileName != NULL) {
        write_traceline("# AmberChargesFileName: %s\n", AmberChargesFileName);
    }        
    if (UserParametersFileName != NULL && LoadedUserParameters) {
        write_traceline("# UserParametersFileName: %s\n", UserParametersFileName);
    }
    if (GromacsOutputBaseName != NULL) {
        write_traceline("# GromacsOutputBaseName: %s\n", GromacsOutputBaseName);
    }
    write_traceline("#\n");
}


/*
 * Local Variables:
 * c-basic-offset: 4
 * tab-width: 8
 * End:
 */