This file is indexed.

/usr/include/ghemical/engine.h is in libghemical-dev 3.0.0-4.1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
// ENGINE.H : the "engine" base class for computation engine classes.

// Copyright (C) 1998 Tommi Hassinen.

// This package 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.

// This package is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this package; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

/*################################################################################################*/

#ifndef ENGINE_H
#define ENGINE_H

#include "libghemicaldefine.h"

class setup;

struct ecomp_store;

class engine;

class engine_bp;	// boundary potential
class engine_pbc;	// periodic boundary conditions

class number_density_evaluator;
class radial_density_function_evaluator;

/*################################################################################################*/

class atom;	// atom.h
class bond;	// bond.h

class model;	// model.h

#include <stdlib.h>

#include <vector>
using namespace std;

#include "typedef.h"

/*################################################################################################*/

/// The setup class is used to define the submodel boundaries in the model.
/** There can be only a single setup object for each model object. 
The setup object will create the engine objects. */

class setup
{
	private:
	
	model * mdl;
	
	protected:
	
	engine * current_eng;
	i32s current_eng_index;
	
	bool has_setup_tables;
	
	// the global tables.
	// ^^^^^^^^^^^^^^^^^^

	atom ** atmtab; i32s natm;
	
	// the local tables.
	// ^^^^^^^^^^^^^^^^^
	
	atom ** qm_atmtab; i32s qm_natm;
	bond ** qm_bndtab; i32s qm_nbnd;
	
	atom ** mm_atmtab; i32s mm_natm;
	bond ** mm_bndtab; i32s mm_nbnd;
	
	bond ** boundary_bndtab; i32s boundary_nbnd;
	
	atom ** sf_atmtab; i32s sf_natm;
	
	public:
	
	setup(model *);
	virtual ~setup(void);
	
	model * GetModel(void) { return mdl; }
	
	bool HasSetupTables(void) { return has_setup_tables; }
	
	// access to global tables.
	// ^^^^^^^^^^^^^^^^^^^^^^^^
	
	atom ** GetAtoms(void) { return atmtab; }
	i32s GetAtomCount(void) { return natm; }
	
	// access to local tables.
	// ^^^^^^^^^^^^^^^^^^^^^^^
	
	atom ** GetQMAtoms(void) { return qm_atmtab; }
	i32s GetQMAtomCount(void) { return qm_natm; }
	bond ** GetQMBonds(void) { return qm_bndtab; }
	i32s GetQMBondCount(void) { return qm_nbnd; }

	atom ** GetMMAtoms(void) { return mm_atmtab; }
	i32s GetMMAtomCount(void) { return mm_natm; }
	bond ** GetMMBonds(void) { return mm_bndtab; }
	i32s GetMMBondCount(void) { return mm_nbnd; }
	
	bond ** GetBoundaryBonds(void) { return boundary_bndtab; }
	i32s GetBoundaryBondCount(void) { return boundary_nbnd; }
	
	atom ** GetSFAtoms(void) { return sf_atmtab; }
	i32s GetSFAtomCount(void) { return sf_natm; }
	
	engine * GetCurrentEngine(void) { return current_eng; }
	
	i32s GetCurrEngIndex(void) { return current_eng_index; }
	void SetCurrEngIndex(i32s index) { current_eng_index = index; }		// only file operations etc should use this...
	
	virtual void UpdateAtomFlags(void) = 0;
	
	void DiscardSetupInfo(void);
	void UpdateSetupInfo(void);
	
	// functions for obtaining information about available eng objects.
	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	
	virtual i32u GetEngineCount(void) = 0;
	virtual i32u GetEngineIDNumber(i32u) = 0;		// this is not much used yet. for saving eng info in files?!?!?!
	virtual const char * GetEngineName(i32u) = 0;
	virtual const char * GetClassName_lg(void) = 0;		// also see model::AddAtom_lg() ; this is an another Win32 API conflict...
	
	void CreateCurrentEngine(void);				///< Create the current_eng object for plotting...
	void DiscardCurrentEngine(void);
	
	virtual engine * CreateEngineByIndex(i32u) = 0;		///< Create an engine object.
	engine * CreateEngineByIDNumber(i32u);
};

/*################################################################################################*/

typedef double ecomp_data[5];

#define ECOMP_DATA_IND_B_bs	0	// bond stretching
#define ECOMP_DATA_IND_B_ab	1	// angle bending
#define ECOMP_DATA_IND_B_ti	2	// torsion + imp.tor. interactions
#define ECOMP_DATA_IND_NB_lj	3	// nonbonded interactions
#define ECOMP_DATA_IND_NB_es	4	// electrostatic interactions

/// A virtual base class for computations.

/** The engine classes are used to implement the computational details of various models 
(like different quantum-mechanical models and molecular mechanics models).

The engine class will store it's own atom coordinates.

When we want to compute something, we create an instance of some suitable engine-class using 
our setup-class. The engine-class will copy that information it needs, and calculates those results 
it is supposed to calculate. If we calculate some useful results that change our original system, 
we can copy those results back to our model-class.

The setup class will create two kinds of atom and bond tables using contents of the model object; 
one (global) contains all atoms/bonds, and the others (local ones) contain only those atoms/bonds 
that belong to a submodel (say, QM or MM submodel).

Since there is, for example, only one table for coordinates and derivatives at the engine base class, 
the different derived engine classes must create a suitable lookup table that maps the local tables 
back to the global one. */

// here are some common error/warning messages:
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#define CONSTRAINTS_NOT_SUPPORTED "Sorry ; constraints are not yet supported by this engine class."

class engine
{
	private:
	
	setup * stp;
	
	protected:
	
	i32s natm;
	
	f64 * crd;
	
	f64 energy;
	
// add atom::ecomp_grp_ind ; define/register the new groups in the model object (and save them in files).
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ecomp_grp		vector<const char *>	<- in model!!!
// ecomp_ngrp		int			<- in engine!!!
// ecomp_data		double *
// ecomp_map		int *			<- make the size (n*n).
//////////////////////////////////////////////////////////////////////////////
//	f64 E_solute;
//	f64 E_solvent;
//	f64 E_solusolv;
//////////////////////////////////////////////////////////////////////////////
	
	f64 * d1;	// GetD1() ???
	f64 * d2;	// GetD2() ???
	
	f64 virial[3];
	
	bool update_neighbor_list;
	
	int ECOMPcycles;
	
	int ECOMPstore_size;
	ecomp_data * ECOMPstore;
	
	friend void CopyCRD(model *, engine *, i32u);
	friend void CopyCRD(engine *, model *, i32u);
	
	friend class model;
	
	friend class geomopt;
	
	friend class moldyn;
	friend class moldyn_langevin;
	
	friend class sasaeval;
	
	friend class random_search;
	friend class systematic_search;
	friend class monte_carlo_search;
	friend class transition_state_search;
	friend class stationary_state_search;
	
	public:
	
	engine(setup *, i32u);
	virtual ~engine(void);
	
	setup * GetSetup(void) { return stp; }
	i32s GetAtomCount(void) { return natm; }
	
	void Check(i32u);			///< This is for debugging; will compare the computed gradient to a numerical one.
	f64 GetGradientVectorLength(void);	///< This calculates the gradient vector length (using the d1 array).
	
	void ScaleCRD(f64, f64, f64);
	
/**	This will request an update for the NB-term list (neighbor list) at the next
	energy evaluation.
*/
	void RequestNeighborListUpdate(void) { update_neighbor_list = true; }
	
	virtual void Compute(i32u, bool = false) = 0;	///< Will compute the energy, and the gradient if needed.
	
	virtual void DoSHAKE(bool);	///< This is an optional method that contains some SHAKE-like corrections to atomic coordinates ; is called before calculating forces in MD.
	
	// these are added to make it easier to set torsional constraints (like for plotting etc).
	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	
	virtual bool SetTorsionConstraint(atom *, atom *, atom *, atom *, f64, f64, bool) = 0;
	virtual bool RemoveTorsionConstraint(atom *, atom *, atom *, atom *) = 0;
	
	// these are mainly for drawing energy level diagrams...
	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	
	virtual i32s GetOrbitalCount(void) = 0;
	virtual f64 GetOrbitalEnergy(i32s) = 0;
	
	virtual i32s GetElectronCount(void) = 0;
	
	// these are for plotting purposes...
	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	
	virtual void SetupPlotting(void) = 0;
	
	virtual fGL GetVDWSurf(fGL *, fGL *) = 0;
	
	virtual fGL GetESP(fGL *, fGL *) = 0;
	
	virtual fGL GetElDens(fGL *, fGL *) = 0;
	
	virtual fGL GetOrbital(fGL *, fGL *) = 0;
	virtual fGL GetOrbDens(fGL *, fGL *) = 0;
	
	// these are to take data out for external apps etc...
	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	
	f64 GetEnergy(void);	///< Compute() must be called before this one!
	
	f64 ReadCRD(int);
	
	protected:
	
	void ecomp_AddCycle(void);				// called in every energy evaluation!
	void ecomp_AddStore2(int, int, int, double);		// called in every energy evaluation!
	void ecomp_AddStoreX(vector<int> &, int, double);	// called in every energy evaluation!
	
	public:
	
	void ecomp_Reset(void);
	double ecomp_ReadStore(int, int, int);
};

/*################################################################################################*/

fGL value_VDWSurf(engine *, fGL *, fGL *);
fGL value_ESP(engine *, fGL *, fGL *);
fGL value_ElDens(engine *, fGL *, fGL *);
fGL value_Orbital(engine *, fGL *, fGL *);
fGL value_OrbDens(engine *, fGL *, fGL *);

void CopyCRD(model *, engine *, i32u);
void CopyCRD(engine *, model *, i32u);

/*################################################################################################*/

/// A base engine class for systems that utilize a boundary potential.

class engine_bp : virtual public engine
{
	protected:
	
	bool use_bp;
	f64 bp_rad_solute; f64 bp_fc_solute;
	f64 bp_rad_solvent; f64 bp_fc_solvent;
	
	number_density_evaluator * nd_eval;
	radial_density_function_evaluator * rdf_eval;
	
	friend class model;
	
	friend class number_density_evaluator;
	friend class radial_density_function_evaluator;
	
	public:
	
	engine_bp(setup *, i32u);
	virtual ~engine_bp(void);
};

/*################################################################################################*/

/// A base engine class for systems with periodic boundary conditions.

class engine_pbc : virtual public engine
{
	protected:
	
	f64 box_HALFdim[3];
	
	i32s num_mol;
	i32s * mrange;
	
// TODO : how to use RDF-evaluator also here???
	
	friend class model;
	friend class moldyn;
	
	public:
	
	engine_pbc(setup *, i32u);
	virtual ~engine_pbc(void);
	
/**	This will check that molecules have not escaped from the periodic box. 
	If we doing geometry optimization or molecular dynamics for periodic models, 
	we should remember to call this at suitable intervals...
*/
	void CheckLocations(void);
};

/*################################################################################################*/

/// Calculates "number density" of solvent molecules -> engine::bp_center.

class number_density_evaluator
{
	protected:
	
	engine_bp * eng;
	bool linear;
	
	i32s classes;
	f64 * upper_limits;
	f64 * class_volumes;
	
	i32u cycles;
	i32u * counts;
	
	public:
	
	number_density_evaluator(engine_bp *, bool, i32s);
	~number_density_evaluator(void);
	
	private:
	
	void UpdateClassLimits(void);
	void ResetCounters(void);
	
	public:
	
	void PrintResults(ostream &);
	
	inline void AddCycle(void)
	{
		cycles++;
	}
	
	inline void AddValue(f64 p1)
	{
		i32s index = 0;
		while (index < classes)
		{
			if (p1 >= upper_limits[index]) index++;
			else break;
		}
		
		counts[index]++;
	}
};

/*################################################################################################*/

/// Calculates radial density function of solvent molecules (in practive O-O distances of H2O) -> engine::bp_center.

class radial_density_function_evaluator
{
	protected:
	
	engine_bp * eng;
	
	i32s classes;
	f64 graph_begin;
	f64 graph_end;
	f64 count_begin;
	f64 count_end;
	
	f64 * upper_limits;
	f64 * class_volumes;
	
	i32u cycles;
	i32u * counts;
	
	friend class eng1_mm_tripos52_nbt_bp;
	friend class eng1_mm_default_nbt_bp;
	friend class eng1_sf;
	
	public:
	
	radial_density_function_evaluator(engine_bp *, i32s, f64, f64, f64 = -1.0, f64 = -1.0);
	~radial_density_function_evaluator(void);
	
	private:
	
	void ResetCounters(void);
	
	public:
	
	void PrintResults(ostream &);
	
	inline void AddCycle(void)
	{
		cycles++;
	}
	
	inline void AddValue(f64 p1)
	{
		if (p1 < graph_begin) return;
		if (p1 >= graph_end) return;
		
		i32s index = 0;
		while (index < classes)
		{
			if (p1 >= upper_limits[index]) index++;
			else break;
		}
		
		counts[index]++;
	}
};

/*################################################################################################*/

#endif	// ENGINE_H

// eof