CifMoleculeReader.cpp (pymol-v1.8.6.0.tar.bz2) | : | CifMoleculeReader.cpp (pymol-v2.1.0.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 34 | skipping to change at line 34 | |||
#include "P.h" | #include "P.h" | |||
#include "Util.h" | #include "Util.h" | |||
#include "Scene.h" | #include "Scene.h" | |||
#include "Rep.h" | #include "Rep.h" | |||
#include "ObjectMolecule.h" | #include "ObjectMolecule.h" | |||
#include "CifFile.h" | #include "CifFile.h" | |||
#include "CifBondDict.h" | #include "CifBondDict.h" | |||
#include "Util2.h" | #include "Util2.h" | |||
#include "Vector.h" | #include "Vector.h" | |||
#include "Lex.h" | #include "Lex.h" | |||
#include "strcasecmp.h" | ||||
// canonical amino acid three letter codes | // canonical amino acid three letter codes | |||
const char * aa_three_letter[] = { | const char * aa_three_letter[] = { | |||
"ALA", // A | "ALA", // A | |||
"ASX", // B for ambiguous asparagine/aspartic-acid | "ASX", // B for ambiguous asparagine/aspartic-acid | |||
"CYS", // C | "CYS", // C | |||
"ASP", // D | "ASP", // D | |||
"GLU", // E | "GLU", // E | |||
"PHE", // F | "PHE", // F | |||
"GLY", // G | "GLY", // G | |||
skipping to change at line 863 | skipping to change at line 864 | |||
} | } | |||
/* | /* | |||
* Read CHEM_COMP_ATOM | * Read CHEM_COMP_ATOM | |||
*/ | */ | |||
static CoordSet ** read_chem_comp_atom_model(PyMOLGlobals * G, cif_data * data, | static CoordSet ** read_chem_comp_atom_model(PyMOLGlobals * G, cif_data * data, | |||
AtomInfoType ** atInfoPtr) { | AtomInfoType ** atInfoPtr) { | |||
const cif_array *arr_x, *arr_y = NULL, *arr_z = NULL; | const cif_array *arr_x, *arr_y = NULL, *arr_z = NULL; | |||
if ((arr_x = data->get_arr("_chem_comp_atom.pdbx_model_cartn_x_ideal"))) { | // setting to exclude one or more coordinate columns | |||
unsigned mask = SettingGetGlobal_i(G, cSetting_chem_comp_cartn_use); | ||||
const char * feedback = ""; | ||||
if (!mask) { | ||||
mask = 0xFF; | ||||
} | ||||
if ((mask & 0x01) | ||||
&& (arr_x = data->get_arr("_chem_comp_atom.pdbx_model_cartn_x_ideal")) | ||||
&& !arr_x->is_missing_all()) { | ||||
arr_y = data->get_arr("_chem_comp_atom.pdbx_model_cartn_y_ideal"); | arr_y = data->get_arr("_chem_comp_atom.pdbx_model_cartn_y_ideal"); | |||
arr_z = data->get_arr("_chem_comp_atom.pdbx_model_cartn_z_ideal"); | arr_z = data->get_arr("_chem_comp_atom.pdbx_model_cartn_z_ideal"); | |||
} else if ((arr_x = data->get_arr("_chem_comp_atom.x"))) { | feedback = ".pdbx_model_Cartn_{x,y,z}_ideal"; | |||
arr_y = data->get_arr("_chem_comp_atom.y"); | } else if ((mask & 0x02) | |||
arr_z = data->get_arr("_chem_comp_atom.z"); | && (arr_x = data->get_arr("_chem_comp_atom.model_cartn_x"))) { | |||
} else if ((arr_x = data->get_arr("_chem_comp_atom.model_cartn_x"))) { | ||||
arr_y = data->get_arr("_chem_comp_atom.model_cartn_y"); | arr_y = data->get_arr("_chem_comp_atom.model_cartn_y"); | |||
arr_z = data->get_arr("_chem_comp_atom.model_cartn_z"); | arr_z = data->get_arr("_chem_comp_atom.model_cartn_z"); | |||
feedback = ".model_Cartn_{x,y,z}"; | ||||
} else if ((mask & 0x04) | ||||
&& (arr_x = data->get_arr("_chem_comp_atom.x")) | ||||
&& !arr_x->is_missing_all()) { | ||||
arr_y = data->get_arr("_chem_comp_atom.y"); | ||||
arr_z = data->get_arr("_chem_comp_atom.z"); | ||||
feedback = ".{x,y,z}"; | ||||
} | } | |||
if (!arr_x || !arr_y || !arr_z) { | if (!arr_x || !arr_y || !arr_z) { | |||
return NULL; | return NULL; | |||
} | } | |||
PRINTFB(G, FB_Executive, FB_Details) | PRINTFB(G, FB_Executive, FB_Details) | |||
" ExecutiveLoad-Detail: Detected chem_comp CIF\n" ENDFB(G); | " ExecutiveLoad-Detail: Detected chem_comp CIF (%s)\n", feedback | |||
ENDFB(G); | ||||
const cif_array * arr_name = data->get_opt("_chem_comp_atom.atom_id "); | const cif_array * arr_name = data->get_opt("_chem_comp_atom.atom_id "); | |||
const cif_array * arr_symbol = data->get_opt("_chem_comp_atom.type_sy mbol"); | const cif_array * arr_symbol = data->get_opt("_chem_comp_atom.type_sy mbol"); | |||
const cif_array * arr_resn = data->get_opt("_chem_comp_atom.comp_id "); | const cif_array * arr_resn = data->get_opt("_chem_comp_atom.comp_id "); | |||
const cif_array * arr_partial_charge = data->get_opt("_chem_comp_atom.partial _charge"); | const cif_array * arr_partial_charge = data->get_opt("_chem_comp_atom.partial _charge"); | |||
const cif_array * arr_formal_charge = data->get_opt("_chem_comp_atom.charge" ); | const cif_array * arr_formal_charge = data->get_opt("_chem_comp_atom.charge" ); | |||
const cif_array * arr_stereo = data->get_opt("_chem_comp_atom.pdbx_st ereo_config"); | const cif_array * arr_stereo = data->get_opt("_chem_comp_atom.pdbx_st ereo_config"); | |||
int nrows = arr_x->get_nrows(); | int nrows = arr_x->get_nrows(); | |||
AtomInfoType *ai; | AtomInfoType *ai; | |||
skipping to change at line 915 | skipping to change at line 933 | |||
LexAssign(G, ai->name, arr_name->as_s(i)); | LexAssign(G, ai->name, arr_name->as_s(i)); | |||
LexAssign(G, ai->resn, arr_resn->as_s(i)); | LexAssign(G, ai->resn, arr_resn->as_s(i)); | |||
strncpy(ai->elem, arr_symbol->as_s(i), cElemNameLen); | strncpy(ai->elem, arr_symbol->as_s(i), cElemNameLen); | |||
ai->partialCharge = arr_partial_charge->as_d(i); | ai->partialCharge = arr_partial_charge->as_d(i); | |||
ai->formalCharge = arr_formal_charge->as_i(i); | ai->formalCharge = arr_formal_charge->as_i(i); | |||
ai->hetatm = 1; | ai->hetatm = 1; | |||
ai->visRep = auto_show; | ai->visRep = auto_show; | |||
ai->stereo = convertCharToStereo(arr_stereo->as_s(i)[0]); | AtomInfoSetStereo(ai, arr_stereo->as_s(i)); | |||
AtomInfoAssignParameters(G, ai); | AtomInfoAssignParameters(G, ai); | |||
AtomInfoAssignColors(G, ai); | AtomInfoAssignColors(G, ai); | |||
coord[atomCount * 3 + 0] = arr_x->as_d(i); | coord[atomCount * 3 + 0] = arr_x->as_d(i); | |||
coord[atomCount * 3 + 1] = arr_y->as_d(i); | coord[atomCount * 3 + 1] = arr_y->as_d(i); | |||
coord[atomCount * 3 + 2] = arr_z->as_d(i); | coord[atomCount * 3 + 2] = arr_z->as_d(i); | |||
atomCount++; | atomCount++; | |||
} | } | |||
skipping to change at line 1034 | skipping to change at line 1052 | |||
arr_u = data->get_arr("_atom_site?u_iso_or_equiv"); // NULL | arr_u = data->get_arr("_atom_site?u_iso_or_equiv"); // NULL | |||
arr_q = data->get_opt("_atom_site?occupancy"); | arr_q = data->get_opt("_atom_site?occupancy"); | |||
arr_ID = data->get_opt("_atom_site.id", | arr_ID = data->get_opt("_atom_site.id", | |||
"_atom_site_label"); | "_atom_site_label"); | |||
arr_mod_num = data->get_opt("_atom_site.pdbx_pdb_model_num"); | arr_mod_num = data->get_opt("_atom_site.pdbx_pdb_model_num"); | |||
arr_entity_id = data->get_arr("_atom_site.label_entity_id"); // NULL | arr_entity_id = data->get_arr("_atom_site.label_entity_id"); // NULL | |||
const cif_array * arr_color = data->get_arr("_atom_site.pymol_color"); | const cif_array * arr_color = data->get_arr("_atom_site.pymol_color"); | |||
const cif_array * arr_reps = data->get_arr("_atom_site.pymol_reps"); | const cif_array * arr_reps = data->get_arr("_atom_site.pymol_reps"); | |||
const cif_array * arr_ss = data->get_opt("_atom_site.pymol_ss"); | const cif_array * arr_ss = data->get_opt("_atom_site.pymol_ss"); | |||
const cif_array * arr_formal_charge = data->get_opt("_atom_site.pdbx_formal_ch arge"); | ||||
if (!arr_chain) | if (!arr_chain) | |||
arr_chain = arr_segi; | arr_chain = arr_segi; | |||
ModelStateMapper model_to_state(!SettingGetGlobal_i(G, cSetting_pdb_honor_mode l_number)); | ModelStateMapper model_to_state(!SettingGetGlobal_i(G, cSetting_pdb_honor_mode l_number)); | |||
int nrows = arr_x->get_nrows(); | int nrows = arr_x->get_nrows(); | |||
AtomInfoType *ai; | AtomInfoType *ai; | |||
int atomCount = 0; | int atomCount = 0; | |||
int auto_show = RepGetAutoShowMask(G); | int auto_show = RepGetAutoShowMask(G); | |||
int first_model_num = model_to_state(arr_mod_num->as_i(0, 1)); | int first_model_num = model_to_state(arr_mod_num->as_i(0, 1)); | |||
skipping to change at line 1156 | skipping to change at line 1175 | |||
} | } | |||
if (arr_reps) { | if (arr_reps) { | |||
ai->visRep = arr_reps->as_i(i, auto_show); | ai->visRep = arr_reps->as_i(i, auto_show); | |||
ai->flags |= cAtomFlag_inorganic; // suppress auto_show_classified | ai->flags |= cAtomFlag_inorganic; // suppress auto_show_classified | |||
} else { | } else { | |||
ai->visRep = auto_show; | ai->visRep = auto_show; | |||
} | } | |||
ai->ssType[0] = arr_ss->as_s(i)[0]; | ai->ssType[0] = arr_ss->as_s(i)[0]; | |||
ai->formalCharge = arr_formal_charge->as_i(i); | ||||
AtomInfoAssignParameters(G, ai); | AtomInfoAssignParameters(G, ai); | |||
if (arr_color) { | if (arr_color) { | |||
ai->color = arr_color->as_i(i); | ai->color = arr_color->as_i(i); | |||
} else { | } else { | |||
AtomInfoAssignColors(G, ai); | AtomInfoAssignColors(G, ai); | |||
} | } | |||
if (arr_entity_id != NULL) { | if (arr_entity_id != NULL) { | |||
skipping to change at line 1979 | skipping to change at line 1999 | |||
if (nBond) { | if (nBond) { | |||
VLASize(bondvla, BondType, nBond); | VLASize(bondvla, BondType, nBond); | |||
} else { | } else { | |||
VLAFreeP(bondvla); | VLAFreeP(bondvla); | |||
} | } | |||
return bondvla; | return bondvla; | |||
} | } | |||
/* | /* | |||
* Read bonds from _pymol_bond (non-standard extension) | ||||
* | ||||
* return: BondType VLA | ||||
*/ | ||||
static BondType * read_pymol_bond(PyMOLGlobals * G, cif_data * data, | ||||
AtomInfoType * atInfo) { | ||||
const cif_array *col_ID_1, *col_ID_2, *col_order; | ||||
if ((col_ID_1 = data->get_arr("_pymol_bond.atom_site_id_1")) == NULL || | ||||
(col_ID_2 = data->get_arr("_pymol_bond.atom_site_id_2")) == NULL || | ||||
(col_order = data->get_arr("_pymol_bond.order")) == NULL) | ||||
return NULL; | ||||
int nrows = col_ID_1->get_nrows(); | ||||
int nAtom = VLAGetSize(atInfo); | ||||
BondType *bondvla, *bond; | ||||
bondvla = bond = VLACalloc(BondType, nrows); | ||||
// ID -> atom index | ||||
std::map<int, int> id_dict; | ||||
for (int atm = 0; atm < nAtom; ++atm) { | ||||
id_dict[atInfo[atm].id] = atm; | ||||
} | ||||
for (int i = 0; i < nrows; i++) { | ||||
auto key1 = col_ID_1->as_i(i); | ||||
auto key2 = col_ID_2->as_i(i); | ||||
auto order_value = col_order->as_i(i); | ||||
int i1, i2; | ||||
if (find2(id_dict, i1, key1, i2, key2)) { | ||||
BondTypeInit2(bond++, i1, i2, order_value); | ||||
} else { | ||||
PRINTFB(G, FB_Executive, FB_Details) | ||||
" Executive-Detail: _pymol_bond name lookup failed: %d %d\n", | ||||
key1, key2 ENDFB(G); | ||||
} | ||||
} | ||||
return bondvla; | ||||
} | ||||
/* | ||||
* Create a new (multi-state) object-molecule from datablock | * Create a new (multi-state) object-molecule from datablock | |||
*/ | */ | |||
static ObjectMolecule *ObjectMoleculeReadCifData(PyMOLGlobals * G, cif_data * da | static ObjectMolecule *ObjectMoleculeReadCifData(PyMOLGlobals * G, | |||
tablock, int discrete) | cif_data * datablock, int discrete, bool quiet) | |||
{ | { | |||
CoordSet ** csets = NULL; | CoordSet ** csets = NULL; | |||
int ncsets; | int ncsets; | |||
CifContentInfo info(G, SettingGetGlobal_b(G, cSetting_cif_use_auth)); | CifContentInfo info(G, SettingGetGlobal_b(G, cSetting_cif_use_auth)); | |||
const char * assembly_id = SettingGetGlobal_s(G, cSetting_assembly); | const char * assembly_id = SettingGetGlobal_s(G, cSetting_assembly); | |||
// title "echo tag" | ||||
const char * title = datablock->get_opt("_struct.title")->as_s(); | ||||
if (!quiet && title[0] && | ||||
strstr(SettingGetGlobal_s(G, cSetting_pdb_echo_tags), "TITLE")) { | ||||
PRINTFB(G, FB_ObjectMolecule, FB_Details) | ||||
"TITLE %s\n", title ENDFB(G); | ||||
} | ||||
if (assembly_id && assembly_id[0]) { | if (assembly_id && assembly_id[0]) { | |||
if (!get_assembly_chains(G, datablock, info.chains_filter, assembly_id)) | if (!get_assembly_chains(G, datablock, info.chains_filter, assembly_id)) | |||
PRINTFB(G, FB_Executive, FB_Details) | PRINTFB(G, FB_Executive, FB_Details) | |||
" ExecutiveLoad-Detail: No such assembly: '%s'\n", assembly_id ENDFB(G); | " ExecutiveLoad-Detail: No such assembly: '%s'\n", assembly_id ENDFB(G); | |||
} | } | |||
// allocate ObjectMolecule | // allocate ObjectMolecule | |||
ObjectMolecule * I = ObjectMoleculeNew(G, (discrete > 0)); | ObjectMolecule * I = ObjectMoleculeNew(G, (discrete > 0)); | |||
I->Obj.Color = AtomInfoUpdateAutoColor(G); | I->Obj.Color = AtomInfoUpdateAutoColor(G); | |||
skipping to change at line 2088 | skipping to change at line 2163 | |||
I->Bond = read_chem_comp_bond(G, datablock, I->AtomInfo); | I->Bond = read_chem_comp_bond(G, datablock, I->AtomInfo); | |||
break; | break; | |||
case CIF_CORE: | case CIF_CORE: | |||
I->Bond = read_geom_bond(G, datablock, I->AtomInfo); | I->Bond = read_geom_bond(G, datablock, I->AtomInfo); | |||
if (!I->Bond) | if (!I->Bond) | |||
I->Bond = read_chemical_conn_bond(G, datablock); | I->Bond = read_chemical_conn_bond(G, datablock); | |||
break; | break; | |||
case CIF_MMCIF: | case CIF_MMCIF: | |||
if (cset) { | I->Bond = read_pymol_bond(G, datablock, I->AtomInfo); | |||
if (cset && !I->Bond) { | ||||
// sort atoms internally | // sort atoms internally | |||
ObjectMoleculeSort(I); | ObjectMoleculeSort(I); | |||
// bonds from file, goes to cset->TmpBond | // bonds from file, goes to cset->TmpBond | |||
read_struct_conn_(G, datablock, I->AtomInfo, cset, info); | read_struct_conn_(G, datablock, I->AtomInfo, cset, info); | |||
// macromolecular bonding | // macromolecular bonding | |||
bond_dict_t bond_dict_local; | bond_dict_t bond_dict_local; | |||
if (read_chem_comp_bond_dict(datablock, bond_dict_local)) { | if (read_chem_comp_bond_dict(datablock, bond_dict_local)) { | |||
ObjectMoleculeConnectComponents(I, &bond_dict_local); | ObjectMoleculeConnectComponents(I, &bond_dict_local); | |||
skipping to change at line 2197 | skipping to change at line 2274 | |||
const char * filename = NULL; | const char * filename = NULL; | |||
#ifndef _PYMOL_NO_CXX11 | #ifndef _PYMOL_NO_CXX11 | |||
auto cif = std::make_shared<cif_file>(filename, st); | auto cif = std::make_shared<cif_file>(filename, st); | |||
#else | #else | |||
cif_file _cif_stack(filename, st); | cif_file _cif_stack(filename, st); | |||
auto cif = &_cif_stack; | auto cif = &_cif_stack; | |||
#endif | #endif | |||
for (auto it = cif->datablocks.begin(); it != cif->datablocks.end(); ++it) { | for (auto it = cif->datablocks.begin(); it != cif->datablocks.end(); ++it) { | |||
ObjectMolecule * obj = ObjectMoleculeReadCifData(G, it->second, discrete); | ObjectMolecule * obj = ObjectMoleculeReadCifData(G, it->second, discrete, qu iet); | |||
if (!obj) { | if (!obj) { | |||
PRINTFB(G, FB_ObjectMolecule, FB_Errors) | PRINTFB(G, FB_ObjectMolecule, FB_Warnings) | |||
" mmCIF-Error: no coordinates found in data_%s\n", it->first ENDFB(G); | " mmCIF-Warning: no coordinates found in data_%s\n", it->first ENDFB(G); | |||
continue; | continue; | |||
} | } | |||
#if !defined(_PYMOL_NOPY) && !defined(_PYMOL_NO_CXX11) | #if !defined(_PYMOL_NOPY) && !defined(_PYMOL_NO_CXX11) | |||
// we only provide access from the Python API so far | // we only provide access from the Python API so far | |||
if (SettingGetGlobal_b(G, cSetting_cif_keepinmemory)) { | if (SettingGetGlobal_b(G, cSetting_cif_keepinmemory)) { | |||
obj->m_cifdata = it->second; | obj->m_cifdata = it->second; | |||
obj->m_ciffile = cif; | obj->m_ciffile = cif; | |||
} | } | |||
#endif | #endif | |||
End of changes. 14 change blocks. | ||||
13 lines changed or deleted | 89 lines changed or added |