1 
2 /*
3 A* -------------------------------------------------------------------
4 B* This file contains source code for the PyMOL computer program
5 C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific.
6 D* -------------------------------------------------------------------
7 E* It is unlawful to modify or remove this copyright notice.
8 F* -------------------------------------------------------------------
9 G* Please see the accompanying LICENSE file for further information.
10 H* -------------------------------------------------------------------
11 I* Additional authors of this source file include:
12 -*
13 -*
14 -*
15 Z* -------------------------------------------------------------------
16 */
17 #ifndef _H_P
18 #define _H_P
19 
20 #include"os_python.h"
21 #include"AtomInfo.h"
22 #include"ObjectMolecule.h"
23 #include"CoordSet.h"
24 #include"PyMOLGlobals.h"
25 
26 #define cLockAPI 1
27 #define cLockInbox 2
28 #define cLockOutbox 3
29 
30 #define cPLog_pml_lf    0
31 #define cPLog_pml       1
32 #define cPLog_pym       2
33 #define cPLog_no_flush  3
34 
35 #define cPType_string          1
36 #define cPType_int             2
37 #define cPType_int_as_string   3
38 #define cPType_float           4
39 #define cPType_stereo          5
40 #define cPType_char_as_type    6
41 #define cPType_model           7
42 #define cPType_index           8
43 #define cPType_int_custom_type 9
44 #define cPType_xyz_float      10
45 #define cPType_settings       11
46 #define cPType_properties     12
47 #define cPType_state          13
48 #define cPType_schar          14
49 
50 #define NUM_ATOM_PROPERTIES    41
51 
52 #define cPRunType_alter          1
53 #define cPRunType_alter_state    2
54 #define cPRunType_label          3
55 
56 
57 int PLabelExprUsesVariable(PyMOLGlobals * G, const char *expr, const char *var);
58 
59 int PLabelAtomAlt(PyMOLGlobals * G, AtomInfoType * at, const char *model, const char *expr,
60                   int index);
61 
62 #ifdef _PYMOL_NOPY
63 
64 #define PRunStringInstance(G,x)
65 #define PRunStringModule(G,x)
66 
67 #define PAutoBlock(G) 1
68 #define PAutoUnblock(G,a)
69 
70 #define PBlock(G)
71 #define PUnblock(G)
72 
73 #define PBlockLegacy()
74 #define PUnblockLegacy()
75 
76 #define PLockAPIAsGlut(G,block_if_busy)
77 #define PUnlockAPIAsGlut(G)
78 #define PUnlockAPIAsGlutNoFlush(G)
79 
80 #define PLockAPI(G)
81 #define PUnlockAPI(G)
82 
83 #define PLockStatus(G)
84 #define PLockStatusAttempt()G 1
85 #define PUnlockStatusG()
86 
87 #define PBlockAndUnlockAPI(G)
88 #define PBlockAndUnlockAPI(G)
89 #define PLockAPIAndUnblock(G)
90 #define PTryLockAPIAndUnblock(G)
91 #define PFlush(G)
92 #define PFlushFast(G)
93 #define PParse(G,s)
94 #define PDo(G,s)
95 
96 #define PLog(G,a,b)
97 #define PLogFlush(G)
98 
99 #define PIsGlutThread() 1
100 #define PComplete(G,a,b) 0
101 
102 #define PPovrayRender(a,b,c,d,e,f,g) 0
103 
104 #define PTruthCallStr(a,b,c)
105 
106 #define PSleep(G,a)
107 #define PSleepWhileBusy(G,a)
108 #define PSleepUnlocked(G,a)
109 
110 #define PFree(G)
111 #define PInit(G,a)
112 #define PSetupEmbedded(G,a,b)
113 #define PConvertOptions(a,b)
114 #define PGetOptions(a)
115 
116 #define PAlterAtom(G,a,b,c,d,e,f,g,h) 0
117 #define PLabelAtom(G,a,b,c,d,e,f) 0
118 
119 #define PAlterAtomState(G,a,b,c,d,e,f,g,h,i,j,k) 0
120 
121 #else
122 
123 ov_status PCacheSet(PyMOLGlobals * G, PyObject * entry, PyObject * output);
124 ov_status PCacheGet(PyMOLGlobals * G,
125                     PyObject ** result_output, PyObject ** result_entry,
126                     PyObject * input);
127 
128 void PInit(PyMOLGlobals * G, int global_instance);
129 void PSetupEmbedded(PyMOLGlobals * G, int argc, char **argv);
130 
131 struct PyMOLOptionRec;
132 
133 void PConvertOptions(CPyMOLOptions * rec, PyObject * options);
134 void PGetOptions(CPyMOLOptions * rec);
135 
136 void PFree(PyMOLGlobals * G);
137 void PExit(PyMOLGlobals * G, int code);
138 void PParse(PyMOLGlobals * G, const char *str);       /* only accepts one command */
139 void PDo(PyMOLGlobals * G, const char *str);  /* accepts multple commands seperated by newlines */
140 
141 int PAlterAtom(PyMOLGlobals * G, ObjectMolecule *obj, CoordSet *cs, PyCodeObject *expr_co,
142                int read_only, int atm, PyObject * space);
143 int PLabelAtom(PyMOLGlobals * G, ObjectMolecule *obj, CoordSet *cs, PyCodeObject *expr_co, int atm);
144 int PAlterAtomState(PyMOLGlobals * G, PyCodeObject *expr_co, int read_only,
145                     ObjectMolecule *obj, CoordSet *cs, int atm, int idx,
146                     int state, PyObject * space);
147 
148 void PLog(PyMOLGlobals * G, const char *str, int lf);
149 void PLogFlush(PyMOLGlobals * G);
150 
151 void PSleep(PyMOLGlobals * G, int usec);
152 void PSleepWhileBusy(PyMOLGlobals * G, int usec);
153 void PSleepUnlocked(PyMOLGlobals * G, int usec);
154 
155 int PLockAPI(PyMOLGlobals * G, int block_if_busy);
156 void PUnlockAPI(PyMOLGlobals * G);
157 
158 int PLockAPIAsGlut(PyMOLGlobals * G, int block_if_busy);
159 void PUnlockAPIAsGlut(PyMOLGlobals * G);
160 void PUnlockAPIAsGlutNoFlush(PyMOLGlobals * G);
161 
162 void PLockStatus(PyMOLGlobals * G);
163 int PLockStatusAttempt(PyMOLGlobals * G);
164 void PUnlockStatus(PyMOLGlobals * G);
165 
166 void PBlock(PyMOLGlobals * G);
167 void PUnblock(PyMOLGlobals * G);
168 
169 void PBlockLegacy(void);
170 void PUnblockLegacy(void);
171 
172 int PAutoBlock(PyMOLGlobals * G);
173 void PAutoUnblock(PyMOLGlobals * G, int flag);
174 
175 void PBlockAndUnlockAPI(PyMOLGlobals * G);
176 void PLockAPIAndUnblock(PyMOLGlobals * G);
177 int PTryLockAPIAndUnblock(PyMOLGlobals * G);
178 
179 int PFlush(PyMOLGlobals * G);
180 int PFlushFast(PyMOLGlobals * G);
181 void PXDecRef(PyObject * obj);
182 PyObject *PXIncRef(PyObject * obj);
183 void PDefineFloat(PyMOLGlobals * G, const char *name, float value);
184 
185 void PRunStringModule(PyMOLGlobals * G, const char *str);
186 void PRunStringInstance(PyMOLGlobals * G, const char *str);
187 
188 void PDumpTraceback(PyObject * err);
189 void PDumpException(void);
190 
191 int PComplete(PyMOLGlobals * G, char *str, int buf_size);
192 
193 int PTruthCallStr(PyObject * object, const char *method, const char *argument);
194 int PTruthCallStr0(PyObject * object, const char *method);
195 int PTruthCallStr1i(PyObject * object, const char *method, int argument);
196 int PTruthCallStr1s(PyObject * object, const char *method, const char *argument);
197 int PTruthCallStr4i(PyObject * object, const char *method, int a1, int a2, int a3, int a4);
198 int PPovrayRender(PyMOLGlobals * G, const char *header, const char *inp, const char *file, int width,
199                   int height, int antialias);
200 int PIsGlutThread(void);
201 
202 PyObject *PGetFontDict(PyMOLGlobals * G, float size, int face, int style);
203 
204 typedef struct {
205   long id;
206   PyThreadState *state;
207 } SavedThreadRec;
208 
209 typedef struct {
210   PyObject_HEAD
211   //  PyObject* dict;
212   ObjectMolecule *obj;
213   CoordSet *cs;
214   AtomInfoType *atomInfo;
215   int atm;
216   int idx;
217   int state;
218   short read_only; // set for PLabelAtom
219   PyMOLGlobals * G;
220   PyObject *dict;
221   PyObject *settingWrapperObject;
222 #ifdef _PYMOL_IP_EXTRAS
223   PyObject *propertyWrapperObject;
224 #endif
225 } WrapperObject;
226 
227 void WrapperObjectReset(WrapperObject *);
228 
229 typedef struct {
230   PyObject_HEAD
231   WrapperObject *wobj;
232 } SettingPropertyWrapperObject;
233 
234 /* instance-specific Python object, containers, closures, and threads */
235 
236 #define MAX_SAVED_THREAD ((PYMOL_MAX_THREADS)+3)
237 
238 struct _CP_inst {
239   /* instance-specific storage */
240 
241   PyObject *obj;
242   PyObject *dict;
243   PyObject *exec;
244   PyObject *cmd;
245   PyObject *parse;              /* parse closure */
246   PyObject *complete;           /* complete partial command / TAB action */
247   PyObject *cmd_do;
248   PyObject *colortype;          /* backwards compatible iterate/alter color type */
249 
250   PyObject *cache;
251 
252   /* locks and threads */
253 
254   PyObject *lock;               /* API locks */
255   PyObject *lock_attempt;
256   PyObject *unlock;
257 
258   PyObject *lock_api_status;        /* status locks */
259   PyObject *lock_api_glut;          /* GLUT locks */
260 
261   int glut_thread_keep_out;
262   SavedThreadRec savedThread[MAX_SAVED_THREAD];
263 };
264 
265 
266 /* PyObject *GetBondsDict(void); */
267 
268 
269 /* all of the following Python objects must be invariant global
270    modules & module dictionaries for the application */
271 
272 extern PyObject *P_menu;        /* used by Menu */
273 extern PyObject *P_xray;        /* used by Symmetry */
274 extern PyObject *P_chempy;      /* used by CoordSet and Selector for construction of models */
275 extern PyObject *P_models;      /* used by Selector for construction of models */
276 extern PyObject *P_setting;     /* used by Setting.c */
277 extern PyTypeObject *P_wrapper;     /* used by P.c for lazy-loading settings/properties/attributes */
278 extern PyObject *P_CmdException;    /* pymol.CmdException */
279 extern PyObject *P_QuietException;  /* pymol.parsing.CmdException */
280 
281 #endif
282 #endif
283