P.cpp (pymol-v1.8.6.0.tar.bz2) | : | P.cpp (pymol-v2.1.0.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 61 | skipping to change at line 61 | |||
#include"Ortho.h" | #include"Ortho.h" | |||
#include"Cmd.h" | #include"Cmd.h" | |||
#include"main.h" | #include"main.h" | |||
#include"AtomInfo.h" | #include"AtomInfo.h" | |||
#include"CoordSet.h" | #include"CoordSet.h" | |||
#include"Util.h" | #include"Util.h" | |||
#include"Executive.h" | #include"Executive.h" | |||
#include"PyMOLOptions.h" | #include"PyMOLOptions.h" | |||
#include"PyMOL.h" | #include"PyMOL.h" | |||
#include "Lex.h" | #include "Lex.h" | |||
#include "Seeker.h" | ||||
static int label_copy_text(char *dst, const char *src, int len, int max) | static int label_copy_text(char *dst, const char *src, int len, int max) | |||
{ | { | |||
dst += len; | dst += len; | |||
while(len < max) { | while(len < max) { | |||
if(!*src) | if(!*src) | |||
break; | break; | |||
*(dst++) = *(src++); | *(dst++) = *(src++); | |||
len++; | len++; | |||
} | } | |||
skipping to change at line 116 | skipping to change at line 117 | |||
if(p != *expr) | if(p != *expr) | |||
*expr = p; | *expr = p; | |||
else if(*p) | else if(*p) | |||
*expr = p + 1; /* always advance input by at least one characte r */ | *expr = p + 1; /* always advance input by at least one characte r */ | |||
/* let caller know whether we read anything */ | /* let caller know whether we read anything */ | |||
return (q != dst); | return (q != dst); | |||
} | } | |||
/* | ||||
* Get R/S label for SDF stereo enumeration | ||||
*/ | ||||
char convertStereoToChar(int stereo){ | ||||
switch (stereo){ | ||||
case 1: return 'S'; | ||||
case 2: return 'R'; | ||||
case 3: return '?'; | ||||
} | ||||
return '\0'; | ||||
} | ||||
/* | ||||
* Get SDF stereo enumeration for R/S label | ||||
*/ | ||||
int convertCharToStereo(char stereo){ | ||||
switch (stereo){ | ||||
case 'S': case 's': return 1; | ||||
case 'R': case 'r': return 2; | ||||
case '?': return 3; | ||||
} | ||||
return 0; | ||||
} | ||||
int PLabelExprUsesVariable(PyMOLGlobals * G, const char *expr, const char *var) | int PLabelExprUsesVariable(PyMOLGlobals * G, const char *expr, const char *var) | |||
{ | { | |||
char ch, quote = 0; | char ch, quote = 0; | |||
int escaped = false; | int escaped = false; | |||
while((ch = *(expr++))) { | while((ch = *(expr++))) { | |||
if(!quote) { | if(!quote) { | |||
if(ch == '\'') { | if(ch == '\'') { | |||
quote = ch; | quote = ch; | |||
} else if(ch == '"') { | } else if(ch == '"') { | |||
quote = ch; | quote = ch; | |||
skipping to change at line 270 | skipping to change at line 247 | |||
if(at->customType != cAtomInfoNoType) | if(at->customType != cAtomInfoNoType) | |||
sprintf(buffer, "%d", at->customType); | sprintf(buffer, "%d", at->customType); | |||
else { | else { | |||
strcpy(buffer, "?"); | strcpy(buffer, "?"); | |||
} | } | |||
} else if(!strcmp(tok, "partial_charge")) { | } else if(!strcmp(tok, "partial_charge")) { | |||
sprintf(buffer, "%1.3f", at->partialCharge); | sprintf(buffer, "%1.3f", at->partialCharge); | |||
} else if(!strcmp(tok, "formal_charge")) { | } else if(!strcmp(tok, "formal_charge")) { | |||
sprintf(buffer, "%d", at->formalCharge); | sprintf(buffer, "%d", at->formalCharge); | |||
} else if(!strcmp(tok, "stereo")) { | } else if(!strcmp(tok, "stereo")) { | |||
sprintf(buffer, "%c", convertStereoToChar(at->stereo)); | strcpy(buffer, AtomInfoGetStereoAsStr(at)); | |||
} else if(!strcmp(tok, "color")) { | } else if(!strcmp(tok, "color")) { | |||
sprintf(buffer, "%d", at->color); | sprintf(buffer, "%d", at->color); | |||
} else if(!strcmp(tok, "cartoon")) { | } else if(!strcmp(tok, "cartoon")) { | |||
sprintf(buffer, "%d", at->cartoon); | sprintf(buffer, "%d", at->cartoon); | |||
} else if(!strcmp(tok, "ID")) { | } else if(!strcmp(tok, "ID")) { | |||
sprintf(buffer, "%d", at->id); | sprintf(buffer, "%d", at->id); | |||
} else if(!strcmp(tok, "str")) { | } else if(!strcmp(tok, "str")) { | |||
/* nop */ | /* nop */ | |||
} else { | } else { | |||
tokresult = false; | tokresult = false; | |||
skipping to change at line 599 | skipping to change at line 576 | |||
static PyObject * pystr_HETATM = PyString_InternFromString("HETATM"); | static PyObject * pystr_HETATM = PyString_InternFromString("HETATM"); | |||
static PyObject * pystr_ATOM = PyString_InternFromString("ATOM"); | static PyObject * pystr_ATOM = PyString_InternFromString("ATOM"); | |||
static PyObject * pystr_QuestionMark = PyString_InternFromString("?"); | static PyObject * pystr_QuestionMark = PyString_InternFromString("?"); | |||
WrapperObject *wobj = (WrapperObject*)obj; | WrapperObject *wobj = (WrapperObject*)obj; | |||
if (!check_wrapper_scope(wobj)) | if (!check_wrapper_scope(wobj)) | |||
return NULL; | return NULL; | |||
char *aprop; | PyMOLGlobals * G = wobj->G; | |||
const char *aprop; | ||||
AtomPropertyInfo *ap; | AtomPropertyInfo *ap; | |||
PyObject *ret = NULL; | PyObject *ret = NULL; | |||
bool borrowed = false; | bool borrowed = false; | |||
PyObject *keyobj = PyObject_Str(key); | PyObject *keyobj = PyObject_Str(key); | |||
aprop = PyString_AS_STRING(keyobj); | aprop = PyString_AS_STRING(keyobj); | |||
ap = PyMOL_GetAtomPropertyInfo(wobj->G->PyMOL, aprop); | ap = PyMOL_GetAtomPropertyInfo(wobj->G->PyMOL, aprop); | |||
Py_DECREF(keyobj); | Py_DECREF(keyobj); | |||
if (ap){ | if (ap){ | |||
switch (ap->Ptype){ | switch (ap->Ptype){ | |||
case cPType_string: | case cPType_string: | |||
skipping to change at line 685 | skipping to change at line 663 | |||
break; | break; | |||
case cPType_settings: | case cPType_settings: | |||
ret = (PyObject*)wobj->G->P_inst->settingWrapperObject; | ret = (PyObject*)wobj->G->P_inst->settingWrapperObject; | |||
borrowed = true; | borrowed = true; | |||
break; | break; | |||
case cPType_properties: | case cPType_properties: | |||
PyErr_SetString(PyExc_NotImplementedError, | PyErr_SetString(PyExc_NotImplementedError, | |||
"'properties/p' not supported in Open-Source PyMOL"); | "'properties/p' not supported in Open-Source PyMOL"); | |||
break; | break; | |||
case cPType_state: | case cPType_state: | |||
{ | ret = PyInt_FromLong((long)wobj->state); | |||
if (wobj->idx >= 0){ | ||||
ret = PyInt_FromLong((long)wobj->state); | ||||
} else { | ||||
PyErr_SetString(PyExc_NameError, | ||||
"'state' only available in iterate_state and alter_state"); | ||||
} | ||||
} | ||||
break; | break; | |||
default: | default: | |||
switch (ap->id) { | switch (ap->id) { | |||
case ATOM_PROP_RESI: | case ATOM_PROP_RESI: | |||
{ | { | |||
char resi[8]; | char resi[8]; | |||
AtomResiFromResv(resi, sizeof(resi), wobj->atomInfo); | AtomResiFromResv(resi, sizeof(resi), wobj->atomInfo); | |||
ret = PyString_FromString(resi); | ret = PyString_FromString(resi); | |||
} | } | |||
break; | break; | |||
case ATOM_PROP_STEREO: | case ATOM_PROP_STEREO: | |||
{ | { | |||
char mmstereotype[] = {convertStereoToChar(wobj->atomInfo->stereo), '\ 0'}; | auto mmstereotype = AtomInfoGetStereoAsStr(wobj->atomInfo); | |||
ret = PyString_FromString(mmstereotype); | ret = PyString_FromString(mmstereotype); | |||
} | } | |||
break; | break; | |||
case ATOM_PROP_ONELETTER: | ||||
{ | ||||
const char * st = LexStr(G, wobj->atomInfo->resn); | ||||
char abbr[2] = {SeekerGetAbbr(G, st, 'O', 'X'), 0}; | ||||
ret = PyString_FromString(abbr); | ||||
} | ||||
break; | ||||
default: | default: | |||
PyErr_SetString(PyExc_SystemError, "unhandled atom property type"); | PyErr_SetString(PyExc_SystemError, "unhandled atom property type"); | |||
} | } | |||
} | } | |||
} else { | } else { | |||
/* if not an atom property, check if local variable in dict */ | /* if not an atom property, check if local variable in dict */ | |||
ret = PyDict_GetItem(wobj->dict, key); | ret = PyDict_GetItem(wobj->dict, key); | |||
borrowed = true; | if (ret) { | |||
borrowed = true; | ||||
} else { | ||||
PyErr_SetNone(PyExc_KeyError); | ||||
} | ||||
} | } | |||
if (borrowed) | if (borrowed) | |||
PXIncRef(ret); | PXIncRef(ret); | |||
return ret; | return ret; | |||
} | } | |||
/* | /* | |||
* iterate-family namespace implementation: assignment | * iterate-family namespace implementation: assignment | |||
* | * | |||
skipping to change at line 759 | skipping to change at line 741 | |||
return -1; | return -1; | |||
} | } | |||
// alter_state: must be setting x/y/z or flags | // alter_state: must be setting x/y/z or flags | |||
if (wobj->idx >= 0) { | if (wobj->idx >= 0) { | |||
if (ap->Ptype == cPType_xyz_float) { | if (ap->Ptype == cPType_xyz_float) { | |||
float * v = wobj->cs->coordPtr(wobj->idx) + ap->offset; | float * v = wobj->cs->coordPtr(wobj->idx) + ap->offset; | |||
PConvPyObjectToFloat(val, v); | PConvPyObjectToFloat(val, v); | |||
return 0; | return 0; | |||
} | } | |||
if (ap->id != ATOM_PROP_FLAGS) { | ||||
PyErr_SetString(PyExc_TypeError, | ||||
"only x/y/z/flags can be modified in alter_state"); | ||||
return -1; | ||||
} | ||||
} | } | |||
switch (ap->Ptype){ | switch (ap->Ptype){ | |||
case cPType_string: | case cPType_string: | |||
{ | { | |||
PyObject *valobj = PyObject_Str(val); | PyObject *valobj = PyObject_Str(val); | |||
char *valstr = PyString_AS_STRING(valobj); | const char *valstr = PyString_AS_STRING(valobj); | |||
char *dest = (char*)(((char*)wobj->atomInfo) + ap->offset); | char *dest = (char*)(((char*)wobj->atomInfo) + ap->offset); | |||
if (strlen(valstr) > ap->maxlen){ | if (strlen(valstr) > ap->maxlen){ | |||
strncpy(dest, valstr, ap->maxlen); | strncpy(dest, valstr, ap->maxlen); | |||
} else { | } else { | |||
strcpy(dest, valstr); | strcpy(dest, valstr); | |||
} | } | |||
Py_DECREF(valobj); | Py_DECREF(valobj); | |||
changed = true; | changed = true; | |||
} | } | |||
break; | break; | |||
skipping to change at line 809 | skipping to change at line 785 | |||
dest = (int*)(((char*)wobj->atomInfo) + ap->offset); | dest = (int*)(((char*)wobj->atomInfo) + ap->offset); | |||
*dest = valint; | *dest = valint; | |||
changed = true; | changed = true; | |||
} | } | |||
break; | break; | |||
case cPType_int_as_string: | case cPType_int_as_string: | |||
{ | { | |||
auto dest = reinterpret_cast<lexidx_t*> | auto dest = reinterpret_cast<lexidx_t*> | |||
(((char*)wobj->atomInfo) + ap->offset); | (((char*)wobj->atomInfo) + ap->offset); | |||
PyObject *valobj = PyObject_Str(val); | PyObject *valobj = PyObject_Str(val); | |||
char *valstr = PyString_AS_STRING(valobj); | const char *valstr = PyString_AS_STRING(valobj); | |||
LexDec(wobj->G, *dest); | LexDec(wobj->G, *dest); | |||
*dest = LexIdx(wobj->G, valstr); | *dest = LexIdx(wobj->G, valstr); | |||
Py_DECREF(valobj); | Py_DECREF(valobj); | |||
changed = true; | changed = true; | |||
} | } | |||
break; | break; | |||
case cPType_float: | case cPType_float: | |||
{ | { | |||
float *dest = (float*)(((char*)wobj->atomInfo) + ap->offset); | float *dest = (float*)(((char*)wobj->atomInfo) + ap->offset); | |||
changed = PConvPyObjectToFloat(val, dest); | changed = PConvPyObjectToFloat(val, dest); | |||
} | } | |||
break; | break; | |||
case cPType_char_as_type: | case cPType_char_as_type: | |||
{ | { | |||
PyObject *valobj = PyObject_Str(val); | PyObject *valobj = PyObject_Str(val); | |||
char *valstr = PyString_AS_STRING(valobj); | const char *valstr = PyString_AS_STRING(valobj); | |||
wobj->atomInfo->hetatm = ((valstr[0] == 'h') || (valstr[0] == 'H')); | wobj->atomInfo->hetatm = ((valstr[0] == 'h') || (valstr[0] == 'H')); | |||
Py_DECREF(valobj); | Py_DECREF(valobj); | |||
changed = true; | changed = true; | |||
} | } | |||
break; | break; | |||
case cPType_int_custom_type: | case cPType_int_custom_type: | |||
{ | { | |||
PyObject *valobj = PyObject_Str(val); | PyObject *valobj = PyObject_Str(val); | |||
char *valstr = PyString_AS_STRING(valobj); | const char *valstr = PyString_AS_STRING(valobj); | |||
int *dest = (int*)(((char*)wobj->atomInfo) + ap->offset); | int *dest = (int*)(((char*)wobj->atomInfo) + ap->offset); | |||
if (valstr[0] == '?'){ | if (valstr[0] == '?'){ | |||
*dest = cAtomInfoNoType; | *dest = cAtomInfoNoType; | |||
} else { | } else { | |||
int valint = PyInt_AS_LONG(val); | int valint = PyInt_AS_LONG(val); | |||
*dest = valint; | *dest = valint; | |||
} | } | |||
Py_DECREF(valobj); | Py_DECREF(valobj); | |||
changed = true; | changed = true; | |||
} | } | |||
skipping to change at line 865 | skipping to change at line 841 | |||
} else { | } else { | |||
PyObject *valobj = PyObject_Str(val); | PyObject *valobj = PyObject_Str(val); | |||
wobj->atomInfo->setResi(PyString_AS_STRING(valobj)); | wobj->atomInfo->setResi(PyString_AS_STRING(valobj)); | |||
Py_DECREF(valobj); | Py_DECREF(valobj); | |||
} | } | |||
break; | break; | |||
case ATOM_PROP_STEREO: | case ATOM_PROP_STEREO: | |||
{ | { | |||
PyObject *valobj = PyObject_Str(val); | PyObject *valobj = PyObject_Str(val); | |||
const char *valstr = PyString_AS_STRING(valobj); | const char *valstr = PyString_AS_STRING(valobj); | |||
wobj->atomInfo->stereo = convertCharToStereo(valstr[0]); | AtomInfoSetStereo(wobj->atomInfo, valstr); | |||
Py_DECREF(valobj); | Py_DECREF(valobj); | |||
} | } | |||
break; | break; | |||
default: | default: | |||
PyErr_Format(PyExc_TypeError, "'%s' is read-only", aprop); | PyErr_Format(PyExc_TypeError, "'%s' is read-only", aprop); | |||
return -1; | return -1; | |||
} | } | |||
} | } | |||
if (changed){ | if (changed){ | |||
switch (ap->id){ | switch (ap->id){ | |||
skipping to change at line 987 | skipping to change at line 963 | |||
} else { | } else { | |||
result = PYOBJECT_CALLMETHOD(P_vfont, "get_font", "fii", size, face, style); | result = PYOBJECT_CALLMETHOD(P_vfont, "get_font", "fii", size, face, style); | |||
} | } | |||
return (PConvAutoNone(result)); | return (PConvAutoNone(result)); | |||
} | } | |||
int PComplete(PyMOLGlobals * G, char *str, int buf_size) | int PComplete(PyMOLGlobals * G, char *str, int buf_size) | |||
{ | { | |||
int ret = false; | int ret = false; | |||
PyObject *result; | PyObject *result; | |||
char *st2; | const char *st2; | |||
PBlockAndUnlockAPI(G); | PBlockAndUnlockAPI(G); | |||
if(G->P_inst->complete) { | if(G->P_inst->complete) { | |||
result = PYOBJECT_CALLFUNCTION(G->P_inst->complete, "s", str); | result = PYOBJECT_CALLFUNCTION(G->P_inst->complete, "s", str); | |||
if(result) { | if(result) { | |||
if(PyString_Check(result)) { | if(PyString_Check(result)) { | |||
st2 = PyString_AsString(result); | st2 = PyString_AsString(result); | |||
UtilNCopy(str, st2, buf_size); | UtilNCopy(str, st2, buf_size); | |||
ret = true; | ret = true; | |||
} | } | |||
Py_DECREF(result); | Py_DECREF(result); | |||
skipping to change at line 1252 | skipping to change at line 1228 | |||
/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ | /* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ | |||
PBlockAndUnlockAPI(G); | PBlockAndUnlockAPI(G); | |||
PXDecRef(PYOBJECT_CALLFUNCTION(P_sleep, "f", usec / 1000000.0)); | PXDecRef(PYOBJECT_CALLFUNCTION(P_sleep, "f", usec / 1000000.0)); | |||
PLockAPIAndUnblock(G); | PLockAPIAndUnblock(G); | |||
/* END PROPRIETARY CODE SEGMENT */ | /* END PROPRIETARY CODE SEGMENT */ | |||
#endif | #endif | |||
} | } | |||
static PyObject *PCatchWrite(PyObject * self, PyObject * args); | static PyObject *PCatchWrite(PyObject * self, PyObject * args); | |||
static PyObject *PCatch_install(PyObject * self, PyObject * args); | ||||
void my_interrupt(int a) | void my_interrupt(int a) | |||
{ | { | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
void PDumpTraceback(PyObject * err) | void PDumpTraceback(PyObject * err) | |||
{ | { | |||
PYOBJECT_CALLMETHOD(P_traceback, "print_tb", "O", err); | PYOBJECT_CALLMETHOD(P_traceback, "print_tb", "O", err); | |||
} | } | |||
skipping to change at line 1298 | skipping to change at line 1275 | |||
PyErr_Print(); | PyErr_Print(); | |||
result = false; | result = false; | |||
} | } | |||
return result; | return result; | |||
} | } | |||
int PAlterAtom(PyMOLGlobals * G, | int PAlterAtom(PyMOLGlobals * G, | |||
ObjectMolecule *obj, CoordSet *cs, PyCodeObject *expr_co, int rea d_only, | ObjectMolecule *obj, CoordSet *cs, PyCodeObject *expr_co, int rea d_only, | |||
int atm, PyObject * space) | int atm, PyObject * space) | |||
{ | { | |||
int result = true; | int state = (obj->DiscreteFlag ? obj->AtomInfo[atm].discrete_state : 0) - 1; | |||
return PAlterAtomState(G, expr_co, read_only, obj, cs, atm, /* idx */ -1, stat | ||||
G->P_inst->wrapperObject->obj = obj; | e, space); | |||
G->P_inst->wrapperObject->cs = cs; | ||||
G->P_inst->wrapperObject->atomInfo = obj->AtomInfo + atm; | ||||
G->P_inst->wrapperObject->atm = atm; | ||||
G->P_inst->wrapperObject->idx = -1; | ||||
G->P_inst->wrapperObject->read_only = read_only; | ||||
G->P_inst->wrapperObject->state = -1; | ||||
PXDecRef(PyEval_EvalCode(expr_co, space, (PyObject*)G->P_inst->wrapperObject)) | ||||
; | ||||
WrapperObjectReset(G->P_inst->wrapperObject); | ||||
if(PyErr_Occurred()) { | ||||
PyErr_Print(); | ||||
result = false; | ||||
} | ||||
return result; | ||||
} | } | |||
/* | /* | |||
* String conversion which takes "label_digits" setting into account. | * String conversion which takes "label_digits" setting into account. | |||
*/ | */ | |||
static | static | |||
int PLabelPyObjectToStrMaxLen(PyMOLGlobals * G, PyObject * obj, char *buffer, in t maxlen) | int PLabelPyObjectToStrMaxLen(PyMOLGlobals * G, PyObject * obj, char *buffer, in t maxlen) | |||
{ | { | |||
if (obj && PyFloat_Check(obj)) { | if (obj && PyFloat_Check(obj)) { | |||
snprintf(buffer, maxlen + 1, "%.*f", | snprintf(buffer, maxlen + 1, "%.*f", | |||
skipping to change at line 1347 | skipping to change at line 1308 | |||
PyObject *resultPyObject; | PyObject *resultPyObject; | |||
OrthoLineType label; | OrthoLineType label; | |||
AtomInfoType * ai = obj->AtomInfo + atm; | AtomInfoType * ai = obj->AtomInfo + atm; | |||
G->P_inst->wrapperObject->obj = obj; | G->P_inst->wrapperObject->obj = obj; | |||
G->P_inst->wrapperObject->cs = cs; | G->P_inst->wrapperObject->cs = cs; | |||
G->P_inst->wrapperObject->atomInfo = ai; | G->P_inst->wrapperObject->atomInfo = ai; | |||
G->P_inst->wrapperObject->atm = atm; | G->P_inst->wrapperObject->atm = atm; | |||
G->P_inst->wrapperObject->idx = -1; | G->P_inst->wrapperObject->idx = -1; | |||
G->P_inst->wrapperObject->read_only = true; | G->P_inst->wrapperObject->read_only = true; | |||
G->P_inst->wrapperObject->state = -1; | ||||
if (obj->DiscreteFlag) { | ||||
G->P_inst->wrapperObject->state = obj->AtomInfo[atm].discrete_state; | ||||
} else { | ||||
G->P_inst->wrapperObject->state = 0; | ||||
} | ||||
if (!expr_co){ | if (!expr_co){ | |||
// unsetting label | // unsetting label | |||
LexAssign(G, ai->label, 0); | LexAssign(G, ai->label, 0); | |||
return true; | return true; | |||
} | } | |||
resultPyObject = PyEval_EvalCode(expr_co, P_inst_dict, (PyObject*)G->P_inst->w rapperObject); | resultPyObject = PyEval_EvalCode(expr_co, P_inst_dict, (PyObject*)G->P_inst->w rapperObject); | |||
WrapperObjectReset(G->P_inst->wrapperObject); | WrapperObjectReset(G->P_inst->wrapperObject); | |||
if(PyErr_Occurred()) { | if(PyErr_Occurred()) { | |||
skipping to change at line 1979 | skipping to change at line 1945 | |||
/* copy arguments to __main__.pymol_argv */ | /* copy arguments to __main__.pymol_argv */ | |||
PyObject_SetAttrString(P_main, "pymol_argv", args); | PyObject_SetAttrString(P_main, "pymol_argv", args); | |||
PyRun_SimpleString | PyRun_SimpleString | |||
("import __main__\nif not hasattr(sys,'argv'): sys.argv=__main__.pymol_argv" ); | ("import __main__\nif not hasattr(sys,'argv'): sys.argv=__main__.pymol_argv" ); | |||
PyRun_SimpleString("if (os.environ['PYMOL_PATH']+'/modules') not in sys.path: sys.path.insert(0,os.environ['PYMOL_PATH']+'/modules')\n"); /* needed for se mistatic pymol */ | PyRun_SimpleString("if (os.environ['PYMOL_PATH']+'/modules') not in sys.path: sys.path.insert(0,os.environ['PYMOL_PATH']+'/modules')\n"); /* needed for se mistatic pymol */ | |||
} | } | |||
void PConvertOptions(CPyMOLOptions * rec, PyObject * options) | void PConvertOptions(CPyMOLOptions * rec, PyObject * options) | |||
{ | { | |||
char *load_str; | const char *load_str; | |||
rec->pmgui = !PyInt_AsLong(PyObject_GetAttrString(options, "no_gui")); | rec->pmgui = !PyInt_AsLong(PyObject_GetAttrString(options, "no_gui")); | |||
rec->internal_gui = PyInt_AsLong(PyObject_GetAttrString(options, "internal_gui ")); | rec->internal_gui = PyInt_AsLong(PyObject_GetAttrString(options, "internal_gui ")); | |||
rec->internal_feedback = | rec->internal_feedback = | |||
PyInt_AsLong(PyObject_GetAttrString(options, "internal_feedback")); | PyInt_AsLong(PyObject_GetAttrString(options, "internal_feedback")); | |||
rec->show_splash = PyInt_AsLong(PyObject_GetAttrString(options, "show_splash") ); | rec->show_splash = PyInt_AsLong(PyObject_GetAttrString(options, "show_splash") ); | |||
rec->security = PyInt_AsLong(PyObject_GetAttrString(options, "security")); | rec->security = PyInt_AsLong(PyObject_GetAttrString(options, "security")); | |||
rec->game_mode = PyInt_AsLong(PyObject_GetAttrString(options, "game_mode")); | rec->game_mode = PyInt_AsLong(PyObject_GetAttrString(options, "game_mode")); | |||
rec->force_stereo = PyInt_AsLong(PyObject_GetAttrString(options, "force_stereo ")); | rec->force_stereo = PyInt_AsLong(PyObject_GetAttrString(options, "force_stereo ")); | |||
rec->winX = PyInt_AsLong(PyObject_GetAttrString(options, "win_x")); | rec->winX = PyInt_AsLong(PyObject_GetAttrString(options, "win_x")); | |||
skipping to change at line 2103 | skipping to change at line 2069 | |||
init_numpy(); | init_numpy(); | |||
initmultiarray(); | initmultiarray(); | |||
initarrayfns(); | initarrayfns(); | |||
initlapack_lite(); | initlapack_lite(); | |||
initumath(); | initumath(); | |||
initranlib(); | initranlib(); | |||
#endif | #endif | |||
/* initialize PyOpenGL */ | /* initialize PyOpenGL */ | |||
#endif | #endif | |||
if(global_instance) { | #if PY_MAJOR_VERSION < 3 | |||
// Support implicit utf-8 encoding (important for labeling!) | ||||
// str(u"...unicode...") -> b"...utf-8..." | ||||
// PyString_AsString(unicodeobj) -> "...utf-8..." | ||||
PyUnicode_SetDefaultEncoding("utf-8"); | ||||
#endif | ||||
if(true /* global_instance */) { | ||||
PCatchInit(); /* setup standard-output catch routine */ | PCatchInit(); /* setup standard-output catch routine */ | |||
} | } | |||
P_pymol = PImportModuleOrFatal("pymol"); | P_pymol = PImportModuleOrFatal("pymol"); | |||
P_pymol_dict = PyModule_GetDict(P_pymol); | P_pymol_dict = PyModule_GetDict(P_pymol); | |||
Py_XINCREF(P_pymol_dict); | Py_XINCREF(P_pymol_dict); | |||
if(!P_pymol_dict) | if(!P_pymol_dict) | |||
ErrFatal(G, "PyMOL", "can't find globals for 'pymol'"); | ErrFatal(G, "PyMOL", "can't find globals for 'pymol'"); | |||
if(global_instance) { /* if global singleton PyMOL... */ | if(global_instance) { /* if global singleton PyMOL... */ | |||
skipping to change at line 2130 | skipping to change at line 2103 | |||
for(a = 0; a < MAX_SAVED_THREAD; a++) { | for(a = 0; a < MAX_SAVED_THREAD; a++) { | |||
(str++)->id = -1; | (str++)->id = -1; | |||
} | } | |||
} | } | |||
} | } | |||
{ | { | |||
G->P_inst->exec = PGetAttrOrFatal(P_pymol, "exec_str"); | G->P_inst->exec = PGetAttrOrFatal(P_pymol, "exec_str"); | |||
if(global_instance) { | if(global_instance) { | |||
PyRun_SimpleString( | PCatch_install(NULL, NULL); | |||
"import sys, pcatch;" | ||||
"pcatch.closed = False;" | ||||
"sys.stderr = sys.stdout = pcatch"); | ||||
} | } | |||
P_traceback = PImportModuleOrFatal("traceback"); | P_traceback = PImportModuleOrFatal("traceback"); | |||
P_cmd = PImportModuleOrFatal("pymol.cmd"); | P_cmd = PImportModuleOrFatal("pymol.cmd"); | |||
if(global_instance) { | if(global_instance) { | |||
/* implies global singleton pymol, so set up the global handle */ | /* implies global singleton pymol, so set up the global handle */ | |||
PyObject_SetAttrString(P_cmd, "_COb", | PyObject_SetAttrString(P_cmd, "_COb", | |||
PyCObject_FromVoidPtr((void *) &SingletonPyMOLGloba ls, | PyCObject_FromVoidPtr((void *) &SingletonPyMOLGloba ls, | |||
NULL)); | NULL)); | |||
/* cmd module is itself the api for the global PyMOL instance */ | /* cmd module is itself the api for the global PyMOL instance */ | |||
G->P_inst->cmd = P_cmd; | G->P_inst->cmd = P_cmd; | |||
} | } | |||
PyObject_SetAttrString(G->P_inst->cmd, "_pymol", G->P_inst->obj); | ||||
/* right now, all locks are global -- eventually some of these may | /* right now, all locks are global -- eventually some of these may | |||
become instance-specific in order to improve concurrency */ | become instance-specific in order to improve concurrency */ | |||
G->P_inst->lock = PGetAttrOrFatal(G->P_inst->cmd, "lock"); | G->P_inst->lock = PGetAttrOrFatal(G->P_inst->cmd, "lock"); | |||
G->P_inst->lock_attempt = PGetAttrOrFatal(G->P_inst->cmd, "lock_attempt"); | G->P_inst->lock_attempt = PGetAttrOrFatal(G->P_inst->cmd, "lock_attempt"); | |||
G->P_inst->unlock = PGetAttrOrFatal(G->P_inst->cmd, "unlock"); | G->P_inst->unlock = PGetAttrOrFatal(G->P_inst->cmd, "unlock"); | |||
G->P_inst->lock_c = PGetAttrOrFatal(G->P_inst->cmd, "lock_c"); | G->P_inst->lock_c = PGetAttrOrFatal(G->P_inst->cmd, "lock_c"); | |||
G->P_inst->unlock_c = PGetAttrOrFatal(G->P_inst->cmd, "unlock_c"); | G->P_inst->unlock_c = PGetAttrOrFatal(G->P_inst->cmd, "unlock_c"); | |||
G->P_inst->lock_status = PGetAttrOrFatal(G->P_inst->cmd, "lock_status"); | G->P_inst->lock_status = PGetAttrOrFatal(G->P_inst->cmd, "lock_status"); | |||
G->P_inst->lock_status_attempt = | G->P_inst->lock_status_attempt = | |||
skipping to change at line 2208 | skipping to change at line 2176 | |||
} | } | |||
{ | { | |||
PyObject *fn_closure = PyObject_GetAttrString(P_parser, "new_complete_clos ure"); | PyObject *fn_closure = PyObject_GetAttrString(P_parser, "new_complete_clos ure"); | |||
G->P_inst->complete = PYOBJECT_CALLFUNCTION(fn_closure, "O", G->P_inst->cm d); | G->P_inst->complete = PYOBJECT_CALLFUNCTION(fn_closure, "O", G->P_inst->cm d); | |||
PXDecRef(fn_closure); | PXDecRef(fn_closure); | |||
if(!G->P_inst->complete) | if(!G->P_inst->complete) | |||
ErrFatal(G, "PyMOL", "can't create 'complete' function closure"); | ErrFatal(G, "PyMOL", "can't create 'complete' function closure"); | |||
} | } | |||
{ | ||||
PyObject *fn_closure = PGetAttrOrFatal(P_pymol, "_colortype"); | ||||
G->P_inst->colortype = PYOBJECT_CALLFUNCTION(fn_closure, "O", G->P_inst->c | ||||
md); | ||||
PXDecRef(fn_closure); | ||||
} | ||||
P_chempy = PImportModuleOrFatal("chempy"); | P_chempy = PImportModuleOrFatal("chempy"); | |||
P_models = PImportModuleOrFatal("chempy.models"); | P_models = PImportModuleOrFatal("chempy.models"); | |||
/* backwards compatibility */ | /* backwards compatibility */ | |||
PRunStringModule(G, "glutThread = thread.get_ident()"); | PRunStringModule(G, "glutThread = thread.get_ident()"); | |||
P_glut_thread_id = PyThread_get_thread_ident(); | P_glut_thread_id = PyThread_get_thread_ident(); | |||
#ifndef WIN32 | #ifndef WIN32 | |||
skipping to change at line 2297 | skipping to change at line 2271 | |||
int blocked; | int blocked; | |||
blocked = PAutoBlock(G); | blocked = PAutoBlock(G); | |||
if(flag) | if(flag) | |||
PRunStringModule(G, "cmd._sgi_stereo(1)"); | PRunStringModule(G, "cmd._sgi_stereo(1)"); | |||
else | else | |||
PRunStringModule(G, "cmd._sgi_stereo(0)"); | PRunStringModule(G, "cmd._sgi_stereo(0)"); | |||
if(blocked) | if(blocked) | |||
PUnblock(G); | PUnblock(G); | |||
} | } | |||
void PFree(void) | void PFree(PyMOLGlobals * G) | |||
{ | { | |||
PXDecRef(G->P_inst->parse); | ||||
PXDecRef(G->P_inst->complete); | ||||
PXDecRef(G->P_inst->colortype); | ||||
} | } | |||
void PExit(PyMOLGlobals * G, int code) | void PExit(PyMOLGlobals * G, int code) | |||
{ | { | |||
ExecutiveDelete(G, "all"); | ExecutiveDelete(G, "all"); | |||
PBlock(G); | PBlock(G); | |||
PyMOL_PushValidContext(G->PyMOL); | ||||
PyMOL_Stop(G->PyMOL); | ||||
PyMOL_PopValidContext(G->PyMOL); | ||||
#ifndef _PYMOL_NO_MAIN | #ifndef _PYMOL_NO_MAIN | |||
if(G->Main) { | if(G->Main) { | |||
MainFree(); | MainFree(); | |||
} | } | |||
#endif | #endif | |||
PyMOL_Free(G->PyMOL); | ||||
#if 1 | #if 1 | |||
/* we're having trouble with threading errors after calling Py_Exit, | /* we're having trouble with threading errors after calling Py_Exit, | |||
so for the time being, let's just take the process down at this | so for the time being, let's just take the process down at this | |||
point, instead of allowing PyExit to be called. */ | point, instead of allowing PyExit to be called. */ | |||
exit(code); | exit(code); | |||
#else | #else | |||
Py_Exit(code); | Py_Exit(code); | |||
#endif | #endif | |||
skipping to change at line 2754 | skipping to change at line 2738 | |||
{ | { | |||
PyObject *seq; | PyObject *seq; | |||
int len; | int len; | |||
PyArg_ParseTuple(args, "O", &seq); | PyArg_ParseTuple(args, "O", &seq); | |||
if(seq && PySequence_Check(seq)) { | if(seq && PySequence_Check(seq)) { | |||
if((len = PySequence_Size(seq)) > 0) { | if((len = PySequence_Size(seq)) > 0) { | |||
int i; | int i; | |||
for(i = 0; i < len; i++) { | for(i = 0; i < len; i++) { | |||
PyObject *obj = PySequence_GetItem(seq, i); | PyObject *obj = PySequence_GetItem(seq, i); | |||
if(obj && PyString_Check(obj)) { | if(obj && PyString_Check(obj)) { | |||
char *str = PyString_AsString(obj); | const char *str = PyString_AsString(obj); | |||
if(SingletonPyMOLGlobals) { | if(SingletonPyMOLGlobals) { | |||
if(Feedback(SingletonPyMOLGlobals, FB_Python, FB_Output)) { | if(Feedback(SingletonPyMOLGlobals, FB_Python, FB_Output)) { | |||
OrthoAddOutput(SingletonPyMOLGlobals, str); | OrthoAddOutput(SingletonPyMOLGlobals, str); | |||
} | } | |||
} | } | |||
} | } | |||
Py_XDECREF(obj); | Py_XDECREF(obj); | |||
} | } | |||
} | } | |||
} | } | |||
skipping to change at line 2780 | skipping to change at line 2764 | |||
fflush(stdout); | fflush(stdout); | |||
fflush(stderr); | fflush(stderr); | |||
return PConvAutoNone(Py_None); | return PConvAutoNone(Py_None); | |||
} | } | |||
static PyObject *PCatchIsAtty(PyObject * self, PyObject * args) | static PyObject *PCatchIsAtty(PyObject * self, PyObject * args) | |||
{ | { | |||
Py_RETURN_FALSE; | Py_RETURN_FALSE; | |||
} | } | |||
static PyObject *PCatch_install(PyObject * self, PyObject * args) | ||||
{ | ||||
PyRun_SimpleString( | ||||
"import sys, pcatch\n" | ||||
"if sys.stdout is not pcatch:" | ||||
"pcatch.closed = False;" | ||||
"pcatch.encoding = 'UTF-8';" | ||||
"sys.stderr = sys.stdout = pcatch"); | ||||
return PConvAutoNone(Py_None); | ||||
} | ||||
static PyMethodDef PCatch_methods[] = { | static PyMethodDef PCatch_methods[] = { | |||
{"writelines", PCatchWritelines, METH_VARARGS}, | {"writelines", PCatchWritelines, METH_VARARGS}, | |||
{"write", PCatchWrite, METH_VARARGS}, | {"write", PCatchWrite, METH_VARARGS}, | |||
{"flush", PCatchFlush, METH_VARARGS}, | {"flush", PCatchFlush, METH_VARARGS}, | |||
{"isatty", PCatchIsAtty, METH_VARARGS}, // called by pip.main(["install", "... "]) | {"isatty", PCatchIsAtty, METH_VARARGS}, // called by pip.main(["install", "... "]) | |||
{"_install", PCatch_install, METH_VARARGS}, | ||||
{NULL, NULL} /* sentinel */ | {NULL, NULL} /* sentinel */ | |||
}; | }; | |||
void PCatchInit(void) | void PCatchInit(void) | |||
{ | { | |||
#if PY_MAJOR_VERSION < 3 | #if PY_MAJOR_VERSION < 3 | |||
PyImport_AddModule("pcatch"); | PyImport_AddModule("pcatch"); | |||
Py_InitModule("pcatch", PCatch_methods); | Py_InitModule("pcatch", PCatch_methods); | |||
#else | #else | |||
static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, | static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, | |||
End of changes. 30 change blocks. | ||||
78 lines changed or deleted | 75 lines changed or added |