OSDN Git Service

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