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_ObjectMap
18 #define _H_ObjectMap
19
20 #include"os_python.h"
21
22 #include"CGO.h"
23 #include"PyMOLObject.h"
24 #include"Symmetry.h"
25 #include"Isosurf.h"
26 #include"vla.h"
27 #include"Result.h"
28
29 #define cMapSourceUndefined 0
30
31
32 /* in order to achieve better backwards compatibility
33 * with session files, future map source should be either:
34 * cMapSourceCrystallographic or cMapSourceGeneralPurpose */
35
36 #define cMapSourceCrystallographic 1
37 #define cMapSourceCCP4 2
38 #define cMapSourceGeneralPurpose 3
39 #define cMapSourceDesc 4
40 #define cMapSourceFLD 5
41 #define cMapSourceBRIX 6
42 #define cMapSourceGRD 7
43 #define cMapSourceChempyBrick 8
44 #define cMapSourceVMDPlugin 9
45 #define cMapSourceObsolete 10
46
47 struct ObjectMapState : public CObjectState {
48 int Active = false;
49 pymol::copyable_ptr<CSymmetry> Symmetry;
50 int Div[3]; /* NOTE: Div is only meaningful for maps defined relative to a unit cell */
51 int Min[3], Max[3]; /* valid min and max indices, required. */
52 int FDim[4]; /* Array dimensions with 3 in fourth slot, required */
53 int MapSource;
54 pymol::copyable_ptr<Isofield> Field;
55 float Corner[24];
56 std::vector<int> Dim; /* this field is redundant and should be eliminated -- if exists, must match FDim */
57 std::vector<float> Origin; /* Origin for non-xtal maps */
58 std::vector<float> Range; /* Range for non-xtal maps */
59 std::vector<float> Grid; /* Spacing for non-xtal maps */
60 float ExtentMin[3], ExtentMax[3];
61 float Mean, SD; /* -- JV for vol */
62 pymol::cache_ptr<CGO> shaderCGO;
63 /* below not stored */
64
65 int have_range = false;
66 float high_cutoff, low_cutoff;
67 ObjectMapState(PyMOLGlobals* G);
68 ObjectMapState(const ObjectMapState&);
69 ObjectMapState& operator=(const ObjectMapState&);
70 };
71
72 struct ObjectMap : public CObject {
73 using StateT = ObjectMapState;
74
75 std::vector<ObjectMapState> State;
76 ObjectMap(PyMOLGlobals* G);
77
78 /// Typed version of getObjectState
getObjectMapStateObjectMap79 StateT* getObjectMapState(int state)
80 {
81 return static_cast<StateT*>(getObjectState(state));
82 }
getObjectMapStateObjectMap83 const StateT* getObjectMapState(int state) const
84 {
85 return static_cast<const StateT*>(getObjectState(state));
86 }
87
88 // virtual methods
89 void update() override;
90 void render(RenderInfo* info) override;
91 void invalidate(int rep, int level, int state) override;
92 int getNFrame() const override;
93 CObject* clone() const override;
94 CSymmetry const* getSymmetry(int state = 0) const override;
95 bool setSymmetry(CSymmetry const& symmetry, int state = 0) override;
96
97 protected:
98 CObjectState* _getObjectState(int state) override;
99 };
100
101 #define cObjectMap_OrthoMinMaxGrid 0
102
103 typedef struct ObjectMapDesc { /* information for creating a new map */
104 int mode;
105 float Grid[3];
106 int Dim[3];
107 float MinCorner[3], MaxCorner[3];
108 int init_mode; /* -1 = nothing
109 0 = zeros
110 1 = ones */
111 } ObjectMapDesc;
112
113
114 int ObjectMapNewCopy(PyMOLGlobals * G, const ObjectMap * src, ObjectMap ** result,
115 int source_state, int target_state);
116 ObjectMapState *ObjectMapNewStateFromDesc(PyMOLGlobals * G, ObjectMap * I,
117 ObjectMapDesc * md, int state, int quiet);
118 int ObjectMapStateGetExcludedStats(PyMOLGlobals * G, ObjectMapState * ms, float *vert_vla,
119 float beyond, float within, float *level);
120
121 int ObjectMapValidXtal(ObjectMap * I, int state);
122 int ObjectMapStateValidXtal(ObjectMapState * ms);
123
124 void ObjectMapStateClamp(ObjectMapState * I, float clamp_floor, float clamp_ceiling);
125
126 ObjectMap *ObjectMapLoadXPLOR(PyMOLGlobals * G, ObjectMap * obj, const char *fname,
127 int state, int is_file, int quiet);
128
129 ObjectMap *ObjectMapLoadCCP4(PyMOLGlobals * G, ObjectMap * obj, const char *fname,
130 int state, int is_string, int bytes, int quiet, int);
131
132 ObjectMap *ObjectMapLoadPHI(PyMOLGlobals * G, ObjectMap * obj, const char *fname, int state,
133 int is_string, int bytes, int quiet);
134
135 ObjectMap *ObjectMapLoadDXFile(PyMOLGlobals * G, ObjectMap * obj, const char *fname, int state,
136 int quiet);
137 ObjectMap *ObjectMapLoadFLDFile(PyMOLGlobals * G, ObjectMap * obj, const char *fname, int state,
138 int quiet);
139 ObjectMap *ObjectMapLoadBRIXFile(PyMOLGlobals * G, ObjectMap * obj, const char *fname,
140 int state, int quiet);
141 ObjectMap *ObjectMapLoadGRDFile(PyMOLGlobals * G, ObjectMap * obj, const char *fname, int state,
142 int quiet);
143 ObjectMap *ObjectMapLoadACNTFile(PyMOLGlobals * G, ObjectMap * obj, const char *fname,
144 int state, int quiet);
145
146 ObjectMap *ObjectMapLoadChemPyBrick(PyMOLGlobals * G, ObjectMap * I, PyObject * Map,
147 int state, int discrete, int quiet);
148 ObjectMap *ObjectMapLoadChemPyMap(PyMOLGlobals * G, ObjectMap * I, PyObject * Map,
149 int state, int discrete, int quiet);
150 pymol::Result<> ObjectMapDouble(ObjectMap * I, int state);
151 pymol::Result<> ObjectMapHalve(ObjectMap * I, int state, int smooth);
152 pymol::Result<> ObjectMapTrim(ObjectMap * I, int state, float *mn, float *mx, int quiet);
153 int ObjectMapSetBorder(ObjectMap * I, float level, int state);
154 int ObjectMapStateSetBorder(ObjectMapState * I, float level);
155 void ObjectMapStatePurge(PyMOLGlobals * G, ObjectMapState * I);
156 int ObjectMapStateInterpolate(ObjectMapState * ms, const float *array, float *result, int *flag,
157 int n);
158 int ObjectMapStateContainsPoint(ObjectMapState * ms, float *point);
159 ObjectMapState *ObjectMapStatePrime(ObjectMap * I, int state);
160 void ObjectMapUpdateExtents(ObjectMap * I);
161
162 #define ObjectMapStateGetActive(I, state) (I)->getObjectMapState(state)
163 #define ObjectMapGetState(I, state) (I)->getObjectMapState(state)
164
165 PyObject *ObjectMapAsPyList(ObjectMap * I);
166 int ObjectMapNewFromPyList(PyMOLGlobals * G, PyObject * list, ObjectMap ** result);
167
168 int ObjectMapInterpolate(ObjectMap * I, int state, const float *array, float *result, int *flag,
169 int n);
170
171 void ObjectMapRegeneratePoints(ObjectMap * om);
172 void ObjectMapStateRegeneratePoints(ObjectMapState * ms);
173 int ObjectMapStateGetDataRange(PyMOLGlobals * G, ObjectMapState * ms, float *min,
174 float *max);
175 int ObjectMapStateGetHistogram(PyMOLGlobals * G, ObjectMapState * ms,
176 int n_points, float limit, float *histogram,
177 float min_arg, float max_arg);
178
179 void ObjectMapDump(const ObjectMap* I, const char* fname, int state, int quiet);
180
181 ObjectMapState * getObjectMapState(PyMOLGlobals * G, const char * name, int state);
182
183 /*========================================================================*/
184 std::vector<char> ObjectMapStateToCCP4Str(const ObjectMapState * ms, int quiet, int);
185
186 template <typename T>
ObjectMapGetCCP4Str(PyMOLGlobals * G,const T * ptr,int state,int quiet,int format)187 std::vector<char> ObjectMapGetCCP4Str(PyMOLGlobals * G, const T * ptr, int state, int quiet, int format) {
188 return ObjectMapStateToCCP4Str(getObjectMapState(G, ptr, state), quiet, format);
189 }
190
191 #endif
192