OSDN Git Service

Ruby: Molecule#find_close_atoms is modified so that it can accept a Vector3D as the...
[molby/Molby.git] / MolLib / Molecule.h
1 /*
2  *  Molecule.h
3  *
4  *  Created by Toshi Nagata on 06/03/11.
5  *  Copyright 2006-2008 Toshi Nagata. All rights reserved.
6  *
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation version 2 of the License.
10  
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 */
16
17 #ifndef __Molecule_h__
18 #define __Molecule_h__
19
20 #include "Types.h"
21 #include "Object.h"
22 #include "IntGroup.h"
23
24 #include <stdio.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29         
30 #define ATOMS_MAX_SYMMETRY 12
31 #define ATOMS_MAX_NUMBER 100000000  /*  Sufficiently large value  */
32
33 /*  Conversion between kcal/mol and internal energy unit (am*ang^2/fs^2, am = atomic mass) */
34 #define KCAL2INTERNAL (4.184e-4)
35 #define INTERNAL2KCAL (1.0/KCAL2INTERNAL)
36 #define J2INTERNAL (1e-4)
37 #define INTERNAL2J (1.0/J2INTERNAL)
38         
39 #define BOLTZMANN (8.31441e-3*J2INTERNAL)
40 #define PI 3.14159265358979
41 #define PI2R 0.564189583547756    /*  1.0/sqrt(PI)  */
42         
43 /*  Anisotropic thermal parameter  */
44 typedef struct Aniso {
45         Double  bij[6];    /*  b11, b22, b33, b12, b13, b23 (ORTEP type 0) */
46         char has_bsig;     /*  Has sigma values?  */
47         Double  bsig[6];   /*  sigma values  */
48         Mat33  pmat;      /*  A 3x3 matrix whose three column vectors are the principal axes of the ellipsoid. Note: If the B matrix is not positive definite, the axis length corresponding to the negative eigenvalue is replaced with 0.001.  */
49 } Aniso;
50
51 /*  Symmetry operation  */
52 /*  If periodic box is defined, dx/dy/dz denote multiples of the axes of the periodic box.
53     Otherwise, dx/dy/dz denote offset to the x/y/z coordinates of the atoms.  */
54 typedef struct Symop {
55         signed int dx : 4;
56         signed int dy : 4;
57         signed int dz : 4;
58         unsigned int sym : 8;
59         unsigned int alive: 1;
60 } Symop;
61
62 /*  Exflags  */
63 enum {
64         kAtomHiddenFlag = 1
65 };
66
67 /*  Atom connection record  */
68 /*  If nconnects <= ATOM_CONNECT_LIMIT, data[] field is used. Otherwise,
69     memory is allocated by malloc().  */
70 #define ATOM_CONNECT_LIMIT 6
71 typedef struct AtomConnect {
72         Int    count;  /*  Number of connections  */
73         union {
74                 Int *ptr;
75                 Int data[ATOM_CONNECT_LIMIT];
76         } u;
77 } AtomConnect;
78
79 typedef struct PiAnchor {
80         AtomConnect connect;
81         Int ncoeffs;
82         Double *coeffs;
83 } PiAnchor;
84
85 /*  Atom record  */
86 typedef struct Atom {
87         Int    segSeq;
88         char   segName[4];
89         Int    resSeq;
90         char   resName[4];
91         char   aname[4];
92         UInt   type;
93         Double  charge;
94         Double  weight;
95         char   element[4];
96         Int    atomicNumber;
97         AtomConnect connect;
98         Vector r;  /*  position  */
99         Vector v;  /*  velocity  */
100         Vector f;  /*  force  */
101         Vector sigma;   /*  For crystallographic data only; sigma for each crystallographic coordinates  */
102                                         /*  (Unlike r, these are not converted to the cartesian system)  */
103         Double  occupancy;
104         Double  tempFactor;
105         Aniso  *aniso;
106         Int    intCharge;
107         Int    exflags;
108         Int    nframes;  /*  Multiple frames  */
109         Vector *frames;
110         Symop  symop;    /*  For symmetry-expanded atom  */
111         Int    symbase;  /*  The index of original atom for symmetry-expansion  */
112         PiAnchor *anchor;  /*  Non-NULL if this atom is a pi-anchor  */
113         Int    labelid;  /*  The label ID; 0 for no label  */
114         short  wrap_dx, wrap_dy, wrap_dz; /*  Calculated by md_wrap_coordinates; used only in wrapped output.  */
115         Double fix_force; /*  0: no fix, >0: fix at fix_pos with harmonic potential, <0: fix at fix_pos without force  */
116         Vector fix_pos;
117         Byte   mm_exclude;        /*  If nonzero, then this atom is excluded from MM/MD calculations  */
118         Byte   periodic_exclude;  /*  If nonzero, then this atom is excluded from periodic calculations  */
119         char   uff_type[6]; /*  UFF type string  */
120 } Atom;
121
122 extern Int gSizeOfAtomRecord;
123
124 #define ATOM_AT_INDEX(p, i)  ((Atom *)((char *)(p) + (i) * gSizeOfAtomRecord))
125 #define ATOM_NEXT(p)         ((Atom *)((char *)(p) + gSizeOfAtomRecord))
126 #define ATOM_PREV(p)         ((Atom *)((char *)(p) - gSizeOfAtomRecord))
127 #define SYMOP_ALIVE(s) ((s.dx || s.dy || s.dz || s.sym) != 0)
128 #define SYMOP_EQUAL(s1, s2) (s1.dx == s2.dx && s1.dy == s2.dy && s1.dz == s2.dz && s1.sym == s2.sym)
129 #define SYMMETRY_AT_INDEX(p, i) (*((i) == 0 ? &gIdentityTransform : &p[i]))
130
131 /*  atom.connects is a union entry, including direct data for nconnects <= ATOM_CONNECT_LIMIT
132     and malloc()'ed entry for nconnects > ATOM_CONNECT_LIMIT. The following functions
133         automatically take care of the memory allocation/deallocation.  */
134 Int *AtomConnectData(AtomConnect *ac);
135 void AtomConnectResize(AtomConnect *ac, Int nconnects);
136 void AtomConnectInsertEntry(AtomConnect *ac, Int idx, Int connect);
137 void AtomConnectDeleteEntry(AtomConnect *ac, Int idx);
138
139 #define ATOM_CONNECT_PTR(ac) ((ac)->count > ATOM_CONNECT_LIMIT ? (ac)->u.ptr : (ac)->u.data)
140
141 /*  Duplicate an atom. If dst is non-NULL, *src is copied to *dst and dst is returned. If dst is NULL, a new atom is allocated by malloc() and that atom is returned. It is the called's responsibility to release the returned memory. */
142 extern Atom *AtomDuplicate(Atom *dst, const Atom *src);
143         
144 /*  Duplicate an atom, except for the frame entry  */
145 extern Atom *AtomDuplicateNoFrame(Atom *dst, const Atom *src);
146         
147 /*  Clean the content of an atom record  */
148 extern void AtomClean(Atom *ap);
149
150 /*  MolEnumerable type code  */
151 enum {
152         kAtomKind = 0,
153         kBondKind = 1,
154         kAngleKind = 2,
155         kDihedralKind = 3,
156         kImproperKind = 4,
157         kResidueKind = 5,
158         kEndKind
159 };
160
161 /*  Enumerable class to access to atoms, bonds, etc.  */
162 typedef struct MolEnumerable {
163         struct Molecule *mol;
164         int    kind;
165 } MolEnumerable;
166
167 /*  Atom reference  */
168 typedef struct AtomRef {
169         struct Molecule *mol;
170         int idx;
171 } AtomRef;
172
173 /*  Crystallographic cell parameter (also used as periodic box in MD) */
174 typedef struct XtalCell {
175         Double  cell[6];     /*  a, b, c, alpha, beta, gamma (in degree)  */
176         Double  rcell[6];    /*  Reciprocal cell  */
177         Vector  axes[3];     /*  Cartesian unit vectors along the three axis  */
178         Vector  origin;      /*  Cartesian origin of the periodic box  */
179         char    flags[3];    /*  1 for periodic, 0 for non-periodic  */
180         char    has_sigma;   /*  Has sigma?  */
181         Transform tr;        /*  Crystal coord -> cartesian  */
182         Transform rtr;       /*  Cartesian -> crystal coord  */
183         Double  cellsigma[6];  /*  For crystallographic data; sigma for the cell parameters  */
184 } XtalCell;
185
186 /*  3-Dimensional distribution  */
187 typedef struct Cube {
188         Int idn;             /*  Integer identifier (such as MO number)  */
189         Vector origin;
190         Vector dx, dy, dz;
191         Int nx, ny, nz;
192         Double *dp;          /*  Value for point (ix, iy, iz) is in dp[(ix*ny+iy)*nz+iz]  */
193 } Cube;
194
195 /*  Gaussian orbital symmetry types  */
196 enum {
197         kGTOType_S,
198         kGTOType_SP,
199         kGTOType_P,
200         kGTOType_D,
201         kGTOType_D5,
202         kGTOType_F,
203         kGTOType_F7,
204         kGTOType_G,
205         kGTOType_G9,
206         kGTOType_UU
207 };
208
209 /*  Exponent/coefficient info for a single gaussian primitive  */
210 typedef struct PrimInfo {
211         Double A;            /*  Exponent  */
212         Double C;            /*  Contraction coefficient  */
213         Double Csp;          /*  P(S=P) contraction coefficient  */
214 } PrimInfo;
215
216 /*  Gaussian orbital shell information  */
217 typedef struct ShellInfo {
218         signed char sym;     /*  Symmetry of the basis; S, P, ... */
219         signed char ncomp;   /*  Number of components (S: 1, P: 3, SP: 4, etc.)  */
220         signed char nprim;   /*  Number of primitives for this shell  */
221         Int p_idx;           /*  Index to the PrimInfo (exponent/coefficient) table  */
222         Int cn_idx;          /*  Index to the normalized (cached) contraction coefficient table  */
223         Int a_idx;           /*  Index to the atom which this primitive belongs to */
224         Int m_idx;           /*  Index to the MO matrix  */
225 } ShellInfo;
226
227 /*  Basis set and MO information  */
228 typedef struct BasisSet {
229         Int nshells;         /*  Number of gaussian orbital shells  */
230         ShellInfo *shells;   /*  Gaussian orbital shells  */
231         Int npriminfos;      /*  Size of primitive information table  */
232         PrimInfo *priminfos; /*  Primitive information table  */
233         Int ncns;            /*  Number of normalized (cached) contraction coefficient values  */
234         Double *cns;         /*  Normalized (cached) contraction coefficients; (up to 10 values for each primitive)  */
235         Int natoms;          /*  Number of atoms; separately cached here because MO info should be invariant during editing */
236         Vector *pos;         /*  Positions of atoms; the unit is bohr, not angstrom  */
237         Double *nuccharges;  /*  Nuclear charges (for ECP atoms)  */
238         Int ne_alpha, ne_beta;  /*  Number of alpha/beta electrons  */
239         Int rflag;           /*  0: UHF, 1: RHF, 2:ROHF  */
240         Int ncomps;          /*  Number of AO components; equal to sum of shells[i].ncomp  */
241         Int nmos;            /*  Number of MOs; equal to ncomps if close shell, ncomps*2 if open shell */
242         Double *mo;          /*  MO matrix (mo[i][j] represents the j-th AO coefficient for the i-th MO)  */
243         Double *moenergies;  /*  MO energies  */
244         Double *scfdensities; /*  SCF densities; lower triangle of a symmetric matrix (size nmos*(nmos+1)/2)  */
245         Int ncubes;          /*  Number of calculated MOs  */
246         Cube **cubes;        /*  Calculated MOs (an array of pointers to Cubes)  */
247 } BasisSet;
248
249 /*  Electrostatic potential  */
250 typedef struct Elpot {
251         Vector pos;
252         Double esp;
253 } Elpot;
254
255 /*  Molecule record  */
256 typedef struct Molecule {
257         Object base;
258         Int    natoms;
259         Atom   *atoms;
260         Int    nbonds;
261         Int    *bonds;       /*  The size of array is 2*nbonds  */
262         Int    nangles;
263         Int    *angles;      /*  The size of array is 3*nangles  */
264         Int    ndihedrals;
265         Int    *dihedrals;   /*  The size of array is 4*ndihedrals  */
266         Int    nimpropers;
267         Int    *impropers;   /*  The size of array is 4*nimpropers  */
268         Int    nresidues;    /*  Number of residues; maximum residue number + 1 (because residue 0 is 'undefined residue')  */
269         char   (*residues)[4];
270         XtalCell   *cell;
271         Int    nsyms;        /*  Symmetry operations; syms are always described in crystallographic units (even when the unit cell is not defined)  */
272         Transform *syms;
273
274         IntGroup *selection;
275         Int    nframes;      /*  The number of frames (>= 1). This is a cached value, and should be
276                                                          recalculated from the atoms if it is -1  */
277         Int    cframe;       /*  The current frame number  */
278
279 /*      Byte   useFlexibleCell;  *//*  Obsolete (since 0.6.5; unit cell is frame dependent in all cases)  */
280         Int    nframe_cells;
281         Vector *frame_cells; /*  The cell vectors for frames; (nframe_cells*4) array of Vectors  */
282
283         struct MainView *mview;  /*  Reference to the MainView object if present (no retain)  */
284         Int    modifyCount;  /*  Internal counter for modification. This value is not to be modified
285                                  manually; instead, call MoleculeIncrementModifyCount() whenever
286                                                      modification is done, which also takes care necessary notification
287                                                          to the other part of the application (system dependent)  */
288
289         struct MDArena *arena;  /*  Reference to the MDArena record during MM/MD run (no retain)  */
290
291         const char *path;     /*  The full path of the molecule, when this molecule is last saved to/loaded from file. Only used in the command-line version. (In GUI version, the path is obtained by the Document mechanism) */
292
293         /*  Information from the dcd files  */
294         Int    startStep;     /*  the timestep for frame 0  */
295         Int    stepsPerFrame; /*  the number of timesteps between neighboring frames  */
296         Double psPerStep;     /*  picosecond per step  */
297
298         /*  Information for basis sets and MOs  */
299         BasisSet *bset;
300         
301         /*  Electrostatic potential  */
302         Int    nelpots;
303         Elpot  *elpots;
304
305         /*  Parameters specific for this molecule  */
306         struct Parameter *par;
307         
308         /*  Bond order (not to be used in MM/MD, but may be necessary to hold this info)  */
309         Int    nbondOrders;
310         Double *bondOrders;
311
312         /*  Flag to request rebuilding MD internal information  */
313         Byte   needsMDRebuild;
314         
315         /*  Flag to clear selection of the parameter table  */
316         Byte   parameterTableSelectionNeedsClear;
317         
318         /*  Flag to request copying coordinates to MD arena  */
319         Byte   needsMDCopyCoordinates;
320
321         /*  Prohibit modification of the topology (to avoid interfering MD) */
322         Byte   noModifyTopology;
323         
324         /*  Flag to request aborting a subthread  */
325         Byte   requestAbortThread;
326
327         /*  Flag to signal that a subthread is terminated  */
328         Byte   threadTerminated;
329
330         /*  Mutex object. If non-NULL, it should be locked before modifying molecule  */
331         void *mutex;
332         
333         /*  Flag to prohibit modification from user interface  */
334         Byte   dontModifyFromGUI;
335
336         /*  Ruby pointer (see ruby_bind.c)  */
337         void *exmolobj;
338         Byte exmolobjProtected;
339
340 } Molecule;
341
342 int strlen_limit(const char *s, int limit);
343
344 Molecule *MoleculeNew(void);
345 int MoleculeLoadFile(Molecule *mp, const char *fname, const char *ftype, char **errbuf);
346 int MoleculeLoadPsfFile(Molecule *mp, const char *fname, char **errbuf);
347 int MoleculeLoadTepFile(Molecule *mp, const char *fname, char **errbuf);
348 int MoleculeLoadShelxFile(Molecule *mp, const char *fname, char **errbuf);
349 int MoleculeLoadGaussianFchkFile(Molecule *mp, const char *fname, char **errbuf);
350 int MoleculeLoadMbsfFile(Molecule *mp, const char *fname, char **errbuf);
351 Molecule *MoleculeNewWithName(const char *name);
352 Molecule *MoleculeInitWithAtoms(Molecule *mp, const Atom *atoms, int natoms);
353 Molecule *MoleculeInitWithMolecule(Molecule *mp2, Molecule *mp);
354 void MoleculeSetName(Molecule *par, const char *name);
355 const char *MoleculeGetName(Molecule *mp);
356 void MoleculeSetPath(Molecule *mol, const char *fname);
357 const char *MoleculeGetPath(Molecule *mol);
358 Molecule *MoleculeWithName(const char *name);
359 Molecule *MoleculeRetain(Molecule *mp);
360 void MoleculeRelease(Molecule *mp);
361 void MoleculeExchange(Molecule *mp1, Molecule *mp2);
362
363 int MoleculeAddGaussianOrbitalShell(Molecule *mol, Int sym, Int nprims, Int a_idx);
364 int MoleculeAddGaussianPrimitiveCoefficients(Molecule *mol, Double exponent, Double contraction, Double contraction_sp);
365 int MoleculeSetMOCoefficients(Molecule *mol, Int idx, Double energy, Int ncomps, Double *coeffs);
366 int MoleculeAllocateBasisSetRecord(Molecule *mol, Int rflag, Int ne_alpha, Int ne_beta);
367
368 void MoleculeIncrementModifyCount(Molecule *mp);
369 void MoleculeClearModifyCount(Molecule *mp);
370
371 MolEnumerable *MolEnumerableNew(Molecule *mol, int kind);
372 void MolEnumerableRelease(MolEnumerable *mseq);
373 AtomRef *AtomRefNew(Molecule *mol, int idx);
374 void AtomRefRelease(AtomRef *aref);
375
376 void MoleculeSetCell(Molecule *mp, Double a, Double b, Double c, Double alpha, Double beta, Double gamma, int convertCoordinates);
377 void MoleculeSetAniso(Molecule *mp, int n1, int type, Double x11, Double x22, Double x33, Double x12, Double x13, Double x23, const Double *sigmap);
378 void MoleculeSetAnisoBySymop(Molecule *mp, int idx);
379 int MoleculeSetPeriodicBox(Molecule *mp, const Vector *ax, const Vector *ay, const Vector *az, const Vector *ao, const char *periodic, int convertCoordinates);
380 int MoleculeCalculateCellFromAxes(XtalCell *cp, int calc_abc);
381
382 int MoleculeReadCoordinatesFromFile(Molecule *mp, const char *fname, const char *ftype, char **errbuf);
383 int MoleculeReadCoordinatesFromPdbFile(Molecule *mp, const char *fname, char **errbuf);
384 int MoleculeReadCoordinatesFromDcdFile(Molecule *mp, const char *fname, char **errbuf);
385
386 int MoleculeLoadGamessDatFile(Molecule *mol, const char *fname, char **errbuf);
387
388 int MoleculeReadExtendedInfo(Molecule *mp, const char *fname, char **errbuf);
389 int MoleculeWriteExtendedInfo(Molecule *mp, const char *fname, char **errbuf);
390
391 int MoleculeWriteToFile(Molecule *mp, const char *fname, const char *ftype, char **errbuf);
392 int MoleculeWriteToPsfFile(Molecule *mp, const char *fname, char **errbuf);
393 int MoleculeWriteToPdbFile(Molecule *mp, const char *fname, char **errbuf);
394 int MoleculeWriteToDcdFile(Molecule *mp, const char *fname, char **errbuf);
395 int MoleculeWriteToTepFile(Molecule *mp, const char *fname, char **errbuf);
396 int MoleculeWriteToMbsfFile(Molecule *mp, const char *fname, char **errbuf);
397 void MoleculeDump(Molecule *mol);
398
399 int MoleculePrepareMDArena(Molecule *mol, int check_only, char **retmsg);
400
401 char *MoleculeSerialize(Molecule *mp, Int *outLength, Int *timep);
402 Molecule *MoleculeDeserialize(const char *data, Int length, Int *timep);
403
404 void MoleculeCleanUpResidueTable(Molecule *mp);
405 int MoleculeChangeNumberOfResidues(Molecule *mp, int nresidues);
406 int MoleculeChangeResidueNumberWithArray(Molecule *mp, IntGroup *group, Int *resSeqs);
407 int MoleculeChangeResidueNumber(Molecule *mp, IntGroup *group, int resSeq);
408 int MoleculeOffsetResidueNumbers(Molecule *mp, IntGroup *group, int offset, int nresidues);
409 int MoleculeChangeResidueNames(Molecule *mp, int argc, Int *resSeqs, char *names);
410 int MoleculeMaximumResidueNumber(Molecule *mp, IntGroup *group);
411 int MoleculeMinimumResidueNumber(Molecule *mp, IntGroup *group);
412
413 struct MolAction;
414 #if defined(DEBUG)
415         int MoleculeCheckSanity(Molecule *mp);
416 #else
417 #define MoleculeCheckSanity(mp)
418 #endif
419
420 int MoleculeCreateAnAtom(Molecule *mp, const Atom *ap, int pos);
421 int MoleculeMerge(Molecule *dst, Molecule *src, IntGroup *where, int resSeqOffset, Int *nactions, struct MolAction ***actions, Int forUndo);
422 int MoleculeUnmerge(Molecule *src, Molecule **dstp, IntGroup *where, int resSeqOffset, Int *nactions, struct MolAction ***actions, Int forUndo);
423 int MoleculeExtract(Molecule *src, Molecule **dstp, IntGroup *where, int dummyFlag);
424 int MoleculeAddBonds(Molecule *mp, Int nbonds, const Int *bonds, IntGroup *where, Int autoGenerate);
425 int MoleculeDeleteBonds(Molecule *mp, Int *bonds, IntGroup *where, Int **outRemoved, IntGroup **outRemovedPos);
426 int MoleculeAssignBondOrders(Molecule *mp, const Double *orders, IntGroup *where);
427 int MoleculeGetBondOrders(Molecule *mp, Double *outOrders, IntGroup *where);
428 int MoleculeAddAngles(Molecule *mp, const Int *angles, IntGroup *where);
429 int MoleculeDeleteAngles(Molecule *mp, Int *angles, IntGroup *where);
430 int MoleculeAddDihedrals(Molecule *mp, const Int *dihedrals, IntGroup *where);
431 int MoleculeDeleteDihedrals(Molecule *mp, Int *dihedrals, IntGroup *where);
432 int MoleculeAddImpropers(Molecule *mp, const Int *impropers, IntGroup *where);
433 int MoleculeDeleteImpropers(Molecule *mp, Int *impropers, IntGroup *where);
434 int MoleculeLookupBond(Molecule *mp, Int n1, Int n2);
435 int MoleculeLookupAngle(Molecule *mp, Int n1, Int n2, Int n3);
436 int MoleculeLookupDihedral(Molecule *mp, Int n1, Int n2, Int n3, Int n4);
437 int MoleculeLookupImproper(Molecule *mp, Int n1, Int n2, Int n3, Int n4);
438
439 /*
440 Int     MoleculeReplaceAllAngles(Molecule *mol, Int nangles, const Int *angles, Int **outAngles);
441 Int MoleculeReplaceAllDihedrals(Molecule *mol, Int ndihedrals, const Int *dihedrals, Int **outDihedrals);
442 Int MoleculeReplaceAllImpropers(Molecule *mol, Int nimpropers, const Int *impropers, Int **outImpropers);
443
444 Int MoleculeFindAllAngles(Molecule *mol, Int **outAngles);
445 Int MoleculeFindAllDihedrals(Molecule *mol, Int **outDihedrals);
446 Int MoleculeFindAllImpropers(Molecule *mol, Int **outImpropers);
447 */
448
449 Int MoleculeFindMissingAngles(Molecule *mol, Int **outAngles);
450 Int MoleculeFindMissingDihedrals(Molecule *mol, Int **outDihedrals);
451 Int MoleculeFindMissingImpropers(Molecule *mol, Int **outImpropers);
452         
453 IntGroup *MoleculeSearchBondsIncludingAtoms(Molecule *mp, IntGroup *atomgroup);
454 IntGroup *MoleculeSearchAnglesIncludingAtoms(Molecule *mp, IntGroup *atomgroup);
455 IntGroup *MoleculeSearchDihedralsIncludingAtoms(Molecule *mp, IntGroup *atomgroup);
456 IntGroup *MoleculeSearchImpropersIncludingAtoms(Molecule *mp, IntGroup *atomgroup);
457
458 IntGroup *MoleculeSearchBondsAcrossAtomGroup(Molecule *mp, IntGroup *atomgroup);
459
460 IntGroup *MoleculeSearchAnglesIncludingBond(Molecule *mp, int n1, int n2);
461 IntGroup *MoleculeSearchDihedralsIncludingBond(Molecule *mp, int n1, int n2);
462 IntGroup *MoleculeSearchImpropersIncludingBond(Molecule *mp, int n1, int n2);
463
464 int MoleculeLookupAtomInResidue(Molecule *mp, int n1, int resno);
465 int MoleculeAnalyzeAtomName(const char *s, char *resName, int *resSeq, char *atomName);
466 int MoleculeAtomIndexFromString(Molecule *mp, const char *s);
467
468 int MoleculeFindCloseAtoms(Molecule *mp, const Vector *vp, Double radius, Double limit, Int *outNbonds, Int **outBonds, Int triangle);
469 int MoleculeGuessBonds(Molecule *mp, Double limit, Int *outNbonds, Int **outBonds);
470 int MoleculeRebuildTablesFromConnects(Molecule *mp);
471 int MoleculeAreAtomsConnected(Molecule *mol, int idx1, int idx2);
472         
473 void MoleculeGetAtomName(Molecule *mp, int index, char *buf, int bufsize);
474
475 void MoleculeSetSelection(Molecule *mp, IntGroup *select);
476 IntGroup *MoleculeGetSelection(Molecule *mp);
477 void MoleculeSelectAtom(Molecule *mp, int n1, int extending);
478 void MoleculeUnselectAtom(Molecule *mp, int n1);
479 void MoleculeToggleSelectionOfAtom(Molecule *mp, int n1);
480 int MoleculeIsAtomSelected(Molecule *mp, int n1);
481 int MoleculeIsBondSelected(Molecule *mp, int n1, int n2);
482 IntGroup *MoleculeModifySelectionByRemovingAtoms(Molecule *mp, IntGroup *selection, IntGroup *remove);
483
484 int MoleculeGetTransformForSymop(Molecule *mp, Symop symop, Transform *tf, int is_cartesian);
485 int MoleculeGetSymopForTransform(Molecule *mp, const Transform tf, Symop *symop, int is_cartesian);
486
487 int MoleculeTransformBySymop(Molecule *mp, const Vector *vpin, Vector *vpout, Symop symop);
488 int MoleculeAddExpandedAtoms(Molecule *mp, Symop symop, IntGroup *group, Int *indices, Int allowOverlap);
489 int MoleculeAmendBySymmetry(Molecule *mp, IntGroup *group, IntGroup **groupout, Vector **vpout);
490
491 int MoleculeShowAllAtoms(Molecule *mp);
492 int MoleculeShowReverse(Molecule *mp);
493 int MoleculeHideAtoms(Molecule *mp, IntGroup *ig);
494
495 int MoleculeRenumberAtoms(Molecule *mp, const Int *new2old, Int *old2new_out, Int isize);
496
497 void MoleculeTransform(Molecule *mp, Transform tr, IntGroup *group);
498 /*void MoleculeMove(Molecule *mp, Transform tr, IntGroup *group);*/
499 void MoleculeTranslate(Molecule *mp, const Vector *vp, IntGroup *group);
500 void MoleculeRotate(Molecule *mp, const Vector *axis, Double angle, const Vector *center, IntGroup *group);
501 int MoleculeCenterOfMass(Molecule *mp, Vector *center, IntGroup *group);
502 int MoleculeBounds(Molecule *mp, Vector *min, Vector *max, IntGroup *group);
503         
504 Int *MoleculeSearchEquivalentAtoms(Molecule *mol, IntGroup *ig);
505         
506 void MoleculeAddExpansion(Molecule *mp, Vector dr, Int symop, IntGroup *group, Double limit);
507 void MoleculeClearExpansion(Molecule *mp, IntGroup *group);
508 void MoleculeRemoveExpansion(Molecule *mp, Vector dr, Int symop, IntGroup *group);
509 void MoleculeAutoExpansion(Molecule *mp, const float *boxstart, const float *boxend, IntGroup *group, Double limit);
510
511 void MoleculeXtalToCartesian(Molecule *mp, Vector *dst, const Vector *src);
512 void MoleculeCartesianToXtal(Molecule *mp, Vector *dst, const Vector *src);
513 Double MoleculeMeasureBond(Molecule *mp, const Vector *vp1, const Vector *vp2);
514 Double MoleculeMeasureAngle(Molecule *mp, const Vector *vp1, const Vector *vp2, const Vector *vp3);
515 Double MoleculeMeasureDihedral(Molecule *mp, const Vector *vp1, const Vector *vp2, const Vector *vp3, const Vector *vp4);
516
517 IntGroup *MoleculeFragmentExcludingAtomGroup(Molecule *mp, int n1, IntGroup *exatoms);
518 IntGroup *MoleculeFragmentExcludingAtoms(Molecule *mp, int n1, int argc, int *argv);
519 IntGroup *MoleculeFragmentWithAtomGroups(Molecule *mp, IntGroup *inatoms, IntGroup *exatoms);
520 int MoleculeIsFragmentDetachable(Molecule *mp, IntGroup *group, int *n1, int *n2);
521 int MoleculeIsFragmentRotatable(Molecule *mp, IntGroup *group, int *n1, int *n2, IntGroup **rotGroup);
522
523 int MoleculeGetNumberOfFrames(Molecule *mp);
524 int MoleculeInsertFrames(Molecule *mp, IntGroup *group, const Vector *inFrame, const Vector *inFrameCell);
525 int MoleculeRemoveFrames(Molecule *mp, IntGroup *group, Vector *outFrame, Vector *outFrameCell);
526 int MoleculeSelectFrame(Molecule *mp, int frame, int copyback);
527 int MoleculeFlushFrames(Molecule *mp);
528
529 void MoleculeUpdatePiAnchorPositions(Molecule *mol);
530 void MoleculeCalculatePiAnchorPosition(Molecule *mol, int idx);
531 int MoleculeSetPiAnchorList(Molecule *mol, Int idx, Int nentries, Int *entries, Double *weights, Int *nUndoActions, struct MolAction ***undoActions);
532         
533 int MoleculeCalcMO(Molecule *mp, Int mono, const Vector *op, const Vector *dxp, const Vector *dyp, const Vector *dzp, Int nx, Int ny, Int nz, int (*callback)(double progress, void *ref), void *ref);
534 int MoleculeGetDefaultMOGrid(Molecule *mp, Int npoints, Vector *op, Vector *xp, Vector *yp, Vector *zp, Int *nx, Int *ny, Int *nz);
535 const Cube *MoleculeGetCubeAtIndex(Molecule *mp, Int index);
536 int MoleculeLookUpCubeWithMONumber(Molecule *mp, Int mono);
537 int MoleculeClearCubeAtIndex(Molecule *mp, Int index);
538 int MoleculeOutputCube(Molecule *mp, Int index, const char *fname, const char *comment);
539
540 /*#define kMoleculePasteboardType "Molecule"
541 #define kParameterPasteboardType "Parameter" */
542 extern char *gMoleculePasteboardType;
543 extern char *gParameterPasteboardType;
544 extern char *gLoadSaveErrorMessage;
545         
546 STUB void MoleculeRetainExternalObj(Molecule *mol);
547 STUB void MoleculeReleaseExternalObj(Molecule *mol);
548
549 STUB int MoleculeCallback_writeToPasteboard(const char *type, const void *data, int length);
550 STUB int MoleculeCallback_readFromPasteboard(const char *type, void **dptr, int *length);
551 STUB int MoleculeCallback_isDataInPasteboard(const char *type);
552
553 STUB Molecule *MoleculeCallback_openNewMolecule(const char *fname);
554 STUB void MoleculeCallback_notifyModification(Molecule *mp, int now_flag);
555 STUB Molecule *MoleculeCallback_currentMolecule(void);
556 STUB Molecule *MoleculeCallback_moleculeAtIndex(int idx);
557 STUB Molecule *MoleculeCallback_moleculeAtOrderedIndex(int idx);
558 STUB void MoleculeCallback_displayName(Molecule *mol, char *buf, int bufsize);
559 STUB void MoleculeCallback_pathName(Molecule *mol, char *buf, int bufsize);
560 STUB int MoleculeCallback_setDisplayName(Molecule *mol, const char *name);
561
562 STUB void MoleculeCallback_lockMutex(void *mutex);
563 STUB void MoleculeCallback_unlockMutex(void *mutex);
564 STUB void MoleculeCallback_disableModificationFromGUI(Molecule *mol);
565 STUB void MoleculeCallback_enableModificationFromGUI(Molecule *mol);
566         
567 STUB void MoleculeCallback_cannotModifyMoleculeDuringMDError(Molecule *mol);
568
569 STUB int MoleculeCallback_callSubProcessAsync(Molecule *mol, const char *cmd, int (*callback)(Molecule *, int), int (*timerCallback)(Molecule *, int), FILE *output, FILE *errout);
570
571 /*  This is also defined in Molby_extern.h, but it may be called from functions in Molecule.c  */
572 STUB int MyAppCallback_checkInterrupt(void);
573         
574 void MoleculeLock(Molecule *mol);
575 void MoleculeUnlock(Molecule *mol);
576
577 #if 0
578 #define __MoleculeLock(mol) MoleculeLock(mol)
579 #define __MoleculeUnlock(mol) MoleculeUnlock(mol)
580 #else
581 #define __MoleculeLock(mol)
582 #define __MoleculeUnlock(mol)
583 #endif
584         
585 #ifdef __cplusplus
586 }
587 #endif
588                 
589 #endif /* __Molecule_h__ */