Ticket #778: changes.diff
| File changes.diff, 39.5 KB (added by , 8 years ago) |
|---|
-
src/core/atomic/atomstruct_cpp/Atom.cpp
diff --git a/src/core/atomic/atomstruct_cpp/Atom.cpp b/src/core/atomic/atomstruct_cpp/Atom.cpp index 1903479..9032ebf 100644
a b Atom::get_idatm_info_map() 846 846 return _idatm_map; 847 847 } 848 848 849 void 850 Atom::bonds_track_change(const std::string& reason) { 851 for(std::vector<Bond*>::iterator b = _bonds.begin(); b != _bonds.end(); ++b) { 852 (*b)->track_change(reason); 853 } 854 } 855 856 849 857 bool 850 858 Atom::has_missing_structure_pseudobond() const 851 859 { … … Atom::set_alt_loc(char alt_loc, bool create, bool _from_residue) 1112 1120 if (alt_loc == _alt_loc || alt_loc == ' ') 1113 1121 return; 1114 1122 graphics_container()->set_gc_shape(); 1115 structure()->change_tracker()->add_modified(this,ChangeTracker::REASON_ALT_LOC);1123 track_change(ChangeTracker::REASON_ALT_LOC); 1116 1124 if (create) { 1117 1125 if (_alt_loc_map.find(alt_loc) != _alt_loc_map.end()) { 1118 1126 set_alt_loc(alt_loc, create=false); … … Atom::set_alt_loc(char alt_loc, bool create, bool _from_residue) 1135 1143 _Alt_loc_info &info = (*i).second; 1136 1144 _serial_number = info.serial_number; 1137 1145 _alt_loc = alt_loc; 1138 structure()->change_tracker()->add_modified(this,ChangeTracker::REASON_COORD);1146 track_change(ChangeTracker::REASON_COORD); 1139 1147 } else { 1140 1148 residue()->set_alt_loc(alt_loc); 1141 1149 } … … Atom::set_aniso_u(float u11, float u12, float u13, float u22, float u23, float u 1160 1168 (*a)[3] = u22; 1161 1169 (*a)[4] = u23; 1162 1170 (*a)[5] = u33; 1163 structure()->change_tracker()->add_modified(this,ChangeTracker::REASON_ANISO_U);1171 track_change(ChangeTracker::REASON_ANISO_U); 1164 1172 } 1165 1173 1166 1174 void … … Atom::set_bfactor(float bfactor) 1171 1179 (*i).second.bfactor = bfactor; 1172 1180 } else 1173 1181 structure()->active_coord_set()->set_bfactor(this, bfactor); 1174 structure()->change_tracker()->add_modified(this,ChangeTracker::REASON_BFACTOR);1182 track_change(ChangeTracker::REASON_BFACTOR); 1175 1183 } 1176 1184 1177 1185 void … … Atom::set_color(const Rgba& rgba) 1180 1188 if (rgba == _rgba) 1181 1189 return; 1182 1190 graphics_container()->set_gc_color(); 1183 change_tracker()->add_modified(this, ChangeTracker::REASON_COLOR); 1191 track_change(ChangeTracker::REASON_COLOR); 1192 bonds_track_change(ChangeTracker::REASON_COLOR); 1184 1193 _rgba = rgba; 1185 1194 } 1186 1195 1187 1196 void 1188 1197 Atom::set_coord(const Coord& coord, CoordSet* cs) 1189 { 1190 structure()->change_tracker()->add_modified(this, ChangeTracker::REASON_COORD); 1198 { 1199 track_change(ChangeTracker::REASON_COORD); 1200 bonds_track_change(ChangeTracker::REASON_COORD); 1191 1201 if (cs == nullptr) { 1192 1202 cs = structure()->active_coord_set(); 1193 1203 if (cs == nullptr) { … … Atom::set_display(bool d) 1214 1224 if (d == _display) 1215 1225 return; 1216 1226 graphics_container()->set_gc_shape(); 1217 change_tracker()->add_modified(this, ChangeTracker::REASON_DISPLAY); 1227 structure()->set_visible_atoms_changed(true); 1228 structure()->set_visible_bonds_changed(true); 1229 track_change(ChangeTracker::REASON_DISPLAY); 1218 1230 _display = d; 1219 1231 } 1220 1232 … … Atom::set_draw_mode(DrawMode dm) 1223 1235 { 1224 1236 if (dm == _draw_mode) 1225 1237 return; 1238 if ( _draw_mode == DrawMode::Sphere || dm == DrawMode::Sphere ) 1239 structure()->set_visible_bonds_changed(true); 1226 1240 graphics_container()->set_gc_shape(); 1227 change_tracker()->add_modified(this,ChangeTracker::REASON_DRAW_MODE);1241 track_change(ChangeTracker::REASON_DRAW_MODE); 1228 1242 _draw_mode = dm; 1229 1243 } 1230 1244 … … Atom::set_hide(int h) 1234 1248 if (h == _hide) 1235 1249 return; 1236 1250 graphics_container()->set_gc_shape(); 1237 change_tracker()->add_modified(this, ChangeTracker::REASON_HIDE); 1251 structure()->set_visible_atoms_changed(true); 1252 structure()->set_visible_bonds_changed(true); 1253 track_change(ChangeTracker::REASON_HIDE); 1238 1254 _hide = h; 1239 1255 } 1240 1256 1241 1257 void 1242 1258 Atom::set_occupancy(float occupancy) 1243 1259 { 1244 structure()->change_tracker()->add_modified(this,ChangeTracker::REASON_OCCUPANCY);1260 track_change(ChangeTracker::REASON_OCCUPANCY); 1245 1261 if (_alt_loc != ' ') { 1246 1262 _Alt_loc_map::iterator i = _alt_loc_map.find(_alt_loc); 1247 1263 (*i).second.occupancy = occupancy; … … Atom::set_radius(float r) 1259 1275 return; 1260 1276 1261 1277 graphics_container()->set_gc_shape(); 1262 change_tracker()->add_modified(this,ChangeTracker::REASON_RADIUS);1278 track_change(ChangeTracker::REASON_RADIUS); 1263 1279 _radius = r; 1264 1280 } 1265 1281 … … Atom::set_selected(bool s) 1269 1285 if (s == _selected) 1270 1286 return; 1271 1287 graphics_container()->set_gc_select(); 1272 change_tracker()->add_modified(this, ChangeTracker::REASON_SELECTED); 1288 track_change(ChangeTracker::REASON_SELECTED); 1289 bonds_track_change(ChangeTracker::REASON_SELECTED); 1273 1290 _selected = s; 1274 1291 } 1275 1292 … … Atom::set_serial_number(int sn) 1281 1298 _Alt_loc_map::iterator i = _alt_loc_map.find(_alt_loc); 1282 1299 (*i).second.serial_number = sn; 1283 1300 } 1284 structure()->change_tracker()->add_modified(this,ChangeTracker::REASON_SERIAL_NUMBER);1301 track_change(ChangeTracker::REASON_SERIAL_NUMBER); 1285 1302 } 1286 1303 1287 1304 std::string -
src/core/atomic/atomstruct_cpp/Atom.h
diff --git a/src/core/atomic/atomstruct_cpp/Atom.h b/src/core/atomic/atomstruct_cpp/Atom.h index eb8c7ed..e9542da 100644
a b private: 109 109 typedef std::map<unsigned char, _Alt_loc_info> _Alt_loc_map; 110 110 _Alt_loc_map _alt_loc_map; 111 111 std::vector<float>* _aniso_u; 112 bool _changed = false; 112 113 Bonds _bonds; // _bonds/_neighbors in same order 113 114 mutable AtomType _computed_idatm_type; 114 115 unsigned int _coord_index; … … private: 128 129 mutable Rings _rings; 129 130 bool _selected = false; 130 131 int _serial_number; 131 void _set_structure_category(Atom::StructCat sc) const;132 void _set_structure_category(Atom::StructCat sc); 132 133 Structure* _structure; 133 134 mutable StructCat _structure_category; 134 135 public: … … public: 137 138 void _switch_initial_element(const Element& e) { _element = &e; } 138 139 139 140 public: 141 bool changed() const { return _changed; } 142 void set_changed(bool flag) { _changed = flag; } 140 143 void add_bond(Bond *b); 141 144 char alt_loc() const { return _alt_loc; } 142 145 std::set<char> alt_locs() const; … … public: 208 211 209 212 // change tracking 210 213 ChangeTracker* change_tracker() const; 214 void track_change(const std::string& reason) { 215 change_tracker()->add_modified(this, reason); 216 this->set_changed(true); 217 } 218 219 void bonds_track_change(const std::string& reason); 220 211 221 212 222 // graphics related 213 223 const Rgba& color() const { return _rgba; } … … Atom::idatm_type() const { 243 253 } 244 254 245 255 inline void 246 Atom::_set_structure_category(Atom::StructCat sc) const256 Atom::_set_structure_category(Atom::StructCat sc) 247 257 { 248 258 if (sc == _structure_category) 249 259 return; 250 change_tracker()->add_modified(const_cast<Atom*>(this), 251 ChangeTracker::REASON_STRUCTURE_CATEGORY); 260 track_change(ChangeTracker::REASON_STRUCTURE_CATEGORY); 261 //change_tracker()->add_modified(const_cast<Atom*>(this), 262 // ChangeTracker::REASON_STRUCTURE_CATEGORY); 252 263 _structure_category = sc; 253 264 } 254 265 255 266 inline void 256 267 Atom::set_computed_idatm_type(const char* it) { 257 268 if (!idatm_is_explicit() && _computed_idatm_type != it) { 269 track_change(ChangeTracker::REASON_IDATM_TYPE); 258 270 change_tracker()->add_modified(this, ChangeTracker::REASON_IDATM_TYPE); 259 271 } 260 272 _computed_idatm_type = it; … … Atom::set_idatm_type(const char* it) { 267 279 if (!(_explicit_idatm_type.empty() && _computed_idatm_type == it) 268 280 && !(*it == '\0' && _explicit_idatm_type == _computed_idatm_type) 269 281 && !(!_explicit_idatm_type.empty() && it == _explicit_idatm_type)) { 270 change_tracker()->add_modified(this, ChangeTracker::REASON_IDATM_TYPE); 282 track_change(ChangeTracker::REASON_IDATM_TYPE); 283 //change_tracker()->add_modified(this, ChangeTracker::REASON_IDATM_TYPE); 271 284 } 272 285 _explicit_idatm_type = it; 273 286 } … … inline void 276 289 Atom::set_name(const AtomName& name) { 277 290 if (name == _name) 278 291 return; 279 change_tracker()->add_modified(this, ChangeTracker::REASON_NAME); 292 track_change(ChangeTracker::REASON_NAME); 293 //change_tracker()->add_modified(this, ChangeTracker::REASON_NAME); 280 294 _name = name; 295 _changed = true; 281 296 } 282 297 283 298 inline Atom::StructCat -
src/core/atomic/atomstruct_cpp/Bond.cpp
diff --git a/src/core/atomic/atomstruct_cpp/Bond.cpp b/src/core/atomic/atomstruct_cpp/Bond.cpp index 268e3f8..dd23972 100644
a b Bond::polymeric_start_atom() const 174 174 return psa; 175 175 } 176 176 177 void 178 Bond::set_hide(int h) { 179 if (h == _hide) 180 return; 181 structure()->set_visible_bonds_changed(true); 182 Connection::set_hide(h); 183 } 184 185 void 186 Bond::set_display(bool d) { 187 if (d == _display) 188 return; 189 structure()->set_visible_bonds_changed(true); 190 Connection::set_display(d); 191 } 192 177 193 } // namespace atomstruct -
src/core/atomic/atomstruct_cpp/Bond.h
diff --git a/src/core/atomic/atomstruct_cpp/Bond.h b/src/core/atomic/atomstruct_cpp/Bond.h index 43b2fcd..b7db12c 100644
a b private: 46 46 const char* err_msg_loop() const 47 47 { return "Can't bond an atom to itself"; } 48 48 mutable Rings _rings; 49 49 bool _changed = false; 50 50 51 static int session_base_version(int /*version*/) { return 1; } 51 52 static int SESSION_NUM_INTS(int /*version*/=CURRENT_SESSION_VERSION) { return 0; } 52 53 static int SESSION_NUM_FLOATS(int /*version*/=CURRENT_SESSION_VERSION) { return 0; } 53 54 public: 55 void set_hide(int h); 56 void set_display(bool d); 54 57 virtual ~Bond() {} 55 58 virtual bool shown() const; 56 59 const Rings& all_rings(bool cross_residues = false, int size_threshold = 0, … … public: 62 65 return rings(cross_residues, 0, ignore); 63 66 } 64 67 static bool polymer_bond_atoms(Atom* first, Atom* second); 68 bool changed() const { return _changed; } 69 void set_changed(bool flag) { _changed = flag; } 65 70 Atom* polymeric_start_atom() const; 66 71 const Rings& rings(bool cross_residues = false, int all_size_threshold = 0, 67 72 std::set<const Residue*>* ignore = nullptr) const; … … public: 80 85 81 86 // change tracking 82 87 ChangeTracker* change_tracker() const; 83 void track_change(const std::string& reason) const{88 void track_change(const std::string& reason) { 84 89 change_tracker()->add_modified(this, reason); 90 this->set_changed(true); 85 91 } 86 92 87 93 // graphics related -
src/core/atomic/atomstruct_cpp/Connection.h
diff --git a/src/core/atomic/atomstruct_cpp/Connection.h b/src/core/atomic/atomstruct_cpp/Connection.h index d0ba00e..443d9cc 100644
a b public: 106 106 } 107 107 108 108 // change tracking 109 virtual void track_change(const std::string& reason) const= 0;109 virtual void track_change(const std::string& reason) = 0; 110 110 111 111 // graphics related 112 112 const Rgba& color() const { return _rgba; } -
src/core/atomic/atomstruct_cpp/CoordSet.cpp
diff --git a/src/core/atomic/atomstruct_cpp/CoordSet.cpp b/src/core/atomic/atomstruct_cpp/CoordSet.cpp index 69eac6b..94399c5 100644
a b CoordSet::session_save(int** ints, float** floats) const 130 130 void 131 131 CoordSet::set_bfactor(const Atom *a, float val) 132 132 { 133 _bfactor_map.insert(std::pair<const Atom *, float>(a, val)); 133 //_bfactor_map.insert(std::pair<const Atom *, float>(a, val)); 134 _bfactor_map[a] = val; 134 135 } 135 136 136 137 void 137 138 CoordSet::set_occupancy(const Atom *a, float val) 138 139 { 139 _occupancy_map.insert(std::pair<const Atom *, float>(a, val)); 140 //_occupancy_map.insert_or_assign(std::pair<const Atom *, float>(a, val)); 141 _occupancy_map[a] = val; 140 142 } 141 143 142 144 } // namespace atomstruct -
src/core/atomic/atomstruct_cpp/PBGroup.h
diff --git a/src/core/atomic/atomstruct_cpp/PBGroup.h b/src/core/atomic/atomstruct_cpp/PBGroup.h index f8e0eb9..cb5dc9b 100644
a b protected: 76 76 77 77 void _check_destroyed_atoms(PBGroup::Pseudobonds& pbonds, const std::set<void*>& destroyed); 78 78 void delete_pbs_check(const std::set<Pseudobond*>& pbs) const; 79 bool _changed = false; 79 80 public: 81 bool changed() const { return _changed; } 82 void set_changed(bool flag) { _changed = flag; } 80 83 virtual void clear() = 0; 81 84 virtual const Rgba& color() const { return _color; } 82 85 virtual const std::string& category() const { return _category; } -
src/core/atomic/atomstruct_cpp/Pseudobond.h
diff --git a/src/core/atomic/atomstruct_cpp/Pseudobond.h b/src/core/atomic/atomstruct_cpp/Pseudobond.h index 52cc7ae..de7d1d9 100644
a b protected: 60 60 { return "Can't form pseudobond to itself"; } 61 61 const char* err_msg_not_end() const 62 62 { return "Atom given to other_end() not in pseudobond!"; } 63 bool _changed = false; 63 64 public: 65 bool changed() const { return _changed; } 66 void set_changed(bool flag) { _changed = flag; } 64 67 ChangeTracker* change_tracker() const; 65 68 GraphicsContainer* graphics_container() const; 66 69 PBGroup* group() const { return _group; } … … public: 76 79 } 77 80 void session_restore(int version, int** ints, float** floats); 78 81 void session_save(int** ints, float** floats) const; 79 void track_change(const std::string& reason) const{82 void track_change(const std::string& reason) { 80 83 change_tracker()->add_modified(this, reason); 84 this->set_changed(true); 81 85 } 82 86 }; 83 87 -
src/core/atomic/atomstruct_cpp/Residue.h
diff --git a/src/core/atomic/atomstruct_cpp/Residue.h b/src/core/atomic/atomstruct_cpp/Residue.h index c1ec67e..a5fecaa 100644
a b private: 79 79 int _ss_id; 80 80 SSType _ss_type; 81 81 Structure * _structure; 82 bool _changed = false; 82 83 public: 84 bool changed() const { return _changed; } 85 void set_changed(bool flag) { _changed = flag; } 83 86 void add_atom(Atom*); 84 87 const Atoms& atoms() const { return _atoms; } 85 88 AtomsMap atoms_map() const; -
src/core/atomic/atomstruct_cpp/Structure.h
diff --git a/src/core/atomic/atomstruct_cpp/Structure.h b/src/core/atomic/atomstruct_cpp/Structure.h index 60ce973..caa4da8 100644
a b protected: 184 184 static int SESSION_NUM_MISC(int version=CURRENT_SESSION_VERSION) { 185 185 return version > 7 ? 3 : 4; 186 186 } 187 187 bool _visible_atoms_changed = false; 188 bool _visible_bonds_changed = false; 189 bool _changed = false; 188 190 public: 191 bool changed() const { return _changed; } 192 void set_changed(const bool& flag) { _changed = flag; } 193 bool visible_atoms_changed() const { return _visible_atoms_changed; } 194 void set_visible_atoms_changed(const bool& flag) { _visible_atoms_changed = flag; } 195 bool visible_bonds_changed() const { return _visible_bonds_changed; } 196 void set_visible_bonds_changed(const bool& flag) { _visible_bonds_changed = flag; } 197 189 198 Structure(PyObject* logger = nullptr); 190 199 virtual ~Structure(); 191 200 -
src/core/atomic/molarray.py
diff --git a/src/core/atomic/molarray.py b/src/core/atomic/molarray.py index ac0a869..a149860 100644
a b class Atoms(Collection): 342 342 "Return list of 2-tuples of (structure, Atoms for that structure)." 343 343 astruct = self.structures._pointers 344 344 return [(us, self.filter(astruct==us._c_pointer.value)) for us in self.unique_structures] 345 346 _changed = cvec_property('atom_changed', bool, doc='Changed since last redraw') 345 347 chain_ids = cvec_property('atom_chain_id', string, read_only = True) 346 348 colors = cvec_property('atom_color', uint8, 4, 347 349 doc="Returns a :mod:`numpy` Nx4 array of uint8 RGBA values. Can be set " … … class Bonds(Collection): 611 613 def __init__(self, bond_pointers = None): 612 614 Collection.__init__(self, bond_pointers, molobject.Bond, Bonds) 613 615 616 617 _changed = cvec_property('bond_changed', bool, doc='Changed since last redraw') 618 ''' 619 True if the bond or the position(s) of its atoms have been changed 620 since the last time they were drawn. 621 Returns a :mod:`numpy` array of bool. Can be set with such an array 622 (or equivalent sequence), or with a single value. 623 ''' 624 614 625 atoms = cvec_property('bond_atoms', cptr, 2, astype = _atoms_pair, read_only = True) 615 626 ''' 616 627 Returns a two-tuple of :class:`Atoms` objects. -
src/core/atomic/molc.cpp
diff --git a/src/core/atomic/molc.cpp b/src/core/atomic/molc.cpp index 4e7e24c..abb3782 100755
a b inline bool normalize(float *v) 248 248 // ------------------------------------------------------------------------- 249 249 // atom functions 250 250 // 251 252 253 extern "C" EXPORT void atom_changed(void *atoms, size_t n, npy_bool *flags) 254 { 255 Atom **a = static_cast<Atom **>(atoms); 256 error_wrap_array_get(a, n, &Atom::changed, flags); 257 } 258 259 extern "C" EXPORT void set_atom_changed (void *atoms, size_t n, npy_bool *flags) 260 { 261 Atom **a = static_cast<Atom **>(atoms); 262 error_wrap_array_set(a, n, &Atom::set_changed, flags); 263 } 264 265 251 266 extern "C" EXPORT void atom_bfactor(void *atoms, size_t n, float32_t *bfactors) 252 267 { 253 268 Atom **a = static_cast<Atom **>(atoms); … … extern "C" EXPORT PyObject *atom_intra_bonds(void *atoms, size_t n) 1024 1039 // ------------------------------------------------------------------------- 1025 1040 // bond functions 1026 1041 // 1042 1043 extern "C" EXPORT void bond_changed(void *bonds, size_t n, npy_bool *flags) 1044 { 1045 Bond **b = static_cast<Bond **>(bonds); 1046 error_wrap_array_get(b, n, &Bond::changed, flags); 1047 } 1048 1049 extern "C" EXPORT void set_bond_changed (void *bonds, size_t n, npy_bool *flags) 1050 { 1051 Bond **b = static_cast<Bond **>(bonds); 1052 error_wrap_array_set(b, n, &Bond::set_changed, flags); 1053 } 1054 1055 1027 1056 extern "C" EXPORT void bond_atoms(void *bonds, size_t n, pyobject_t *atoms) 1028 1057 { 1029 1058 Bond **b = static_cast<Bond **>(bonds); … … extern "C" EXPORT void *bond_other_atom(void *bond, void *atom) 1224 1253 // ------------------------------------------------------------------------- 1225 1254 // pseudobond functions 1226 1255 // 1256 1257 extern "C" EXPORT void pseudobond_changed(void *pbonds, size_t n, npy_bool *flags) 1258 { 1259 Pseudobond **b = static_cast<Pseudobond **>(pbonds); 1260 error_wrap_array_get(b, n, &Pseudobond::changed, flags); 1261 } 1262 1263 extern "C" EXPORT void set_pseudobond_changed (void *pbonds, size_t n, npy_bool *flags) 1264 { 1265 Pseudobond **b = static_cast<Pseudobond **>(pbonds); 1266 error_wrap_array_set(b, n, &Pseudobond::set_changed, flags); 1267 } 1268 1269 1270 1227 1271 extern "C" EXPORT void pseudobond_atoms(void *pbonds, size_t n, pyobject_t *atoms) 1228 1272 { 1229 1273 Pseudobond **b = static_cast<Pseudobond **>(pbonds); … … extern "C" EXPORT void pseudobond_global_manager_session_save_teardown(void *man 1734 1778 // ------------------------------------------------------------------------- 1735 1779 // residue functions 1736 1780 // 1781 1782 extern "C" EXPORT void residue_changed(void *residues, size_t n, npy_bool *flags) 1783 { 1784 Residue **r = static_cast<Residue **>(residues); 1785 error_wrap_array_get(r, n, &Residue::changed, flags); 1786 } 1787 1788 extern "C" EXPORT void set_residue_changed (void *residues, size_t n, npy_bool *flags) 1789 { 1790 Residue **r = static_cast<Residue **>(residues); 1791 error_wrap_array_set(r, n, &Residue::set_changed, flags); 1792 } 1793 1794 1737 1795 extern "C" EXPORT void residue_atoms(void *residues, size_t n, pyobject_t *atoms) 1738 1796 { 1739 1797 Residue **r = static_cast<Residue **>(residues); … … extern "C" EXPORT int sequence_ungapped_to_gapped(void *seq, int32_t index) 3211 3269 // ------------------------------------------------------------------------- 3212 3270 // structure functions 3213 3271 // 3272 3273 3214 3274 extern "C" EXPORT void set_structure_color(void *mol, uint8_t *rgba) 3215 3275 { 3216 3276 Structure *m = static_cast<Structure *>(mol); … … extern "C" EXPORT void structure_atoms(void *mols, size_t n, pyobject_t *atoms) 3303 3363 } 3304 3364 } 3305 3365 3366 extern "C" EXPORT void structure_visible_atoms_changed(void *mols, size_t n, npy_bool *changed) 3367 { 3368 Structure **m = static_cast<Structure **>(mols); 3369 try { 3370 for (size_t i = 0; i != n; ++i) { 3371 *changed++ = m[i]->visible_atoms_changed(); 3372 } 3373 } catch (...) { 3374 molc_error(); 3375 } 3376 } 3377 3378 extern "C" EXPORT void set_structure_visible_atoms_changed(void *mols, size_t n, npy_bool *changed) 3379 { 3380 Structure **m = static_cast<Structure **>(mols); 3381 try { 3382 for (size_t i = 0; i != n; ++i) { 3383 m[i]->set_visible_atoms_changed(*changed++); 3384 } 3385 } catch (...) { 3386 molc_error(); 3387 } 3388 } 3389 3390 extern "C" EXPORT void structure_visible_atoms(void *mols, size_t n, pyobject_t *atoms) 3391 { 3392 Structure **m = static_cast<Structure **>(mols); 3393 try { 3394 for (size_t i = 0; i != n; ++i) { 3395 const Structure::Atoms &a = m[i]->atoms(); 3396 for (size_t j = 0; j != a.size(); ++j) { 3397 if ( a[j]->visible() ) 3398 *atoms++ = a[j]; 3399 } 3400 } 3401 } catch (...) { 3402 molc_error(); 3403 } 3404 } 3405 3406 3306 3407 extern "C" EXPORT void structure_ball_scale(void *mols, size_t n, float32_t *bscales) 3307 3408 { 3308 3409 Structure **m = static_cast<Structure **>(mols); … … extern "C" EXPORT void structure_bonds(void *mols, size_t n, pyobject_t *bonds) 3334 3435 } 3335 3436 } 3336 3437 3438 extern "C" EXPORT void structure_num_bonds_visible(void *mols, size_t n, size_t *nbonds) 3439 { 3440 Structure **m = static_cast<Structure **>(mols); 3441 try { 3442 for (size_t i = 0; i != n; ++i) 3443 { 3444 const Structure::Bonds &bonds = m[i]->bonds(); 3445 int c = 0; 3446 for (auto b: bonds) 3447 if (b->shown()) 3448 c++; 3449 nbonds[i] = c; 3450 } 3451 } catch (...) { 3452 molc_error(); 3453 } 3454 } 3455 3456 extern "C" EXPORT void structure_visible_bonds(void *mols, size_t n, pyobject_t *bonds) 3457 { 3458 Structure **m = static_cast<Structure **>(mols); 3459 try { 3460 for (size_t i = 0; i != n; ++i) { 3461 const Structure::Bonds &b = m[i]->bonds(); 3462 for (size_t j = 0; j != b.size(); ++j) { 3463 if ( b[j]->shown() ) 3464 *bonds++ = b[j]; 3465 } 3466 } 3467 } catch (...) { 3468 molc_error(); 3469 } 3470 } 3471 3472 extern "C" EXPORT void structure_visible_bonds_changed(void *mols, size_t n, npy_bool *changed) 3473 { 3474 Structure **m = static_cast<Structure **>(mols); 3475 try { 3476 for (size_t i = 0; i != n; ++i) { 3477 *changed++ = m[i]->visible_bonds_changed(); 3478 } 3479 } catch (...) { 3480 molc_error(); 3481 } 3482 } 3483 3484 extern "C" EXPORT void set_structure_visible_bonds_changed(void *mols, size_t n, npy_bool *changed) 3485 { 3486 Structure **m = static_cast<Structure **>(mols); 3487 try { 3488 for (size_t i = 0; i != n; ++i) { 3489 m[i]->set_visible_bonds_changed(*changed++); 3490 } 3491 } catch (...) { 3492 molc_error(); 3493 } 3494 } 3495 3496 3337 3497 extern "C" EXPORT void structure_num_residues(void *mols, size_t n, size_t *nres) 3338 3498 { 3339 3499 Structure **m = static_cast<Structure **>(mols); -
src/core/atomic/molobject.py
diff --git a/src/core/atomic/molobject.py b/src/core/atomic/molobject.py index a4937f2..9413f68 100644
a b class Atom(State): 125 125 126 126 def atomspec(self): 127 127 return self.residue.atomspec() + '@' + self.name 128 128 129 _changed = c_property('atom_changed', bool, doc='Changed since last redraw') 129 130 alt_loc = c_property('atom_alt_loc', byte, doc='Alternate location indicator') 130 131 bfactor = c_property('atom_bfactor', float32, doc = "B-factor, floating point value.") 131 132 bonds = c_property('atom_bonds', cptr, "num_bonds", astype=_bonds, read_only=True, … … class Bond(State): 378 379 def atomspec(self): 379 380 return a1.atomspec() + a2.atomspec() 380 381 382 383 _changed = c_property('bond_changed', bool, doc='Changed since last redraw') 384 381 385 atoms = c_property('bond_atoms', cptr, 2, astype = _atom_pair, read_only = True) 382 386 '''Two-tuple of :py:class:`Atom` objects that are the bond end points.''' 383 387 color = c_property('bond_color', uint8, 4) … … class StructureData: 1463 1467 '''Index of the active coordinate set.''' 1464 1468 atoms = c_property('structure_atoms', cptr, 'num_atoms', astype = _atoms, read_only = True) 1465 1469 ''':class:`.Atoms` collection containing all atoms of the structure.''' 1470 _visible_atoms = c_property('structure_visible_atoms', cptr, 'num_atoms_visible', astype = _atoms, 1471 read_only = True) 1472 ''':class:`.Atoms` containing only the visible atoms of the structure. Read only.''' 1473 _visible_atoms_changed = c_property('structure_visible_atoms_changed', bool) 1474 '''A boolean flag indicating whether any atom has changed its visibility.''' 1466 1475 ball_scale = c_property('structure_ball_scale', float32, 1467 1476 doc = "Scales sphere radius in ball-and-stick style.") 1468 1477 bonds = c_property('structure_bonds', cptr, 'num_bonds', astype = _bonds, read_only = True) 1469 1478 ''':class:`.Bonds` collection containing all bonds of the structure.''' 1479 _visible_bonds = c_property('structure_visible_bonds', cptr, 'num_bonds_visible', astype = _bonds, 1480 read_only = True) 1481 ''':class:`.Bonds` containing only the visible bonds of the structure. Read only.''' 1482 _visible_bonds_changed = c_property('structure_visible_bonds_changed', bool) 1483 '''A boolean flag indicating whether any atom has changed its visibility.''' 1470 1484 chains = c_property('structure_chains', cptr, 'num_chains', astype = _chains, read_only = True) 1471 1485 ''':class:`.Chains` collection containing all chains of the structure.''' 1472 1486 coordset_ids = c_property('structure_coordset_ids', int32, 'num_coordsets', read_only = True) … … class StructureData: 1477 1491 '''Structure has lower case chain ids. Boolean''' 1478 1492 num_atoms = c_property('structure_num_atoms', size_t, read_only = True) 1479 1493 '''Number of atoms in structure. Read only.''' 1480 num_atoms_visible = c_property('structure_num_atoms_visible', size_t, read_only = True)1494 _num_atoms_visible = c_property('structure_num_atoms_visible', size_t, read_only = True) 1481 1495 '''Number of visible atoms in structure. Read only.''' 1482 1496 num_bonds = c_property('structure_num_bonds', size_t, read_only = True) 1483 1497 '''Number of bonds in structure. Read only.''' 1498 _num_bonds_visible = c_property('structure_num_bonds_visible', size_t, read_only = True) 1499 '''Number of visible atoms in structure. Read only.''' 1484 1500 num_coordsets = c_property('structure_num_coordsets', size_t, read_only = True) 1485 1501 '''Number of coordinate sets in structure. Read only.''' 1486 1502 num_chains = c_property('structure_num_chains', size_t, read_only = True) -
src/core/atomic/structure.py
diff --git a/src/core/atomic/structure.py b/src/core/atomic/structure.py index fb07010..fd555da 100644
a b class Structure(Model, StructureData): 54 54 self._ribbon_t2r = {} # ribbon triangles-to-residue map 55 55 self._ribbon_r2t = {} # ribbon residue-to-triangles map 56 56 self._ribbon_tether = [] # ribbon tethers from ribbon to floating atoms 57 57 58 self._cached_num_atoms_visible = self._num_atoms_visible 59 self._cached_visible_atoms = self._visible_atoms 60 self._cached_num_bonds_visible = self._num_bonds_visible 61 self._cached_visible_bonds = self._visible_bonds 62 58 63 from . import molobject 59 64 molobject.add_to_object_map(self) 60 65 … … class Structure(Model, StructureData): 64 69 ("save_teardown", "end save session")]: 65 70 self._ses_handlers.append(t.add_handler(trig_name, 66 71 lambda *args, qual=ses_func: self._ses_call(qual))) 67 72 68 73 self._make_drawing() 69 74 70 75 def __str__(self): … … class Structure(Model, StructureData): 257 262 from ..colors import most_common_color 258 263 if ribbon_displays.any(): 259 264 return most_common_color(residues.filter(ribbon_displays).ribbon_colors) 260 atoms = self.atoms261 shown = atoms.filter(atoms.displays)265 shown = self.visible_atoms 266 #shown = atoms.filter(atoms.displays) 262 267 if shown: 263 268 return most_common_color(shown.colors) 264 return most_common_color( atoms.colors)269 return most_common_color(self.atoms.colors) 265 270 def _set_single_color(self, color): 266 271 self.atoms.colors = color 267 272 self.residues.ribbon_colors = color … … class Structure(Model, StructureData): 269 274 270 275 def _make_drawing(self): 271 276 # Create graphics 272 self._update_atom_graphics() 273 self._update_bond_graphics() 274 for pbg in self.pbg_map.values(): 275 pbg._update_graphics() 276 self._create_ribbon_graphics() 277 self._update_graphics_if_needed(force_recalc = True) 278 #~ self._update_atom_graphics() 279 #~ self._update_bond_graphics() 280 #~ for pbg in self.pbg_map.values(): 281 #~ pbg._update_graphics() 282 #~ self._create_ribbon_graphics() 277 283 278 284 @property 279 285 def _level_of_detail(self): 280 286 gu = structure_graphics_updater(self.session) 281 287 return gu.level_of_detail 288 289 @property 290 def num_atoms_visible(self): 291 if self._visible_atoms_changed: 292 self._cached_num_atoms_visible = self._num_atoms_visible 293 return self._cached_num_atoms_visible 294 295 @property 296 def visible_atoms(self): 297 if self._visible_atoms_changed: 298 self._cached_visible_atoms = self._visible_atoms 299 return self._cached_visible_atoms 300 301 @property 302 def num_bonds_visible(self): 303 if self._visible_bonds_changed: 304 self._cached_num_bonds_visible = self._num_bonds_visible 305 return self._cached_num_bonds_visible 282 306 307 @property 308 def visible_bonds(self): 309 if self._visible_bonds_changed: 310 self._cached_visible_bonds = self._visible_bonds 311 return self._cached_visible_bonds 312 283 313 def new_atoms(self): 284 314 # TODO: Handle instead with a C++ notification that atoms added or deleted 285 315 self._atom_bounds_needs_update = True 286 316 287 def _update_graphics_if_needed(self, *_ ):317 def _update_graphics_if_needed(self, *_, force_recalc = False): 288 318 gc = self._graphics_changed 289 if gc == 0 :319 if gc == 0 and not force_recalc: 290 320 return 291 321 322 292 323 if gc & self._RIBBON_CHANGE: 293 324 self._create_ribbon_graphics() 294 325 # Displaying ribbon can set backbone atom hide bits producing shape change. … … class Structure(Model, StructureData): 299 330 s = (gc & self._SHAPE_CHANGE) 300 331 if gc & (self._COLOR_CHANGE | self._RIBBON_CHANGE) or s: 301 332 self._update_ribbon_tethers() 302 self._update_graphics(gc )333 self._update_graphics(gc, force_recalc = force_recalc) 303 334 self.redraw_needed(shape_changed = s, 304 335 selection_changed = (gc & self._SELECT_CHANGE)) 305 336 if s: … … class Structure(Model, StructureData): 313 344 if isinstance(surf, MolecularSurface): 314 345 surf.update_selection() 315 346 316 def _update_graphics(self, changes = StructureData._ALL_CHANGE): 317 self._update_atom_graphics(changes) 318 self._update_bond_graphics(changes) 347 def _update_graphics(self, changes = StructureData._ALL_CHANGE, force_recalc = False): 348 import numpy 349 atoms = self.visible_atoms 350 bonds = self.visible_bonds 351 force_atom_recalc = False 352 force_bond_recalc = False 353 354 if force_recalc: 355 force_atom_recalc = True 356 force_bond_recalc = True 357 358 else: 359 if self._visible_atoms_changed: 360 force_atom_recalc = True 361 self._visible_atoms_changed = False 362 363 if self._visible_bonds_changed: 364 force_bond_recalc = True 365 self._visible_bonds_changed = False 366 367 368 if force_atom_recalc: 369 achanged = numpy.array([True]*len(atoms)) 370 ch_atoms = atoms 371 else: 372 achanged = atoms._changed 373 ch_atoms = atoms[achanged] 374 375 if force_bond_recalc: 376 bchanged = numpy.array([True]*len(bonds)) 377 ch_bonds = bonds 378 else: 379 bchanged = bonds._changed 380 ch_bonds = bonds[bchanged] 381 382 383 half_bond_change_filter = numpy.concatenate((bchanged,bchanged)) 384 385 self._update_atom_graphics( ch_atoms, achanged, changes = changes, force_recalc = force_atom_recalc) 386 self._update_bond_graphics(ch_bonds, half_bond_change_filter, changes = changes, force_recalc = force_bond_recalc) 319 387 for pbg in self.pbg_map.values(): 320 388 pbg._update_graphics(changes) 321 389 self._update_ribbon_graphics() 322 390 323 def _update_atom_graphics(self, changes = StructureData._ALL_CHANGE): 324 atoms = self.atoms # optimzation, avoid making new numpy array from C++ 325 avis = atoms.visibles 391 def _update_atom_graphics(self, atoms, ch_filter, changes = StructureData._ALL_CHANGE, force_recalc = False): 392 import numpy 326 393 p = self._atoms_drawing 394 from numpy import empty, float32, multiply 395 #ch_indices = numpy.where(ch_filter)[0] 396 327 397 if p is None: 328 if avis.sum() == 0: 329 return 398 #avis = atoms.visibles 399 #if avis.sum() == 0: 400 # return 330 401 self._atoms_drawing = p = self.new_drawing('atoms') 331 402 self._atoms_drawing.custom_x3d = self._custom_atom_x3d 332 403 # Update level of detail of spheres 333 404 self._level_of_detail.set_atom_sphere_geometry(p) 405 406 if force_recalc: 407 n = len(atoms) 408 xyzr = empty((n, 4), float32) 409 xyzr[:, :3] = atoms.coords 410 xyzr[:, 3] = self._atom_display_radii(atoms) 334 411 412 from ..geometry import Places 413 p.colors = atoms.colors 414 p.positions = Places(shift_and_scale=xyzr) 415 p.display_positions = numpy.array([True]*len(atoms)) 416 p.selected_positions = atoms.selected # if atoms.num_selected > 0 else None 417 atoms._changed = False 418 return 419 420 335 421 if changes & self._SHAPE_CHANGE: 336 422 # Set instanced sphere center position and radius 337 423 n = len(atoms) 338 from numpy import empty, float32, multiply339 424 xyzr = empty((n, 4), float32) 340 425 xyzr[:, :3] = atoms.coords 341 426 xyzr[:, 3] = self._atom_display_radii(atoms) 342 427 343 428 from ..geometry import Places 344 p.positions = Places(shift_and_scale=xyzr) 345 p.display_positions = avis 429 p.positions.set_shift_and_scale(ch_filter, xyzr) 430 #p.display_positions = avis 431 346 432 347 433 if changes & (self._COLOR_CHANGE | self._SHAPE_CHANGE): 348 434 # Set atom colors 349 p. colors = atoms.colors435 p.set_colors(atoms.colors, ch_filter) 350 436 351 437 if changes & (self._SELECT_CHANGE | self._SHAPE_CHANGE): 352 438 # Set selected 353 p.selected_positions = atoms.selected if atoms.num_selected > 0 else None 439 pmask = ch_filter*False 440 pmask[ch_filter] = atoms.selected 441 p.selected_positions = pmask # atoms.selected if atoms.num_selected > 0 else None 442 atoms._changed = False 354 443 355 444 def _custom_atom_x3d(self, stream, x3d_scene, indent, place): 356 445 from numpy import empty, float32 357 446 p = self._atoms_drawing 358 atoms = self. atoms447 atoms = self.visible_atoms 359 448 radii = self._atom_display_radii(atoms) 360 449 tab = ' ' * indent 361 450 for v, xyz, r, c in zip(p.display_positions, atoms.coords, radii, p.colors): … … class Structure(Model, StructureData): 371 460 def _atom_display_radii(self, atoms): 372 461 return atoms.display_radii(self.ball_scale, self.bond_radius) 373 462 374 def _update_bond_graphics(self, changes = StructureData._ALL_CHANGE): 375 bonds = self.bonds # optimzation, avoid making new numpy array from C++ 463 def _update_bond_graphics(self, bonds, ch_filter, changes = StructureData._ALL_CHANGE, force_recalc = False): 464 import numpy 465 #ch_indices = numpy.where(ch_filter)[0] 376 466 p = self._bonds_drawing 377 467 if p is None: 378 if bonds.num_shown == 0:379 return468 #if bonds.num_shown == 0: 469 # return 380 470 self._bonds_drawing = p = self.new_drawing('bonds') 381 471 self._bonds_drawing.custom_x3d = self._custom_bond_x3d 382 472 # Update level of detail of cylinders 383 473 self._level_of_detail.set_bond_cylinder_geometry(p) 384 385 if changes & (self._SHAPE_CHANGE | self._SELECT_CHANGE):474 475 if force_recalc: 386 476 bond_atoms = bonds.atoms 387 if changes & self._SHAPE_CHANGE:388 477 ba1, ba2 = bond_atoms 478 p.colors = bonds.half_colors 389 479 p.positions = _halfbond_cylinder_placements(ba1.coords, ba2.coords, bonds.radii) 390 480 p.display_positions = _shown_bond_cylinders(bonds) 481 p.selected_positions = _selected_bond_cylinders(bond_atoms) 482 bonds._changed = False 483 return 484 485 if changes & (self._SHAPE_CHANGE | self._SELECT_CHANGE): 486 bond_atoms = bonds.atoms 487 if changes & self._SHAPE_CHANGE: 488 ba1, ba2 = bond_atoms 489 p.positions.set_opengl_matrices(ch_filter, 490 _halfbond_cylinder_placements(ba1.coords, ba2.coords, bonds.radii)._opengl_array) 491 #p.display_positions = ch_filter #_shown_bond_cylinders(bonds) 391 492 if changes & (self._COLOR_CHANGE | self._SHAPE_CHANGE): 392 p. colors = c = bonds.half_colors493 p.set_colors(bonds.half_colors, ch_filter) 393 494 if changes & (self._SELECT_CHANGE | self._SHAPE_CHANGE): 394 p.selected_positions = _selected_bond_cylinders(bond_atoms) 495 pmask = ch_filter*False 496 pmask[ch_filter] = _selected_bond_cylinders(bond_atoms) 497 p.selected_positions = pmask 498 bonds._changed = False 395 499 396 500 def _custom_bond_x3d(self, stream, x3d_scene, indent, place): 397 501 from numpy import empty, float32 398 502 p = self._bonds_drawing 399 bonds = self. bonds503 bonds = self.visible_bonds 400 504 ba1, ba2 = bonds.atoms 401 505 cyl_info = _halfbond_cylinder_x3d(ba1.coords, ba2.coords, bonds.radii) 402 506 tab = ' ' * indent … … class Structure(Model, StructureData): 1376 1480 def _update_ribbon_graphics(self): 1377 1481 # Set selected ribbons in graphics 1378 1482 from .molarray import Residues 1379 atoms = self. atoms1483 atoms = self.visible_atoms 1380 1484 if atoms.num_selected > 0: 1381 1485 residues = atoms.filter(atoms.selected).unique_residues 1382 1486 from numpy import array … … class Structure(Model, StructureData): 1450 1554 def _atom_bounds(self): 1451 1555 if not self._atom_bounds_needs_update: 1452 1556 return self._cached_atom_bounds 1453 a = self.atoms 1454 adisp = a[a.displays] 1455 xyz = adisp.coords 1456 radii = adisp.radii 1557 a = self.visible_atoms 1558 xyz = a.coords 1559 radii = a.radii 1457 1560 # TODO: Currently 40% of time is taken in getting atom radii because 1458 1561 # they are recomputed from element and bonds every time. Ticket #789. 1459 1562 # If that was fixed by using a precomputed radius, then it would make