OSDN Git Service

Copy/paste of molecules was broken when it had atoms with more than ATOMS_CONNECTS_LI...
[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_CONNECTS 12 */
29 #define ATOM_CONNECTS_LIMIT 6
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                 
42 /*  Anisotropic thermal parameter  */
43 typedef struct Aniso {
44         Double  bij[6];    /*  b11, b22, b33, b12, b13, b23 (ORTEP type 0) */
45         char has_bsig;     /*  Has sigma values?  */
46         Double  bsig[6];   /*  sigma values  */
47         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.  */
48 } Aniso;
49
50 /*  Symmetry operation  */
51 /*  If periodic box is defined, dx/dy/dz denote multiples of the axes of the periodic box.
52     Otherwise, dx/dy/dz denote offset to the x/y/z coordinates of the atoms.  */
53 typedef struct Symop {
54         signed int dx : 4;
55         signed int dy : 4;
56         signed int dz : 4;
57         unsigned int sym : 8;
58         unsigned int alive: 1;
59 } Symop;
60
61 /*  Exflags  */
62 enum {
63         kAtomHiddenFlag = 1
64 };
65
66 /*  Atom record  */
67 typedef struct Atom {
68         Int    segSeq;
69         char   segName[4];
70         Int    resSeq;
71         char   resName[4];
72         char   aname[4];
73         UInt   type;
74         Double  charge;
75         Double  weight;
76         char   element[4];
77         Int    atomicNumber;
78         Int    nconnects;   /*  Number of connections (= bonds)  */
79         union {
80                 Int *ptr;
81                 Int data[ATOM_CONNECTS_LIMIT];
82         } connects;  /*  If nconnects > ATOM_CONNECTS_LIMIT, memory is malloc()'ed; otherwise, data[] is used.  */
83 /*      Int    connects[ATOMS_MAX_CONNECTS]; */
84         Vector r;  /*  position  */
85         Vector v;  /*  velocity  */
86         Vector f;  /*  force  */
87         Vector sigma;   /*  For crystallographic data only; sigma for each crystallographic coordinates  */
88                                         /*  (Unlike r, these are not converted to the cartesian system)  */
89         Double  occupancy;
90         Double  tempFactor;
91         Aniso  *aniso;
92         Int    intCharge;
93         Int    exflags;
94         Int    nframes;  /*  Multiple frames  */
95         Vector *frames;
96         Symop  symop;    /*  For symmetry-expanded atom  */
97         Int    symbase;  /*  The index of original atom for symmetry-expansion  */
98         Int    labelid;  /*  The label ID; 0 for no label  */
99         short  wrap_dx, wrap_dy, wrap_dz; /*  Calculated by md_wrap_coordinates; used only in wrapped output.  */
100         Double fix_force; /*  0: no fix, >0: fix at fix_pos with harmonic potential, <0: fix at fix_pos without force  */
101         Vector fix_pos;
102         Byte   mm_exclude;        /*  If nonzero, then this atom is excluded from MM/MD calculations  */
103         Byte   periodic_exclude;  /*  If nonzero, then this atom is excluded from periodic calculations  */
104 } Atom;
105
106 extern Int gSizeOfAtomRecord;
107
108 #define ATOM_AT_INDEX(p, i)  ((Atom *)((char *)(p) + (i) * gSizeOfAtomRecord))
109 #define ATOM_NEXT(p)         ((Atom *)((char *)(p) + gSizeOfAtomRecord))
110 #define ATOM_PREV(p)         ((Atom *)((char *)(p) - gSizeOfAtomRecord))
111 #define SYMOP_ALIVE(s) ((s.dx || s.dy || s.dz || s.sym) != 0)
112 #define SYMOP_EQUAL(s1, s2) (s1.dx == s2.dx && s1.dy == s2.dy && s1.dz == s2.dz && s1.sym == s2.sym)
113
114 /*  atom.connects is a union entry, including direct data for nconnects <= ATOM_CONNECTS_LIMIT
115     and malloc()'ed entry for nconnects > ATOM_CONNECTS_LIMIT. The following functions
116         automatically take care of the memory allocation/deallocation.  */
117 Int *AtomConnects(Atom *ap);
118 void AtomResizeConnects(Atom *ap, Int nconnects);
119 Int AtomConnectEntryAtIndex(Atom *ap, Int idx);
120 void AtomSetConnectEntry(Atom *ap, Int idx, Int connect);
121 void AtomInsertConnectEntry(Atom *ap, Int idx, Int connect);
122 void AtomDeleteConnectEntry(Atom *ap, Int idx);
123
124 /*  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. */
125 extern Atom *AtomDuplicate(Atom *dst, const Atom *src);
126         
127 /*  Duplicate an atom, except for the frame entry  */
128 extern Atom *AtomDuplicateNoFrame(Atom *dst, const Atom *src);
129         
130 /*  Clean the content of an atom record  */
131 extern void AtomClean(Atom *ap);
132
133 /*  MolEnumerable type code  */
134 enum {
135         kAtomKind = 0,
136         kBondKind = 1,
137         kAngleKind = 2,
138         kDihedralKind = 3,
139         kImproperKind = 4,
140         kResidueKind = 5,
141         kEndKind
142 };
143
144 /*  Enumerable class to access to atoms, bonds, etc.  */
145 typedef struct MolEnumerable {
146         struct Molecule *mol;
147         int    kind;
148 } MolEnumerable;
149
150 /*  Atom reference  */
151 typedef struct AtomRef {
152         struct Molecule *mol;
153         int idx;
154 } AtomRef;
155
156 /*  Crystallographic cell parameter (also used as periodic box in MD) */
157 typedef struct XtalCell {
158         Double  cell[6];     /*  a, b, c, alpha, beta, gamma (in degree)  */
159         Double  rcell[6];    /*  Reciprocal cell  */
160         Vector  axes[3];     /*  Cartesian unit vectors along the three axis  */
161         Vector  origin;      /*  Cartesian origin of the periodic box  */
162         char    flags[3];    /*  1 for periodic, 0 for non-periodic  */
163         char    has_sigma;   /*  Has sigma?  */
164         Transform tr;        /*  Crystal coord -> cartesian  */
165         Transform rtr;       /*  Cartesian -> crystal coord  */
166         Double  cellsigma[6];  /*  For crystallographic data; sigma for the cell parameters  */
167 } XtalCell;
168
169 /*  Periodic box parameter  */
170 #if 0
171 typedef struct PeriodicBox {
172         Vector  axes[3];     /*  Unit vectors along the three axis  */
173         Vector  origin;      /*  Origin of the periodic box  */
174         char    flags[3];    /*  1 for periodic, 0 for non-periodic  */
175         Transform tr;        /*  Internal coord -> cartesian  */
176         Transform rtr;       /*  Cartesian -> internal coord  */        
177 } PeriodicBox;
178 #endif
179
180 /*  Expanded atoms  */
181 typedef struct ExAtom {
182         Int    index;        /*  Base atom index  */
183         Vector dr;           /*  Translational offset  */
184         Int    symop;        /*  Symmetry operation  */
185         Int    labelid;      /*  Label ID; 0 for no label  */
186 } ExAtom;
187
188 /*  3-Dimensional distribution  */
189 typedef struct Cube {
190         Int idn;             /*  Integer identifier (such as MO number)  */
191         Vector origin;
192         Vector dx, dy, dz;
193         Int nx, ny, nz;
194         Double *dp;          /*  Value for point (ix, iy, iz) is in dp[(ix*ny+iy)*nz+iz]  */
195 } Cube;
196
197 /*  Gaussian orbital symmetry types  */
198 enum {
199         kGTOType_S,
200         kGTOType_SP,
201         kGTOType_P,
202         kGTOType_D,
203         kGTOType_D5,
204         kGTOtype_F,
205         kGTOType_F7,
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 /*      char   is_xtal_coord; *//*  True if the coordinates are measured in crystallographic units  */
272         Int    nsyms;        /*  Symmetry operations; syms are always described in crystallographic units (even when is_xtal_coord is false)  */
273         Transform *syms;
274 /*      PeriodicBox *box;    *//*  Periodic box  */
275         IntGroup *selection;
276         Int    nexatoms;
277         ExAtom *exatoms;
278         Int    nexbonds;
279         Int    *exbonds;     /*  The size of array is 2*nbonds; Atom index >= 0 : base atoms, < 0 : expanded atoms at index -exbonds[n]-1  */
280         Int    nframes;      /*  The number of frames (>= 1). This is a cached value, and should be
281                                                          recalculated from the atoms if it is -1  */
282         Int    cframe;       /*  The current frame number  */
283
284         Byte   useFlexibleCell;
285         Int    nframe_cells;
286         Vector *frame_cells; /*  The cell vectors for frames; (nframe_cells*4) array of Vectors  */
287
288         struct MainView *mview;  /*  Reference to the MainView object if present (no retain)  */
289         Int    modifyCount;  /*  Internal counter for modification. This value is not to be modified
290                                  manually; instead, call MoleculeIncrementModifyCount() whenever
291                                                      modification is done, which also takes care necessary notification
292                                                          to the other part of the application (system dependent)  */
293
294         struct MDArena *arena;  /*  Reference to the MDArena record during MM/MD run (no retain)  */
295
296         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) */
297
298         /*  Information from the dcd files  */
299         Int    startStep;     /*  the timestep for frame 0  */
300         Int    stepsPerFrame; /*  the number of timesteps between neighboring frames  */
301         Double psPerStep;     /*  picosecond per step  */
302
303         /*  Information for basis sets and MOs  */
304         BasisSet *bset;
305         
306         /*  Electrostatic potential  */
307         Int    nelpots;
308         Elpot  *elpots;
309
310         /*  Parameters specific for this molecule  */
311         struct Parameter *par;
312         
313         /*  Flag to request rebuilding MD internal information  */
314         Byte   needsMDRebuild;
315         
316         /*  Flag to clear selection of the parameter table  */
317         Byte   parameterTableSelectionNeedsClear;
318         
319         /*  Flag to request copying coordinates to MD arena  */
320         Byte   needsMDCopyCoordinates;
321
322         /*  Prohibit modification of the topology (to avoid interfering MD) */
323         Byte   noModifyTopology;
324         
325         /*  Flag to request aborting a subthread  */
326         Byte   requestAbortThread;
327
328         /*  Flag to signal that a subthread is terminated  */
329         Byte   threadTerminated;
330
331         /*  Mutex object. If non-NULL, it should be locked before modifying molecule  */
332         void *mutex;
333         
334         /*  Ruby pointer (see ruby_bind.c)  */
335         void *exmolobj;
336
337 } Molecule;
338
339 int strlen_limit(const char *s, int limit);
340
341 Molecule *MoleculeNew(void);
342 int MoleculeLoadFile(Molecule *mp, const char *fname, const char *ftype, char *errbuf, int errbufsize);
343 int MoleculeLoadPsfFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
344 int MoleculeLoadTepFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
345 int MoleculeLoadShelxFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
346 int MoleculeLoadGaussianFchkFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
347 int MoleculeLoadMbsfFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
348 Molecule *MoleculeNewWithName(const char *name);
349 Molecule *MoleculeInitWithAtoms(Molecule *mp, const Atom *atoms, int natoms);
350 Molecule *MoleculeInitWithMolecule(Molecule *mp2, const Molecule *mp);
351 void MoleculeSetName(Molecule *par, const char *name);
352 const char *MoleculeGetName(Molecule *mp);
353 void MoleculeSetPath(Molecule *mol, const char *fname);
354 const char *MoleculeGetPath(Molecule *mol);
355 Molecule *MoleculeWithName(const char *name);
356 Molecule *MoleculeRetain(Molecule *mp);
357 void MoleculeRelease(Molecule *mp);
358 extern void MoleculeReleaseExternalHook(Molecule *mol);
359 void MoleculeExchange(Molecule *mp1, Molecule *mp2);
360
361 int MoleculeAddGaussianOrbitalShell(Molecule *mol, Int sym, Int nprims, Int a_idx);
362 int MoleculeAddGaussianPrimitiveCoefficients(Molecule *mol, Double exponent, Double contraction, Double contraction_sp);
363 int MoleculeSetMOCoefficients(Molecule *mol, Int idx, Double energy, Int ncomps, Double *coeffs);
364 int MoleculeAllocateBasisSetRecord(Molecule *mol, Int rflag, Int ne_alpha, Int ne_beta);
365
366 void MoleculeIncrementModifyCount(Molecule *mp);
367 void MoleculeClearModifyCount(Molecule *mp);
368
369 MolEnumerable *MolEnumerableNew(Molecule *mol, int kind);
370 void MolEnumerableRelease(MolEnumerable *mseq);
371 AtomRef *AtomRefNew(Molecule *mol, int idx);
372 void AtomRefRelease(AtomRef *aref);
373
374 void MoleculeSetCell(Molecule *mp, Double a, Double b, Double c, Double alpha, Double beta, Double gamma, int convertCoordinates);
375 void MoleculeSetAniso(Molecule *mp, int n1, int type, Double x11, Double x22, Double x33, Double x12, Double x13, Double x23, const Double *sigmap);
376 void MoleculeSetAnisoBySymop(Molecule *mp, int idx);
377 int MoleculeSetPeriodicBox(Molecule *mp, const Vector *ax, const Vector *ay, const Vector *az, const Vector *ao, const char *periodic);
378
379 int MoleculeReadCoordinatesFromFile(Molecule *mp, const char *fname, const char *ftype, char *errbuf, int errbufsize);
380 int MoleculeReadCoordinatesFromPdbFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
381 int MoleculeReadCoordinatesFromDcdFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
382
383 int MoleculeReadExtendedInfo(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
384 int MoleculeWriteExtendedInfo(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
385
386 int MoleculeWriteToFile(Molecule *mp, const char *fname, const char *ftype, char *errbuf, int errbufsize);
387 int MoleculeWriteToPsfFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
388 int MoleculeWriteToPdbFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
389 int MoleculeWriteToDcdFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
390 int MoleculeWriteToTepFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize);
391 void MoleculeDump(Molecule *mol);
392
393 int MoleculePrepareMDArena(Molecule *mol, int check_only, char **retmsg);
394
395 char *MoleculeSerialize(Molecule *mp, Int *outLength, Int *timep);
396 Molecule *MoleculeDeserialize(const char *data, Int length, Int *timep);
397
398 void MoleculeCleanUpResidueTable(Molecule *mp);
399 int MoleculeChangeNumberOfResidues(Molecule *mp, int nresidues);
400 int MoleculeChangeResidueNumberWithArray(Molecule *mp, IntGroup *group, Int *resSeqs);
401 int MoleculeChangeResidueNumber(Molecule *mp, IntGroup *group, int resSeq);
402 int MoleculeOffsetResidueNumbers(Molecule *mp, IntGroup *group, int offset, int nresidues);
403 int MoleculeChangeResidueNames(Molecule *mp, int argc, Int *resSeqs, char *names);
404 int MoleculeMaximumResidueNumber(Molecule *mp, IntGroup *group);
405 int MoleculeMinimumResidueNumber(Molecule *mp, IntGroup *group);
406
407 int MoleculeCreateAnAtom(Molecule *mp, const Atom *ap, int pos);
408 int MoleculeMerge(Molecule *dst, Molecule *src, IntGroup *where, int resSeqOffset);
409 int MoleculeUnmerge(Molecule *src, Molecule **dstp, IntGroup *where, int resSeqOffset);
410 int MoleculeExtract(Molecule *src, Molecule **dstp, IntGroup *where, int dummyFlag);
411 int MoleculeAddBonds(Molecule *mp, Int nbonds, const Int *bonds);
412 int MoleculeDeleteBonds(Molecule *mp, Int nbonds, const Int *bonds);
413 int MoleculeAddAngles(Molecule *mp, const Int *angles, IntGroup *where);
414 int MoleculeDeleteAngles(Molecule *mp, Int *angles, IntGroup *where);
415 int MoleculeAddDihedrals(Molecule *mp, const Int *dihedrals, IntGroup *where);
416 int MoleculeDeleteDihedrals(Molecule *mp, Int *dihedrals, IntGroup *where);
417 int MoleculeAddImpropers(Molecule *mp, const Int *impropers, IntGroup *where);
418 int MoleculeDeleteImpropers(Molecule *mp, Int *impropers, IntGroup *where);
419 int MoleculeLookupBond(Molecule *mp, Int n1, Int n2);
420 int MoleculeLookupAngle(Molecule *mp, Int n1, Int n2, Int n3);
421 int MoleculeLookupDihedral(Molecule *mp, Int n1, Int n2, Int n3, Int n4);
422 int MoleculeLookupImproper(Molecule *mp, Int n1, Int n2, Int n3, Int n4);
423
424 /*
425 Int     MoleculeReplaceAllAngles(Molecule *mol, Int nangles, const Int *angles, Int **outAngles);
426 Int MoleculeReplaceAllDihedrals(Molecule *mol, Int ndihedrals, const Int *dihedrals, Int **outDihedrals);
427 Int MoleculeReplaceAllImpropers(Molecule *mol, Int nimpropers, const Int *impropers, Int **outImpropers);
428
429 Int MoleculeFindAllAngles(Molecule *mol, Int **outAngles);
430 Int MoleculeFindAllDihedrals(Molecule *mol, Int **outDihedrals);
431 Int MoleculeFindAllImpropers(Molecule *mol, Int **outImpropers);
432 */
433
434 Int MoleculeFindMissingAngles(Molecule *mol, Int **outAngles);
435 Int MoleculeFindMissingDihedrals(Molecule *mol, Int **outDihedrals);
436 Int MoleculeFindMissingImpropers(Molecule *mol, Int **outImpropers);
437         
438 IntGroup *MoleculeSearchBondsIncludingAtoms(Molecule *mp, IntGroup *atomgroup);
439 IntGroup *MoleculeSearchAnglesIncludingAtoms(Molecule *mp, IntGroup *atomgroup);
440 IntGroup *MoleculeSearchDihedralsIncludingAtoms(Molecule *mp, IntGroup *atomgroup);
441 IntGroup *MoleculeSearchImpropersIncludingAtoms(Molecule *mp, IntGroup *atomgroup);
442
443 IntGroup *MoleculeSearchBondsAcrossAtomGroup(Molecule *mp, IntGroup *atomgroup);
444
445 IntGroup *MoleculeSearchAnglesIncludingBond(Molecule *mp, int n1, int n2);
446 IntGroup *MoleculeSearchDihedralsIncludingBond(Molecule *mp, int n1, int n2);
447 IntGroup *MoleculeSearchImpropersIncludingBond(Molecule *mp, int n1, int n2);
448
449 int MoleculeLookupAtomInResidue(Molecule *mp, int n1, int resno);
450 int MoleculeAnalyzeAtomName(const char *s, char *resName, int *resSeq, char *atomName);
451 int MoleculeAtomIndexFromString(Molecule *mp, const char *s);
452
453 int MoleculeFindCloseAtoms(Molecule *mp, Int index, Double limit, Int *outNbonds, Int **outBonds, Int triangle);
454 int MoleculeGuessBonds(Molecule *mp, Double limit, Int *outNbonds, Int **outBonds);
455 int MoleculeAreAtomsConnected(Molecule *mp, int n1, int n2);
456 int MoleculeRebuildTablesFromConnects(Molecule *mp);
457
458 void MoleculeGetAtomName(Molecule *mp, int index, char *buf, int bufsize);
459
460 void MoleculeSetSelection(Molecule *mp, IntGroup *select);
461 IntGroup *MoleculeGetSelection(Molecule *mp);
462 void MoleculeSelectAtom(Molecule *mp, int n1, int extending);
463 void MoleculeUnselectAtom(Molecule *mp, int n1);
464 void MoleculeToggleSelectionOfAtom(Molecule *mp, int n1);
465 int MoleculeIsAtomSelected(Molecule *mp, int n1);
466 int MoleculeIsBondSelected(Molecule *mp, int n1, int n2);
467 IntGroup *MoleculeModifySelectionByRemovingAtoms(Molecule *mp, IntGroup *selection, IntGroup *remove);
468
469 int MoleculeGetTransformForSymop(Molecule *mp, Symop symop, Transform *tf, int is_cartesian);
470 int MoleculeGetSymopForTransform(Molecule *mp, const Transform tf, Symop *symop, int is_cartesian);
471
472 int MoleculeTransformBySymop(Molecule *mp, const Vector *vpin, Vector *vpout, Symop symop);
473 int MoleculeAddExpandedAtoms(Molecule *mp, Symop symop, IntGroup *group, Int *indices);
474 int MoleculeAmendBySymmetry(Molecule *mp, IntGroup *group, IntGroup **groupout, Vector **vpout);
475
476 int MoleculeShowAllAtoms(Molecule *mp);
477 int MoleculeShowReverse(Molecule *mp);
478 int MoleculeHideAtoms(Molecule *mp, IntGroup *ig);
479
480 int MoleculeRenumberAtoms(Molecule *mp, const Int *new2old, Int *old2new_out, Int isize);
481
482 void MoleculeTransform(Molecule *mp, Transform tr, IntGroup *group);
483 /*void MoleculeMove(Molecule *mp, Transform tr, IntGroup *group);*/
484 void MoleculeTranslate(Molecule *mp, const Vector *vp, IntGroup *group);
485 void MoleculeRotate(Molecule *mp, const Vector *axis, Double angle, const Vector *center, IntGroup *group);
486 int MoleculeCenterOfMass(Molecule *mp, Vector *center, IntGroup *group);
487 int MoleculeBounds(Molecule *mp, Vector *min, Vector *max, IntGroup *group);
488         
489 Int *MoleculeSearchEquivalentAtoms(Molecule *mol, IntGroup *ig);
490         
491 void MoleculeAddExpansion(Molecule *mp, Vector dr, Int symop, IntGroup *group, Double limit);
492 void MoleculeClearExpansion(Molecule *mp, IntGroup *group);
493 void MoleculeRemoveExpansion(Molecule *mp, Vector dr, Int symop, IntGroup *group);
494 void MoleculeAutoExpansion(Molecule *mp, const float *boxstart, const float *boxend, IntGroup *group, Double limit);
495
496 void MoleculeXtalToCartesian(Molecule *mp, Vector *dst, const Vector *src);
497 void MoleculeCartesianToXtal(Molecule *mp, Vector *dst, const Vector *src);
498 Double MoleculeMeasureBond(Molecule *mp, const Vector *vp1, const Vector *vp2);
499 Double MoleculeMeasureAngle(Molecule *mp, const Vector *vp1, const Vector *vp2, const Vector *vp3);
500 Double MoleculeMeasureDihedral(Molecule *mp, const Vector *vp1, const Vector *vp2, const Vector *vp3, const Vector *vp4);
501
502 IntGroup *MoleculeFragmentExcludingAtomGroup(Molecule *mp, int n1, IntGroup *exatoms);
503 IntGroup *MoleculeFragmentExcludingAtoms(Molecule *mp, int n1, int argc, int *argv);
504 IntGroup *MoleculeFragmentWithAtomGroups(Molecule *mp, IntGroup *inatoms, IntGroup *exatoms);
505 int MoleculeIsFragmentDetachable(Molecule *mp, IntGroup *group, int *n1, int *n2);
506 int MoleculeIsFragmentRotatable(Molecule *mp, IntGroup *group, int *n1, int *n2, IntGroup **rotGroup);
507
508 int MoleculeGetNumberOfFrames(Molecule *mp);
509 int MoleculeInsertFrames(Molecule *mp, IntGroup *group, const Vector *inFrame, const Vector *inFrameCell);
510 int MoleculeRemoveFrames(Molecule *mp, IntGroup *group, Vector *outFrame, Vector *outFrameCell);
511 int MoleculeSelectFrame(Molecule *mp, int frame, int copyback);
512 int MoleculeFlushFrames(Molecule *mp);
513
514 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);
515 int MoleculeGetDefaultMOGrid(Molecule *mp, Int npoints, Vector *op, Vector *xp, Vector *yp, Vector *zp, Int *nx, Int *ny, Int *nz);
516 const Cube *MoleculeGetCubeAtIndex(Molecule *mp, Int index);
517 int MoleculeLookUpCubeWithMONumber(Molecule *mp, Int mono);
518 int MoleculeClearCubeAtIndex(Molecule *mp, Int index);
519 int MoleculeOutputCube(Molecule *mp, Int index, const char *fname, const char *comment);
520
521 #define kMoleculePasteboardType "Molecule"
522 #define kParameterPasteboardType "Parameter"
523
524 STUB int MoleculeCallback_writeToPasteboard(const char *type, const void *data, int length);
525 STUB int MoleculeCallback_readFromPasteboard(const char *type, void **dptr, int *length);
526 STUB int MoleculeCallback_isDataInPasteboard(const char *type);
527
528 STUB Molecule *MoleculeCallback_openNewMolecule(const char *fname);
529 STUB void MoleculeCallback_notifyModification(Molecule *mp, int now_flag);
530 STUB Molecule *MoleculeCallback_currentMolecule(void);
531 STUB Molecule *MoleculeCallback_moleculeAtIndex(int idx);
532 STUB Molecule *MoleculeCallback_moleculeAtOrderedIndex(int idx);
533 STUB void MoleculeCallback_displayName(Molecule *mol, char *buf, int bufsize);
534 STUB void MoleculeCallback_pathName(Molecule *mol, char *buf, int bufsize);
535 STUB int MoleculeCallback_setDisplayName(Molecule *mol, const char *name);
536
537 STUB void MoleculeCallback_lockMutex(void *mutex);
538 STUB void MoleculeCallback_unlockMutex(void *mutex);
539 STUB void MoleculeCallback_cannotModifyMoleculeDuringMDError(Molecule *mol);
540
541 /*  This is also defined in Molby_extern.h, but it may be called from functions in Molecule.c  */
542 STUB int MyAppCallback_checkInterrupt(void);
543         
544 void MoleculeLock(Molecule *mol);
545 void MoleculeUnlock(Molecule *mol);
546
547 #if 0
548 #define __MoleculeLock(mol) MoleculeLock(mol)
549 #define __MoleculeUnlock(mol) MoleculeUnlock(mol)
550 #else
551 #define __MoleculeLock(mol)
552 #define __MoleculeUnlock(mol)
553 #endif
554         
555 #ifdef __cplusplus
556 }
557 #endif
558                 
559 #endif /* __Molecule_h__ */