1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
|
/*
A* -------------------------------------------------------------------
B* This file contains source code for the PyMOL computer program
C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific.
D* -------------------------------------------------------------------
E* It is unlawful to modify or remove this copyright notice.
F* -------------------------------------------------------------------
G* Please see the accompanying LICENSE file for further information.
H* -------------------------------------------------------------------
I* Additional authors of this source file include:
-*
-*
-*
Z* -------------------------------------------------------------------
*/
#include"os_python.h"
#include"os_predef.h"
#include"os_std.h"
#include"Base.h"
#include"OOMac.h"
#include"MemoryDebug.h"
#include"Err.h"
#include"DistSet.h"
#include"Scene.h"
#include"Color.h"
#include"RepDistDash.h"
#include"RepDistLabel.h"
#include"RepAngle.h"
#include"RepDihedral.h"
#include"PConv.h"
#include"ObjectMolecule.h"
#include"ListMacros.h"
#include"Selector.h"
#include "PyMOL.h"
static void DistSetUpdate(DistSet * I, int state);
static void DistSetFree(DistSet * I);
static void DistSetInvalidateRep(DistSet * I, int type, int level);
int DistSetGetLabelVertex(DistSet * I, int at, float *v)
{
if((at >= 0) && (at < I->NLabel) && I->LabCoord) {
float *vv = I->LabCoord + 3 * at;
copy3f(vv, v);
return true;
}
return false;
}
int DistSetMoveLabel(DistSet * I, int at, float *v, int mode)
{
ObjectDist *obj;
int a1 = at;
int result = 0;
LabPosType *lp;
obj = I->Obj;
if(a1 >= 0) {
if(!I->LabPos)
I->LabPos = VLACalloc(LabPosType, I->NLabel);
if(I->LabPos) {
result = 1;
lp = I->LabPos + a1;
if(!lp->mode) {
float *lab_pos = SettingGet_3fv(obj->Obj.G, I->Setting, obj->Obj.Setting,
cSetting_label_position);
copy3f(lab_pos, lp->pos);
}
lp->mode = 1;
if(mode) {
add3f(v, lp->offset, lp->offset);
} else {
copy3f(v, lp->offset);
}
}
}
return (result);
}
/* -- JV */
int DistSetMoveWithObject(DistSet * I, struct ObjectMolecule *obj)
{
/* TODO:
* 3. Make this multi-threaded
*/
PyMOLGlobals * G = I->State.G;
int a, idx, rVal=0, passedNAtoms = 0, totalNAtoms = 0;
float *src, *dst;
CMeasureInfo * memb = NULL;
CoordSet * cs;
short update = 0;
PRINTFD(G, FB_DistSet)
" DistSet: adjusting distance vertex\n" ENDFD;
/* If the user doesn't provide the Object obj, we should consider
* looping over all atoms in Selector->Table instead of bailing */
if (!I || !obj) return 0;
DListIterate(I->MeasureInfo, memb, next){
if (memb && memb->obj==obj) {
totalNAtoms += obj->NAtom;
}
}
memb = NULL;
DListIterate(I->MeasureInfo, memb, next)
{
/* if this distance set belongs to this object */
PyMOL_SetProgress(G->PyMOL, PYMOL_PROGRESS_FAST, passedNAtoms, totalNAtoms);
if (memb && memb->obj==obj) {
for (a=0; a<obj->NAtom; a++ ) {
passedNAtoms++;
/* matched on OBJ above and now ATOM ID within the object */
if (obj->AtomInfo[a].id == memb->id) {
/* if the state we found in our record could be right */
if (memb->state < obj->NCSet) {
/* get the coordinate set for this state */
cs = obj->CSet[memb->state];
/* get proper index based on state and discrete flags */
if (obj->DiscreteFlag) {
if (cs==obj->DiscreteCSet[a]) {
idx = obj->DiscreteAtmToIdx[a];
} else {
idx = -1;
}
} else {
idx = cs->AtmToIdx[a];
}
/* given a valid index, update the coordinate, finally */
if (idx>=0) {
/* valid offset */
float * varDst = NULL;
if (memb->measureType==cRepDash && memb->offset < I->NIndex) {
varDst = I->Coord;
I->fInvalidateRep(I, cRepDash, cRepInvCoord);
update = 1;
} else if (memb->measureType==cRepAngle && memb->offset < I->NAngleIndex) {
varDst = I->AngleCoord;
I->fInvalidateRep(I, cRepAngle, cRepInvCoord);
update = 1;
} else if (memb->measureType==cRepDihedral && memb->offset < I->NDihedralIndex) {
varDst = I->DihedralCoord;
I->fInvalidateRep(I, cRepDihedral, cRepInvCoord);
update = 1;
}
/* update the coordinates */
if (varDst) {
src = cs->Coord + 3 * idx;
dst = varDst + 3 * memb->offset;
copy3f(src,dst);
/* no matter what, update labels */
I->fInvalidateRep(I, cRepLabel, cRepInvCoord);
rVal |= 1;
}
}
}
}
}
}
}
if (update){
/* We need to update these representations right away since this could be
called during the scene rendering loop, and update might not be called
on this object again. This is ok since update checks to see if the reps
exist, and if they already do, then the overhead is minimal, so multiple
calls to update won't normally happen, but when they do, it won't hurt. */
I->fUpdate(I, -1);
}
PRINTFD(G, FB_DistSet)
" DistSet: done updating distance set's vertex\n" ENDFD;
return rVal;
}
int DistSetFromPyList(PyMOLGlobals * G, PyObject * list, DistSet ** cs)
{
#ifdef _PYMOL_NOPY
return 0;
#else
DistSet *I = NULL;
int ok = true;
int ll = 0;
if(*cs) {
DistSetFree(*cs);
*cs = NULL;
}
if(list == Py_None) { /* allow None for CSet */
*cs = NULL;
} else {
if(ok)
I = DistSetNew(G);
if(ok)
ok = (I != NULL);
if(ok)
ok = (list != NULL);
if(ok)
ok = PyList_Check(list);
if(ok)
ll = PyList_Size(list);
/* TO SUPPORT BACKWARDS COMPATIBILITY...
Always check ll when adding new PyList_GetItem's */
if(ok)
ok = PConvPyIntToInt(PyList_GetItem(list, 0), &I->NIndex);
if(ok)
ok = PConvPyListToFloatVLANoneOkay(PyList_GetItem(list, 1), &I->Coord);
if(ok && (ll > 2)) { /* have angles and torsions too... */
if(ok)
ok = PConvPyListToFloatVLANoneOkay(PyList_GetItem(list, 2), &I->LabCoord);
if(ok)
ok = PConvPyIntToInt(PyList_GetItem(list, 3), &I->NAngleIndex);
if(ok)
ok = PConvPyListToFloatVLANoneOkay(PyList_GetItem(list, 4), &I->AngleCoord);
if(ok)
ok = PConvPyIntToInt(PyList_GetItem(list, 5), &I->NDihedralIndex);
if(ok)
ok = PConvPyListToFloatVLANoneOkay(PyList_GetItem(list, 6), &I->DihedralCoord);
}
if(ok && (ll > 7))
I->Setting = SettingNewFromPyList(G, PyList_GetItem(list, 7)); /* state settings */
if(ok && (ll > 8))
ok = PConvPyListToLabPosVLA(PyList_GetItem(list, 8), &I->LabPos);
if(!ok) {
if(I)
DistSetFree(I);
} else {
*cs = I;
}
}
return (ok);
#endif
}
PyObject *DistSetAsPyList(DistSet * I)
{
#ifdef _PYMOL_NOPY
return NULL;
#else
PyObject *result = NULL;
if(I) {
result = PyList_New(9);
PyList_SetItem(result, 0, PyInt_FromLong(I->NIndex));
PyList_SetItem(result, 1, PConvFloatArrayToPyListNullOkay(I->Coord, I->NIndex * 3));
PyList_SetItem(result, 2, PConvFloatArrayToPyListNullOkay(I->LabCoord, I->NLabel));
PyList_SetItem(result, 3, PyInt_FromLong(I->NAngleIndex));
PyList_SetItem(result, 4,
PConvFloatArrayToPyListNullOkay(I->AngleCoord, I->NAngleIndex * 3));
PyList_SetItem(result, 5, PyInt_FromLong(I->NDihedralIndex));
PyList_SetItem(result, 6,
PConvFloatArrayToPyListNullOkay(I->DihedralCoord,
I->NDihedralIndex * 3));
PyList_SetItem(result, 7, SettingAsPyList(I->Setting));
if(I->LabPos) {
PyList_SetItem(result, 8, PConvLabPosVLAToPyList(I->LabPos, VLAGetSize(I->LabPos)));
} else {
PyList_SetItem(result, 8, PConvAutoNone(NULL));
}
/* TODO setting ... */
}
return (PConvAutoNone(result));
#endif
}
/*========================================================================*/
int DistSetGetExtent(DistSet * I, float *mn, float *mx)
{
float *v;
int a;
int c;
v = I->Coord;
for(a = 0; a < I->NIndex; a++) {
min3f(v, mn, mn);
max3f(v, mx, mx);
v += 3;
}
v = I->AngleCoord;
c = I->NAngleIndex / 5;
for(a = 0; a < c; a++) {
min3f(v, mn, mn);
max3f(v, mx, mx);
v += 3;
min3f(v, mn, mn);
max3f(v, mx, mx);
v += 3;
min3f(v, mn, mn);
max3f(v, mx, mx);
v += 9;
}
v = I->DihedralCoord;
c = I->NDihedralIndex / 6;
for(a = 0; a < c; a++) {
min3f(v, mn, mn);
max3f(v, mx, mx);
v += 3;
min3f(v, mn, mn);
max3f(v, mx, mx);
v += 3;
min3f(v, mn, mn);
max3f(v, mx, mx);
v += 3;
min3f(v, mn, mn);
max3f(v, mx, mx);
v += 9;
}
return (I->NIndex + I->NAngleIndex + I->NDihedralIndex);
}
/*========================================================================*/
static void DistSetInvalidateRep(DistSet * I, int type, int level)
{
int a;
PRINTFD(I->State.G, FB_DistSet)
" DistSetInvalidateRep: entered.\n" ENDFD;
/* if representation type is specified, adjust it */
if(type >= 0) {
if(type < I->NRep) {
if(I->Rep[type]) {
SceneChanged(I->State.G);
I->Rep[type]->fFree(I->Rep[type]);
I->Rep[type] = NULL;
}
}
} else {
/* reset all representation types */
for(a = 0; a < I->NRep; a++) {
if(I->Rep[a]) {
SceneChanged(I->State.G);
switch (level) {
case cRepInvColor:
if(I->Rep[a]->fRecolor) {
I->Rep[a]->fInvalidate(I->Rep[a], (struct CoordSet *) I, level);
} else {
I->Rep[a]->fFree(I->Rep[a]);
I->Rep[a] = NULL;
}
break;
default:
I->Rep[a]->fFree(I->Rep[a]);
I->Rep[a] = NULL;
break;
}
}
}
}
}
/*========================================================================*/
static void DistSetUpdate(DistSet * I, int state)
{
/* status bar 0% */
OrthoBusyFast(I->State.G, 0, I->NRep);
if(!I->Rep[cRepDash]) {
/* query the dist set looking for the selected atoms for this distance,
* then update the *coords */
I->Rep[cRepDash] = RepDistDashNew(I,state);
SceneInvalidate(I->State.G);
}
if(!I->Rep[cRepLabel]) {
/* query the dist set looking for the selected atoms for this distance,
* then update the *coords */
I->Rep[cRepLabel] = RepDistLabelNew(I, state);
SceneInvalidate(I->State.G);
}
if(!I->Rep[cRepAngle]) {
/* query the angle set looking for the selected atoms for this distance,
* then update the *coords */
I->Rep[cRepAngle] = RepAngleNew(I, state);
SceneInvalidate(I->State.G);
}
if(!I->Rep[cRepDihedral]) {
/* query the dihedral set looking for the selected atoms for this distance,
* then update the *coords */
I->Rep[cRepDihedral] = RepDihedralNew(I, state);
SceneInvalidate(I->State.G);
}
/* status bar 100% */
OrthoBusyFast(I->State.G, 1, 1);
}
/*========================================================================*/
static void DistSetRender(DistSet * I, RenderInfo * info)
{
CRay *ray = info->ray;
int pass = info->pass;
Picking **pick = info->pick;
int float_labels = SettingGet_i(I->State.G,
I->Setting,
I->Obj->Obj.Setting,
cSetting_float_labels);
int a;
Rep *r;
for(a = 0; a < I->NRep; a++)
if(I->Rep[a])
if(I->Obj->Obj.RepVis[a]) {
r = I->Rep[a];
if(ray || pick) {
if(ray)
ray->fColor3fv(ray, ColorGet(I->State.G, I->Obj->Obj.Color));
r->fRender(r, info);
} else {
ObjectUseColor((CObject *) I->Obj);
switch (a) {
case cRepLabel:
if(float_labels) {
if(pass == -1)
r->fRender(r, info);
} else if(pass == 0)
r->fRender(r, info);
break;
default:
if(pass == 0) {
r->fRender(r, info);
}
break;
}
}
}
}
/*========================================================================*/
DistSet *DistSetNew(PyMOLGlobals * G)
{
int a;
OOAlloc(G, DistSet);
I->State.G = G;
I->State.Matrix = NULL;
I->fFree = DistSetFree;
I->fRender = DistSetRender;
I->fUpdate = DistSetUpdate;
I->fInvalidateRep = DistSetInvalidateRep;
I->NIndex = 0;
I->Coord = NULL;
I->Rep = VLAlloc(Rep *, cRepCnt);
I->NRep = cRepCnt;
I->Setting = NULL;
I->LabPos = NULL;
I->LabCoord = NULL;
I->AngleCoord = NULL;
I->NAngleIndex = 0;
I->DihedralCoord = NULL;
I->NDihedralIndex = 0;
I->NLabel = 0;
for(a = 0; a < I->NRep; a++)
I->Rep[a] = NULL;
DListInit(I->MeasureInfo, prev, next, CMeasureInfo);
return (I);
}
/*========================================================================*/
static void DistSetFree(DistSet * I)
{
int a;
CMeasureInfo * ptr, *target;
if(I) {
for(a = 0; a < I->NRep; a++)
if(I->Rep[a])
I->Rep[a]->fFree(I->Rep[a]);
VLAFreeP(I->AngleCoord);
VLAFreeP(I->DihedralCoord);
VLAFreeP(I->LabCoord);
VLAFreeP(I->LabPos);
VLAFreeP(I->Coord);
VLAFreeP(I->Rep);
if (I->MeasureInfo) {
ptr = I->MeasureInfo->next;
while(ptr != I->MeasureInfo) {
target = ptr;
ptr = ptr->next;
DListRemove(target,prev,next);
DListElemFree(target);
target = NULL;
}
}
/* need to find and decrement the number of dist sets on the objects */
SettingFreeP(I->Setting);
OOFreeP(I);
}
}
|