libcootapi
 
Loading...
Searching...
No Matches
/opt/conda/conda-bld/coot-headless_1759975870518/work/api/coot-molecule.hh
1/*
2 * api/coot-molecule.hh
3 *
4 * Copyright 2020 by Medical Research Council
5 * Author: Paul Emsley
6 *
7 * This file is part of Coot
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 3 of the License, or (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copies of the GNU General Public License and
20 * the GNU Lesser General Public License along with this program; if not,
21 * write to the Free Software Foundation, Inc., 51 Franklin Street,
22 * Fifth Floor, Boston, MA, 02110-1301, USA.
23 * See http://www.gnu.org/licenses/
24 *
25 */
26
27#ifndef COOT_MOLECULE_HH
28#define COOT_MOLECULE_HH
29
30#include <utility>
31#include <atomic>
32#include <array>
33#include <set>
34
35
36#include "compat/coot-sysdep.h"
37
38#include <clipper/core/xmap.h>
39#include "utils/ctpl.h"
40#include "utils/coot-fasta.hh"
41#include "coot-utils/atom-selection-container.hh"
42#include "coot-utils/coot-rama.hh"
43#include "coot-utils/sfcalc-genmap.hh"
44#include "coot-utils/atom-tree.hh"
45#include "coot-utils/texture-as-floats.hh"
46#include "coot-utils/coot-align.hh"
47#include "geometry/residue-and-atom-specs.hh"
48#include "coords/Cartesian.hh"
49#include "coords/Bond_lines.hh"
50#include "ideal/simple-restraint.hh"
51#include "ideal/extra-restraints.hh"
52#include "coot-utils/simple-mesh.hh"
53#include "ghost-molecule-display.hh"
54
55#ifdef MAKE_ENHANCED_LIGAND_TOOLS
56#include "lidia-core/rdkit-interface.hh"
57#endif
58
59#include "density-contour/CIsoSurface.h"
60#include "gensurf.hh"
61#include "coot-utils/coot-shelx.hh"
62
63#include "coot-colour.hh" // put this in utils
64
65#include "coords/mmdb-extras.hh"
66#include "merge-molecule-results-info-t.hh"
67#include "phi-psi-prob.hh"
68
69#include "coot-utils/atom-overlaps.hh"
70#include "symmetry-info.hh" // contains cell
71
72#include "instancing.hh"
73
74#include "generic-3d-lines.hh"
75
76#include "coot-simple-molecule.hh"
77
78#include "coot-utils/coot-map-utils.hh" // for map_molecule_centre_info_t
79#include "api-cell.hh" // 20230702-PE not needed in this file - remove it from here
80
81#include "moved-atom.hh"
82#include "moved-residue.hh"
83
84#include "bond-colour.hh"
85#include "blender-mesh.hh"
86#include "user-defined-colour-table.hh"
87
88// 2023-07-04-PE This is a hack. This should be configured - and the
89// various functions that depend on this being true should be
90// reworked so that they run without a thread pool.
91
92#ifdef HAVE_BOOST_THREAD // part of DEFS in Makefile
93#define HAVE_BOOST_BASED_THREAD_POOL_LIBRARY
94#endif
95
96#include "plain-atom-overlap.hh"
97
98
99namespace coot {
100
101 enum { RESIDUE_NUMBER_UNSET = -1111}; // from molecule-class-info
102
103 class residue_range_t {
104 public:
105 residue_range_t() : res_no_start(-999), res_no_end(-999) {}
106 residue_range_t(const std::string &c, int r1, int r2) : res_no_start(r1), res_no_end(r2) {}
107 std::string chain_id;
108 int res_no_start;
109 int res_no_end;
110 };
111
112 class atom_distance_t {
113 public:
114 atom_distance_t(const atom_spec_t &a1, const atom_spec_t &a2,
115 float d) : atom_1(a1), atom_2(a2), distance(d) {}
116 atom_distance_t() : distance(-1) {}
117 atom_spec_t atom_1;
118 atom_spec_t atom_2;
119 float distance;
120 };
121
123
124 class molecule_save_info_t {
125 public:
126 // ints because we subtract from them.
127 std::pair<time_t, int> last_saved;
128 int modification_index;
129 int max_modification_index;
130 molecule_save_info_t() : last_saved(std::make_pair(0,0)), modification_index(0),
131 max_modification_index(0) {}
132 void new_modification(const std::string &mod_string) {
133 modification_index++;
134 if (false) // debugging
135 std::cout << "new_modification: moved on to " << modification_index
136 << " by " << mod_string << std::endl;
137 if (modification_index > max_modification_index)
138 max_modification_index = modification_index;
139 }
140 void made_a_save() {
141 // this is called when the server says that it has saved the file
142 last_saved.first = time(nullptr);
143 last_saved.second = modification_index;
144 }
145 bool have_unsaved_changes() const {
146 return modification_index > last_saved.second;
147 }
148 std::string index_string(int idx) const {
149 return std::to_string(idx);
150 }
151 void set_modification_index(int idx) {
152 // undo() and redo() (acutally restore_from_backup()) use this.
153 // the index is the idx number given to restore_from_backup() by
154 // the functions below
155 modification_index = idx;
156 }
157 int get_previous_modification_index() const {
158 return modification_index - 1;
159 }
160 int get_next_modification_index() const {
161 return modification_index + 1;
162 }
163 };
164
165 // molecule_save_info_t save_info;
166
167
168 class modification_info_t {
169 public:
170 class save_info_t {
171 public:
172 save_info_t(const std::string &file_name, const std::string &mis) : file_name(file_name), modification_info_string(mis) {}
173 std::string file_name;
174 std::string modification_info_string;
175 mmdb::Manager *get_mol();
176 };
177 private:
178 void init() {};
179 void print_save_info() const;
180 public:
181 modification_info_t() : backup_dir("coot-backup"), mol_name("placeholder"), is_mmcif_flag(false),
182 modification_index(0), max_modification_index(0) {}
183 modification_info_t(const std::string &mol_name_for_backup, bool is_mmcif) :
184 backup_dir("coot-backup"), mol_name(mol_name_for_backup), is_mmcif_flag(is_mmcif),
185 modification_index(0), max_modification_index(0) {}
186 std::string backup_dir;
187 std::string mol_name; // used in construction of filename, it is a stub to which we add an extension
188 bool is_mmcif_flag;
189 std::vector<save_info_t> save_info;
190 int modification_index;
191 int max_modification_index;
192 bool have_unsaved_changes() const;
193 void set_molecule_name(const std::string &molecule_name, bool is_mmcif) { mol_name = molecule_name; is_mmcif_flag = is_mmcif; }
194 std::string get_index_string(int idx) const { return std::to_string(idx); }
195 std::string get_backup_file_name_from_index(int idx) const;
197 std::string make_backup(mmdb::Manager *mol, const std::string &modification_info_string);
199 mmdb::Manager *undo(mmdb::Manager *mol);
201 mmdb::Manager *redo();
202
203 };
204
205 modification_info_t modification_info;
206
207 bool use_gemmi; // true now
208 int imol_no; // this molecule's index in the container vector
209 bool is_closed_flag;
210 int ligand_flip_number;
211 std::string name;
212 bool is_from_shelx_ins_flag;
213 ShelxIns shelxins;
214
215 std::map<residue_spec_t, int> current_rotamer_map;
216 bool really_do_backups; // default true
217
218 // private
219 void makebonds(protein_geometry *geom, rotamer_probability_tables *rotamer_tables_p,
220 const std::set<int> &no_bonds_to_these_atoms,
221 bool draw_hydrogen_atoms_flag, bool draw_missing_loops_flag);
222
223#if defined __has_builtin
224#if __has_builtin (__builtin_FUNCTION)
225 void make_bonds_type_checked(protein_geometry *geom, rotamer_probability_tables *rot_prob_tables_p, bool draw_hydrogen_atoms_flag, bool draw_missing_loops_flag, const char *s = __builtin_FUNCTION());
226 void make_bonds_type_checked(protein_geometry *geom, const std::set<int> &no_bonds_to_these_atom_indices, bool draw_hydrogen_atoms_flag, bool draw_missing_loops_flag, const char *s = __builtin_FUNCTION());
227#else
228 void make_bonds_type_checked(protein_geometry *geom, const char *s = 0);
229 void make_bonds_type_checked(protein_geometry *geom, rotamer_probability_tables *rot_prob_tables_p, bool draw_hydrogen_atoms_flag, bool draw_missing_loops_flag, const char *s = 0);
230#endif
231#else // repeat above
232 void make_bonds_type_checked(protein_geometry *geom, const char *s = 0);
233 void make_bonds_type_checked(protein_geometry *geom, rotamer_probability_tables *rot_prob_tables_p, bool draw_hydrogen_atoms_flag, bool draw_missing_loops_flag, const char *s = 0);
234#endif
235
236 api_bond_colour_t bonds_box_type; // public accessable via get_bonds_box_type(); // wass Bonds_box_type()
237 graphical_bonds_container bonds_box;
238 api_bond_colour_t get_bonds_box_type() const { return bonds_box_type; }
239
240 // this is the bond dictionary also mode.
241 // 20221011-PE force_rebonding arg is not currently used.
242 void make_colour_by_chain_bonds(protein_geometry *geom,
243 const std::set<int> &no_bonds_to_these_atoms,
244 bool change_c_only_flag,
245 bool goodsell_mode,
246 bool draw_hydrogen_atoms_flag,
247 bool draw_missing_loops_flag,
248 bool do_rota_markup=false,
249 rotamer_probability_tables *rotamer_tables_p = nullptr,
250 bool force_rebonding=true);
251 void make_ca_bonds();
252 // just a copy of the version in src
253 float bonds_colour_map_rotation;
254 // std::vector<glm::vec4> make_colour_table(bool against_a_dark_background) const; public now
255 glm::vec4 get_bond_colour_by_colour_wheel_position(int icol, api_bond_colour_t bonds_box_type) const;
256 colour_t get_bond_colour_by_mol_no(int colour_index, bool against_a_dark_background) const;
257 colour_t get_bond_colour_basic(int colour_index, bool against_a_dark_background) const;
258 bool use_bespoke_grey_colour_for_carbon_atoms;
259 colour_t bespoke_carbon_atoms_colour;
260
261 void update_map_triangles(float radius, Cartesian centre, float contour_level); // using vector of threads
262 void update_map_triangles_using_thread_pool(float radius, Cartesian centre, float contour_level, ctpl::thread_pool *thread_pool_p);
263
264 short int is_em_map_cached_flag; // -1 mean unset (so set it, 0 means no, 1 means yes)
265 short int is_em_map_cached_state(); // set is_em_map_cached_flag if not set
266 ghost_molecule_display_t map_ghost_info;
267
268 bool xmap_is_diff_map;
269 bool has_xmap() const { return is_valid_map_molecule(); }
270
271 colour_holder map_colour;
272 glm::vec4 position_to_colour_using_other_map(const clipper::Coord_orth &position,
273 const clipper::Xmap<float> &other_map_for_colouring) const;
274 float other_map_for_colouring_min_value;
275 float other_map_for_colouring_max_value;
276 glm::vec4 fraction_to_colour(float f) const; // for other map colouring - perhaps this function name is too generic?
277 bool radial_map_colour_invert_flag;
278 float radial_map_colour_saturation;
279
280 // save the data used for the fourier, so that we can use it to
281 // sharpen the map:
282 // uncommenting the following line causes a crash in the multi-molecule
283 // (expand molecule space) test.
284 bool original_fphis_filled;
285 bool original_fobs_sigfobs_filled;
286 bool original_fobs_sigfobs_fill_tried_and_failed;
287 clipper::HKL_data< clipper::datatypes::F_phi<float> > *original_fphis_p;
288 clipper::HKL_data< clipper::datatypes::F_sigF<float> > *original_fobs_sigfobs_p;
289 clipper::HKL_data< clipper::data32::Flag> *original_r_free_flags_p;
290
291 void clear_draw_vecs();
292 void clear_diff_map_draw_vecs();
293 std::vector<density_contour_triangles_container_t> draw_vector_sets;
294 std::vector<density_contour_triangles_container_t> draw_diff_map_vector_sets;
295 std::vector<std::pair<int, TRIANGLE> > map_triangle_centres; // with associated mid-points and indices
296
297 // insert coords - c.f function in molecule-class-info_t
298 void insert_coords_internal(const atom_selection_container_t &asc);
299
300 // This function no longer does a backup or updates the save_info!
301 // The calling function should do that.
302 void replace_coords(const atom_selection_container_t &asc,
303 bool change_altconf_occs_flag,
304 bool replace_coords_with_zero_occ_flag);
305 // helper function for above function
306 bool movable_atom(mmdb::Atom *mol_atom, bool replace_coords_with_zero_occ_flag) const;
307 bool moving_atom_matches(mmdb::Atom *at, int this_mol_index_maybe) const;
308 void adjust_occupancy_other_residue_atoms(mmdb::Atom *at,
309 mmdb::Residue *residue,
310 short int force_sum_1_flag);
311
312 // return -1 on failure
313 int full_atom_spec_to_atom_index(const atom_spec_t &atom_spec) const;
314 // return -1 on no atom found.
315 int full_atom_spec_to_atom_index(const std::string &chain,
316 int resno,
317 const std::string &insertion_code,
318 const std::string &atom_name,
319 const std::string &alt_conf) const;
320
321 std::string name_for_display_manager() const;
322 std::string dotted_chopped_name() const;
323 // std::string get_save_molecule_filename(const std::string &dir);
324 std::string make_backup(const std::string &modification_type); // returns warning message, otherwise empty string
325 void save_history_file_name(const std::string &file);
326 std::vector<std::string> history_filename_vec;
327 std::string save_time_string;
328 void restore_from_backup(int mod_index, const std::string &cwd);
329
330 std::vector<atom_spec_t> fixed_atom_specs;
331
332 std::pair<int, mmdb::Residue *>
333 find_serial_number_for_insert(int seqnum_for_new,
334 const std::string &ins_code_for_new,
335 const std::string &chain_id) const;
336
337 // remove TER record from residue
338 //
339 void remove_TER_internal(mmdb::Residue *res_p);
340 void remove_TER_on_last_residue(mmdb::Chain *chain_p);
341 std::pair<bool, std::string> unused_chain_id() const;
342 int append_to_molecule(const minimol::molecule &water_mol);
343
344 glm::vec4 colour_holder_to_glm(const colour_holder &ch) const;
345
346 std::pair<bool, Cartesian> get_HA_unit_vector(mmdb::Residue *r) const;
347
349 void setup_cylinder_clashes(instanced_mesh_t &im, const atom_overlaps_dots_container_t &c,
350 float ball_size, unsigned int num_subdivisions,
351 const std::string &molecule_name_stub) const;
352
354 void setup_dots(instanced_mesh_t &im,
355 const atom_overlaps_dots_container_t &c,
356 float ball_size, unsigned int num_subdivisions,
357 const std::string &molecule_name_stub) const;
358
359 // ====================== SHELX stuff ======================================
360
361 std::pair<int, std::string> write_shelx_ins_file(const std::string &filename) const;
362 int read_shelx_ins_file(const std::string &filename);
363 // return the success status, 0 for fail, 1 for good.
364 int add_shelx_string_to_molecule(const std::string &str);
365 bool is_from_shelx_ins() const { return is_from_shelx_ins_flag; }
366
367 void trim_atom_label_table();
368 void delete_ghost_selections();
369 void update_symmetry();
370 bool show_symmetry;
371
373 void delete_any_link_containing_residue(const residue_spec_t &res_spec);
374 // this doesn't do a backup - the calling function is in charge of that
375 void delete_link(mmdb::Link *link, mmdb::Model *model_p);
376
377 bool sanity_check_atoms(mmdb::Manager *mol) const; // sfcalc_genmap crashes after merge of ligand.
378 // Why? Something wrong with the atoms after merge?
379 // Let's diagnose.... Return false on non-sane.
380
381 // internal function for public rotamer functions
382 int set_residue_to_rotamer_move_atoms(mmdb::Residue *res, mmdb::Residue *moving_res);
383
384 // ====================== Jiggle-Fit (internal) ================================
385
386 float fit_to_map_by_random_jiggle(mmdb::PPAtom atom_selection,
387 int n_atoms,
388 const clipper::Xmap<float> &xmap,
389 float map_sigma,
390 int n_trials,
391 float jiggle_scale_factor,
392 bool use_biased_density_scoring,
393 std::vector<mmdb::Chain *> chains_for_moving);
394
395 minimol::molecule rigid_body_fit(const minimol::molecule &mol_in,
396 const clipper::Xmap<float> &xmap,
397 float map_sigma) const;
398
399 // ====================== validation ======================================
400
401 std::vector<coot::geometry_distortion_info_container_t>
402 geometric_distortions_from_mol(const atom_selection_container_t &asc, bool with_nbcs,
403 coot::protein_geometry &geom,
404 ctpl::thread_pool &static_thread_pool);
405
406
407 // ====================== dragged refinement ======================================
408
409 coot::restraints_container_t *last_restraints;
410
411 // ====================== init ======================================
412
413 void init() {
414 is_closed_flag = false; // changed on close_yourself()
415 // use_gemmi = true; // 20240112-PE woohoo! Let the bugs flow!
416 // 20240118 Turns out the bugs flowed too much. Let's set this back to false.
417 use_gemmi = false;
418 // set the imol before calling this function.
419 ligand_flip_number = 0;
420 bonds_box_type = api_bond_colour_t::UNSET_TYPE;
421 is_em_map_cached_flag = false;
422 xmap_is_diff_map = false;
423 is_from_shelx_ins_flag = false;
424 show_symmetry = false;
425 default_temperature_factor_for_new_atoms = 20.0;
426 original_fphis_filled = false;
427 original_fobs_sigfobs_filled = false;
428 original_fobs_sigfobs_fill_tried_and_failed = false;
429 original_fphis_p = nullptr;
430 original_fobs_sigfobs_p = nullptr;
431 original_r_free_flags_p = nullptr;
432 refmac_r_free_flag_sensible = false;
433 use_bespoke_grey_colour_for_carbon_atoms = false;
434 really_do_backups = true;
435
436 radial_map_colour_saturation = 0.5;
437 radial_map_colour_invert_flag = false;
438
439 other_map_for_colouring_min_value = 0.0;
440 other_map_for_colouring_max_value = 1.0;
441
442 map_colour = colour_holder(0.3, 0.3, 0.7);
443 last_restraints = nullptr;
444
445 float rotate_colour_map_on_read_pdb = 0.24;
446 bonds_colour_map_rotation = (imol_no + 1) * rotate_colour_map_on_read_pdb;
447 while (bonds_colour_map_rotation > 360.0)
448 bonds_colour_map_rotation -= 360.0;
449
450 base_colour_for_bonds = colour_holder(0.43, 0.33, 0.2);
451
452 fill_default_colour_rules();
453 if (false) {
454 auto v = get_colour_rules();
455 std::cout << "colour rules: " << std::endl;
456 std::cout << "-------------" << std::endl;
457 for (unsigned int i=0; i<v.size(); i++) {
458 std::cout << i << " " << v[i].first << " " << v[i].second << std::endl;
459 }
460 std::cout << "-------------" << std::endl;
461 }
462
463 indexed_user_defined_colour_selection_cids_apply_to_non_carbon_atoms_also = true;
464
465 gltf_pbr_roughness = 0.2;
466 gltf_pbr_metalicity = 0.0;
467
468 }
469
470 // chain-id (maybe) and plain sequence.
471 coot::fasta_multi multi_fasta_seq;
472
473 static std::string file_to_string(const std::string &fn);
474
475 public:
476
477 // ---------------------------------------------------------------------------------------------------------------
478 // ---------------------------------------------------------------------------------------------------------------
479 // public
480 // ---------------------------------------------------------------------------------------------------------------
481 // ---------------------------------------------------------------------------------------------------------------
482
483 // enum refine_residues_mode {SINGLE, TRIPLE, QUINTUPLE, HEPTUPLE, SPHERE, BIG_SPHERE, CHAIN, ALL};
484
485 atom_selection_container_t atom_sel;
486 // set this on reading a pdb file
487 float default_temperature_factor_for_new_atoms; // direct access
488
489 // for rsr neighbours - they are fixed.
490 std::vector<std::pair<bool, mmdb::Residue *> > neighbouring_residues;
491
493 molecule_t(const std::string &name_in, int mol_no_in) : name(name_in) {imol_no = mol_no_in; init(); }
495 molecule_t(const std::string &name_in, int mol_no_in, short int is_em_map) : name(name_in) {
496 imol_no = mol_no_in; init(); is_em_map_cached_flag = is_em_map; }
497
498 molecule_t(const std::string &name_in, int mol_no_in, const clipper::Xmap<float> &xmap_in, bool is_em_map_flag)
499 : name(name_in), xmap(xmap_in) {imol_no = mol_no_in; init(); is_em_map_cached_flag = is_em_map_flag; }
500
501 explicit molecule_t(atom_selection_container_t asc, int imol_no_in, const std::string &name_in) : name(name_in), atom_sel(asc) {
502 imol_no = imol_no_in;
503 init();
504 default_temperature_factor_for_new_atoms =
505 util::median_temperature_factor(atom_sel.atom_selection,
506 atom_sel.n_selected_atoms,
507 99999.9, 0.0, false, false);
508 }
509
510 float get_median_temperature_factor() const;
511
512 float get_temperature_factor_of_atom(const std::string &atom_cid) const;
513
514 // ------------------------ close
515
516 int close_yourself();
517
518 bool is_closed() const { return is_closed_flag; }
519
520 // --------------------- backups
521
522 void set_really_do_backups(bool state) { really_do_backups = state; }
523
524 // ------------------------------- rsr utils
525 // - add in the environment of this fragment molecule
526 // from the residue from which this fragment was copied
527 void add_neighbor_residues_for_refinement_help(mmdb::Manager *mol);
528
529 // ----------------------- structure factor stuff ------------------------------------------------------
530
531 void fill_fobs_sigfobs(); // re-reads MTZ file (currently 20210816-PE)
532
533 // used to be a const ref. Now return the whole thing!. Caller must call
534 // fill_fobs_sigfobs() directly before using this function - meh, not a good API.
535 // Return a *pointer* to the data so that we don't get this hideous non-reproducable
536 // crash when we access this data item after the moelcule vector has been resized
537 // 20210816-PE.
538 // CAUTION: this function can throw a std::runtime_error.
539 clipper::HKL_data<clipper::data32::F_sigF> *get_original_fobs_sigfobs() const {
540 if (!original_fobs_sigfobs_filled) {
541 std::string m("Original Fobs/sigFobs is not filled");
542 throw(std::runtime_error(m));
543 }
544 return original_fobs_sigfobs_p;
545 }
546
547 clipper::HKL_data<clipper::data32::Flag> *get_original_rfree_flags() const {
548 if (!original_fobs_sigfobs_filled) {
549 std::string m("Original Fobs/sigFobs is not filled - so no RFree flags");
550 throw(std::runtime_error(m));
551 }
552 return original_r_free_flags_p;
553 }
554 // use this molecules mol and the passed data to make a map for some other
555 // molecule
556 int sfcalc_genmap(const clipper::HKL_data<clipper::data32::F_sigF> &fobs,
557 const clipper::HKL_data<clipper::data32::Flag> &free,
558 clipper::Xmap<float> *xmap_p);
559 util::sfcalc_genmap_stats_t
560 sfcalc_genmaps_using_bulk_solvent(const clipper::HKL_data<clipper::data32::F_sigF> &fobs,
561 const clipper::HKL_data<clipper::data32::Flag> &free,
562 clipper::Xmap<float> *xmap_2fofc_p,
563 clipper::Xmap<float> *xmap_fofc_p);
564 // String munging helper function (for reading mtz files).
565 // Return a pair.first string of length 0 on error to construct dataname(s).
566 std::pair<std::string, std::string> make_import_datanames(const std::string &fcol,
567 const std::string &phi_col,
568 const std::string &weight_col,
569 int use_weights) const;
570 // make these private?
571 std::string refmac_fobs_col;
572 std::string refmac_sigfobs_col;
573 std::string refmac_mtz_filename;
574 std::string refmac_r_free_col;
575 std::string Refmac_fobs_col() const { return refmac_fobs_col; }
576 std::string Refmac_sigfobs_col() const { return refmac_sigfobs_col; }
577 std::string Refmac_mtz_filename() const { return refmac_mtz_filename; }
578 bool refmac_r_free_flag_sensible;
579
580 void associate_data_mtz_file_with_map(const std::string &data_mtz_file_name,
581 const std::string &f_col, const std::string &sigf_col,
582 const std::string &r_free_col);
583
584 // ----------------------- xmap
585
586 clipper::Xmap<float> xmap; // public because the filling function needs access
587
588 // public access to the lock (from threads)
589 static std::atomic<bool> draw_vector_sets_lock;
590
591 util::map_molecule_centre_info_t get_map_molecule_centre() const;
592
593 // ----------------------- utils
594
595 void replace_molecule_by_model_from_file(const std::string &pdb_file_name);
596
597 std::string get_name() const { return name; }
598 void set_molecule_name(const std::string &n) { name = n; };
599 int get_molecule_index() const { return imol_no; }
600 // void set_molecule_index(int idx) { imol_no = idx; } // 20221011-PE needed?
601 bool is_valid_model_molecule() const;
602 bool is_valid_map_molecule() const;
603 unsigned int get_number_of_atoms() const;
604 int get_number_of_hydrogen_atoms() const;
605 float get_molecule_diameter() const;
613
615 std::vector<std::string> get_types_in_molecule() const;
616 mmdb::Residue *cid_to_residue(const std::string &cid) const;
617 std::vector<mmdb::Residue *> cid_to_residues(const std::string &cid) const;
618 mmdb::Atom *cid_to_atom(const std::string &cid) const;
619 std::pair<bool, residue_spec_t> cid_to_residue_spec(const std::string &cid) const;
620 std::pair<bool, atom_spec_t> cid_to_atom_spec(const std::string &cid) const;
621 std::vector<std::string> get_residue_names_with_no_dictionary(const protein_geometry &geom) const;
622 // here res-name might be HOH or DUM
623 int insert_waters_into_molecule(const minimol::molecule &water_mol, const std::string &res_name);
624
625 // ----------------------- model utils
626
631 std::vector<residue_range_t> get_missing_residue_ranges() const;
632
633 // public
634 void make_bonds(protein_geometry *geom, rotamer_probability_tables *rot_prob_tables_p,
635 bool draw_hydrogen_atoms_flag, bool draw_missing_loops_flag);
636
638 std::vector<glm::vec4> make_colour_table(bool against_a_dark_background) const;
639 std::vector<glm::vec4> make_colour_table_for_goodsell_style(float colour_wheel_rotation_step,
640 float saturation, float goodselliness) const;
641
642 // for debugging
643 void print_colour_table(const std::string &debugging_label) const;
644
645 // print_secondary_structure_info
646 void print_secondary_structure_info() const;
647
648 // returns either the specified atom or null if not found
649 mmdb::Atom *get_atom(const atom_spec_t &atom_spec) const;
650 // returns either the specified residue or null if not found
651 mmdb::Residue *get_residue(const residue_spec_t &residue_spec) const;
652
653 // can return null
654 mmdb::Residue *get_residue(const std::string &residue_cid) const;
655
656 std::string get_residue_name(const residue_spec_t &residue_spec) const;
657
658 bool have_unsaved_changes() const { return modification_info.have_unsaved_changes(); }
659 int undo(); // 20221018-PE return status not yet useful
660 int redo(); // likewise
661 // the return value of WritePDBASCII() or WriteCIFASCII(). mmdb return type
662 int write_coordinates(const std::string &file_name) const; // return 0 on OK, 1 on failure
663
665 std::string molecule_to_PDB_string() const;
666
668 std::string molecule_to_mmCIF_string() const;
669
670 std::vector<atom_spec_t> get_fixed_atoms() const;
671
672 std::vector<std::string> chains_in_model() const;
673 std::vector<std::pair<residue_spec_t, std::string> > get_single_letter_codes_for_chain(const std::string &chain_id) const;
674
675 residue_spec_t get_residue_closest_to(mmdb::Manager *mol, const clipper::Coord_orth &co) const;
676
677 std::vector<std::string> get_chain_ids() const;
678
680 std::vector<std::vector<std::string> > get_ncs_related_chains() const;
681
683 bool copy_ncs_chain(const std::string &from_chain_id, const std::string &to_chain_id);
684
688 std::vector<double> get_residue_CA_position(const std::string &cid) const;
689
693 std::vector<double> get_residue_average_position(const std::string &cid) const;
694
698 std::vector<double> get_residue_sidechain_average_position(const std::string &cid) const;
699
706 void set_occupancy(const std::string &cid, float occ_new);
707
708 // ----------------------- model bonds
709
710 simple_mesh_t get_bonds_mesh(const std::string &mode, protein_geometry *geom,
711 bool against_a_dark_background,
712 float bonds_width, float atom_radius_to_bond_width_ratio,
713 int smoothness_factor,
714 bool draw_hydrogen_atoms_flag,
715 bool draw_missing_residue_loops);
716
717 simple_mesh_t get_goodsell_style_mesh(protein_geometry *geom_p, float colour_wheel_rotation_step,
718 float saturation, float goodselliness);
719
720 instanced_mesh_t get_bonds_mesh_instanced(const std::string &mode, protein_geometry *geom,
721 bool against_a_dark_background,
722 float bonds_width, float atom_radius_to_bond_width_ratio,
723 bool render_atoms_as_aniso, // if possible, of course
724 float aniso_probability,
725 bool render_aniso_atoms_as_ortep,
726 int smoothness_factor,
727 bool draw_hydrogen_atoms_flag,
728 bool draw_missing_residue_loops);
729
730 instanced_mesh_t get_bonds_mesh_for_selection_instanced(const std::string &mode, const std::string &selection_cid,
731 protein_geometry *geom,
732 bool against_a_dark_background,
733 float bonds_width, float atom_radius_to_bond_width_ratio,
734 bool render_atoms_as_aniso, // if possible, of course
735 bool render_aniso_atoms_as_ortep,
736 int smoothness_factor,
737 bool draw_hydrogen_atoms_flag,
738 bool draw_missing_residue_loops);
739
740 instanced_mesh_t get_goodsell_style_mesh_instanced(protein_geometry *geom_p, float colour_wheel_rotation_step,
741 float saturation, float goodselliness);
742
743
744 // adding colours using the functions below add into user_defined_colours
745 std::map<unsigned int, colour_holder> user_defined_bond_colours;
746
747 // we store these variables so that they can be used by (temporary) molecules constructed from atom selections
748 //
749 std::vector<std::pair<std::string, unsigned int> > indexed_user_defined_colour_selection_cids;
750 bool indexed_user_defined_colour_selection_cids_apply_to_non_carbon_atoms_also;
751
755 void set_user_defined_bond_colours(const std::map<unsigned int, std::array<float, 4> > &colour_map);
756
758 // make this static?
759 void set_user_defined_atom_colour_by_selections(const std::vector<std::pair<std::string, unsigned int> > &indexed_residues_cids,
760 bool colour_applies_to_non_carbon_atoms_also,
761 mmdb::Manager *mol);
762
763 // need not be public
764 void store_user_defined_atom_colour_selections(const std::vector<std::pair<std::string, unsigned int> > &indexed_residues_cids,
765 bool colour_applies_to_non_carbon_atoms_also);
766
767 void apply_user_defined_atom_colour_selections(const std::vector<std::pair<std::string, unsigned int> > &indexed_residues_cids,
768 bool colour_applies_to_non_carbon_atoms_also,
769 mmdb::Manager *mol);
770
773
774 colour_holder base_colour_for_bonds;
775
777 void set_base_colour_for_bonds(float r, float g, float b);
778
779 std::set<int> no_bonds_to_these_atom_indices;
780
781 void add_to_non_drawn_bonds(const std::string &atom_selection_cid);
782
783 void clear_non_drawn_bonds() { no_bonds_to_these_atom_indices.clear(); }
784
785 void print_non_drawn_bonds() const;
786
787 void fill_default_colour_rules(); // assign colours to chains.
788
793 std::vector<std::pair<std::string, std::string> > colour_rules;
794
796 void add_colour_rule(const std::string &selection, const std::string &colour_name);
797
800
801 void print_colour_rules() const;
802
805 std::vector<std::pair<std::string, std::string> > get_colour_rules() const;
806
807 std::vector<std::pair<std::string, float> > M2T_float_params;
808 std::vector<std::pair<std::string, int> > M2T_int_params;
809
811 void M2T_updateFloatParameter(const std::string &param_name, float value);
812
814 void M2T_updateFloatParameter(const std::string &param_name, int value);
815
816 void print_M2T_FloatParameters() const;
817
818 void print_M2T_IntParameters() const;
819
821 void M2T_updateIntParameter(const std::string &param_name, int value);
822
823 simple_mesh_t get_molecular_representation_mesh(const std::string &cid,
824 const std::string &colour_scheme,
825 const std::string &style,
826 int secondaryStructureUsageFlag) const;
827
828 simple_mesh_t get_gaussian_surface(float sigma, float contour_level,
829 float box_radius, float grid_scale, float fft_b_factor) const;
830
831 simple_mesh_t get_chemical_features_mesh(const std::string &cid, const protein_geometry &geom) const;
832
833 bool hydrogen_atom_should_be_drawn() const { return false; } // 20221018-PE for now.
834 void set_use_bespoke_carbon_atom_colour(bool state) {
835 use_bespoke_grey_colour_for_carbon_atoms = state;
836 // make_bonds_type_checked("set_use_bespoke_carbon_atom_colour");
837 }
838 void set_bespoke_carbon_atom_colour(const colour_t &col) {
839 bespoke_carbon_atoms_colour = col;
840 // make_bonds_type_checked("set_bespoke_carbon_atom_colour");
841 }
842
844 void export_map_molecule_as_gltf(clipper::Coord_orth &position,
845 float radius, float contour_level,
846 const std::string &file_name);
847
849 void export_model_molecule_as_gltf(const std::string &mode,
850 const std::string &selection_cid,
851 protein_geometry *geom,
852 bool against_a_dark_background,
853 float bonds_width, float atom_radius_to_bond_width_ratio, int smoothness_factor,
854 bool draw_hydrogen_atoms_flag, bool draw_missing_residue_loops,
855 const std::string &file_name);
856
857 // this is the ribbons and surfaces API
858 void export_molecular_representation_as_gltf(const std::string &atom_selection_cid,
859 const std::string &colour_scheme,
860 const std::string &style,
861 int secondary_structure_usage_flag,
862 const std::string &file_name);
863
864 void export_chemical_features_as_gltf(const std::string &cid,
865 const protein_geometry &geom,
866 const std::string &file_name) const;
867
868 float gltf_pbr_roughness;
869 float gltf_pbr_metalicity;
870
871 void set_show_symmetry(bool f) { show_symmetry = f;}
872 bool get_show_symmetry() { return show_symmetry;}
873 void transform_by(mmdb::mat44 SSMAlign_TMatrix);
874 void transform_by(const clipper::RTop_orth &rtop, mmdb::Residue *res);
875 void transform_by(const clipper::RTop_orth &rtop);
876
877 symmetry_info_t get_symmetry(float symmetry_search_radius, const Cartesian &symm_centre) const;
878
879 // ----------------------- model analysis functions
880
881 std::vector<std::string> non_standard_residue_types_in_model() const;
882 std::vector<phi_psi_prob_t> ramachandran_validation(const ramachandrans_container_t &rc) const;
883 // not const because it recalculates the bonds.
884 simple_mesh_t get_rotamer_dodecs(protein_geometry *geom_p, rotamer_probability_tables *rpt);
885
886 instanced_mesh_t get_rotamer_dodecs_instanced(protein_geometry *geom_p, rotamer_probability_tables *rpt);
887
888 omega_distortion_info_container_t peptide_omega_analysis(const protein_geometry &geom,
889 const std::string &chain_id,
890 bool mark_cis_peptides_as_bad_flag) const;
891
892 std::vector<residue_spec_t> get_non_standard_residues_in_molecule() const;
893
894 std::vector<std::string> get_residue_types_without_dictionaries(const protein_geometry &geom) const;
895
897 instanced_mesh_t contact_dots_for_ligand(const std::string &cid, const protein_geometry &geom,
898 unsigned int num_subdivisions) const;
899
901 instanced_mesh_t all_molecule_contact_dots(const coot::protein_geometry &geom,
902 unsigned int num_subdivisions) const;
903
905 make_exportable_environment_bond_box(coot::residue_spec_t &spec, float max_dist, coot::protein_geometry &geom) const;
906
910 simple::molecule_t get_simple_molecule(int imol, const std::string &residue_cid,
911 const bool draw_hydrogen_atoms_flag,
912 coot::protein_geometry *geom_p);
913 // which call this function:
914 simple::molecule_t get_simple_molecule(int imol, mmdb::Residue *residue_p,
915 bool draw_hydrogen_atoms_flag,
916 coot::protein_geometry *geom_p);
917
921 // We need the thread pool?
923 coot::protein_geometry &geom,
924 ctpl::thread_pool &static_thread_pool);
925
930 std::vector<coot::geometry_distortion_info_container_t>
931 geometric_distortions_for_one_residue_from_mol(const std::string &ligand_cid, bool with_nbcs,
932 coot::protein_geometry &geom,
933 ctpl::thread_pool &static_thread_pool);
934
939 std::vector<coot::geometry_distortion_info_container_t>
940 geometric_distortions_for_selection_from_mol(const std::string &selection_cid, bool with_nbcs,
941 coot::protein_geometry &geom,
942 ctpl::thread_pool &static_thread_pool);
943
944 // I want a function that does the evaluation of the distortion
945 // in place - I don't want to get a function that allows me to
946 // calculate the distortion from the restraints.
947 //
948 std::pair<int, double>
949 simple_geometric_distortions_from_mol(const std::string &ligand_cid, bool with_nbcs,
950 coot::protein_geometry &geom,
951 ctpl::thread_pool &static_thread_pool);
952
953 coot::instanced_mesh_t get_extra_restraints_mesh(int mode) const;
954
956 std::vector<coot::residue_spec_t> residues_near_residue(const std::string &residue_cid, float dist) const;
957
960 std::vector<coot::atom_distance_t>
961 get_distances_between_atoms_of_residues(const std::string &cid_res_1,
962 const std::string &cid_res_2,
963 float dist_max) const;
964
966 std::vector<plain_atom_overlap_t> get_overlaps(protein_geometry *geom_p);
967
969 float get_atom_overlap_score(protein_geometry *geom_p) const;
970
972 std::vector<plain_atom_overlap_t> get_overlaps_for_ligand(const std::string &cid_ligand,
973 protein_geometry *geom_p);
974
976 coot::atom_overlaps_dots_container_t get_overlap_dots(protein_geometry *geom_p);
977
979 coot::atom_overlaps_dots_container_t get_overlap_dots_for_ligand(const std::string &cid_ligand,
980 protein_geometry *geom_p);
981
982 instanced_mesh_t get_HOLE(const clipper::Coord_orth &start_pos,
983 const clipper::Coord_orth &end_pos,
984 const protein_geometry &geom) const;
985
993 std::string get_svg_for_2d_ligand_environment_view(const std::string &residue_cid,
994 protein_geometry *geom,
995 bool add_key) const;
996
997
998#ifdef MAKE_ENHANCED_LIGAND_TOOLS
1001 RDKit::ROMol *rdkit_mol(const std::string &ligand_cid);
1002#endif
1003
1004 // ------------------------ model-changing functions
1005
1006 int move_molecule_to_new_centre(const coot::Cartesian &new_centre);
1007 coot::Cartesian get_molecule_centre() const;
1008
1009 int flip_peptide(const atom_spec_t &rs, const std::string &alt_conf);
1010 int auto_fit_rotamer(const std::string &chain_id, int res_no, const std::string &ins_code,
1011 const std::string &alt_conf,
1012 const clipper::Xmap<float> &xmap, const coot::protein_geometry &pg);
1013
1014 std::pair<bool,float> backrub_rotamer(mmdb::Residue *residue_p,
1015 const clipper::Xmap<float> &xmap,
1016 const coot::protein_geometry &pg);
1017
1018 std::pair<bool,float> backrub_rotamer(const std::string &chain_id, int res_no,
1019 const std::string &ins_code, const std::string &alt_conf,
1020 const clipper::Xmap<float> &xmap,
1021 const coot::protein_geometry &pg);
1022
1023 // return the number of deleted atoms
1024 int delete_atoms(const std::vector<atom_spec_t> &atoms);
1025 int delete_atom(atom_spec_t &atom_spec);
1026 int delete_residue(residue_spec_t &residue_spec);
1027 int delete_residue_atoms_with_alt_conf(coot::residue_spec_t &residue_spec, const std::string &alt_conf);
1028 int delete_chain_using_atom_cid(const std::string &cid);
1029 int delete_literal_using_cid(const std::string &cid); // cid is an atom selection, e.g. containing a residue range
1030
1031 int change_alt_locs(const std::string &cid, const std::string &change_mode);
1032
1033 std::pair<int, std::string> add_terminal_residue_directly(const residue_spec_t &spec,
1034 const std::string &new_res_type,
1035 const protein_geometry &geom,
1036 const clipper::Xmap<float> &xmap,
1037 mmdb::Manager *standard_residues_asc_mol, // for RNA
1038 ctpl::thread_pool &static_thread_pool);
1039
1040 void execute_simple_nucleotide_addition(const std::string &term_type,
1041 mmdb::Residue *res_p, const std::string &chain_id,
1042 mmdb::Manager *standard_residues_asc_mol);
1043 void execute_simple_nucleotide_addition(mmdb::Residue *residue_p,
1044 mmdb::Manager *standard_residues_asc_mol);
1045 void execute_simple_nucleotide_addition(const std::string &cid,
1046 mmdb::Manager *standard_residues_asc_mol);
1047
1048 int add_compound(const dictionary_residue_restraints_t &monomer_restraints, const Cartesian &position,
1049 const clipper::Xmap<float> &xmap, float map_rmsd);
1050
1051
1053 int add_alternative_conformation(const std::string &cid);
1054
1056 int fill_partial_residue(const residue_spec_t &res_spec, const std::string &alt_conf,
1057 const clipper::Xmap<float> &xmap, const protein_geometry &geom);
1058
1060 int fill_partial_residues(const clipper::Xmap<float> &xmap, protein_geometry *geom);
1061
1062 int mutate(const residue_spec_t &spec, const std::string &new_res_type);
1063
1064 void add_named_glyco_tree(const std::string &glycosylation_name, const std::string &chain_id, int res_no,
1065 const clipper::Xmap<float> &xmap, protein_geometry *geom);
1066
1067 int side_chain_180(const residue_spec_t &residue_spec, const std::string &alt_conf,
1068 coot::protein_geometry *geom_p); // sub functions are non-const
1069
1070 int delete_side_chain(const residue_spec_t &residue_spec);
1071
1072 std::string jed_flip(coot::residue_spec_t &spec, const std::string &atom_name, const std::string &alt_conf,
1073 bool invert_selection, protein_geometry *geom);
1074
1075 // move this up
1076 std::string jed_flip_internal(coot::atom_tree_t &tree,
1077 const std::vector<coot::dict_torsion_restraint_t> &interesting_torsions,
1078 const std::string &atom_name,
1079 bool invert_selection);
1080
1081 // return a non-null string on a problem
1082 std::string jed_flip_internal(coot::atom_tree_t &tree,
1083 const dict_torsion_restraint_t &torsion,
1084 const std::string &atom_name,
1085 bool invert_selection);
1086
1087 // manipulate the torsion angles of first residue in this molecule to
1088 // match those of the passed (reference residue (from a different
1089 // molecule, typically). This function presumes that this molecule
1090 // contains just a ligand.
1091 // @return the number of torsion angles changed
1092 int match_torsions(mmdb::Residue *res_ref,
1093 const std::vector <coot::dict_torsion_restraint_t> &tr_ligand,
1094 const coot::protein_geometry &geom);
1095
1096 coot::minimol::molecule eigen_flip_residue(const residue_spec_t &residue_spec);
1097
1098 int apply_transformation_to_atom_selection(const std::string &atom_selection_cid,
1099 int n_atoms_in_selection,
1100 clipper::Coord_orth &rotation_centre,
1101 clipper::RTop_orth &rtop);
1102
1105 void multiply_residue_temperature_factors(const std::string &cid, float factor);
1106
1108 int add_hydrogen_atoms(protein_geometry *geom); // because of coot::reduce api - hmm.
1109
1112
1117
1126 bool residue_is_nucleic_acid(const std::string &cid) const;
1127
1128 // change the chain id
1129 // return -1 on a conflict
1130 // 1 on good.
1131 // 0 on did nothing
1132 // return also an information/error message
1133 std::pair<int, std::string> change_chain_id(const std::string &from_chain_id,
1134 const std::string &to_chain_id,
1135 bool use_resno_range,
1136 int start_resno, int end_resno);
1137
1138 // make these private
1139 //
1140 std::pair<int, std::string>
1141 change_chain_id_with_residue_range(const std::string &from_chain_id,
1142 const std::string &to_chain_id,
1143 int start_resno,
1144 int end_resno);
1145 void change_chain_id_with_residue_range_helper_insert_or_add(mmdb::Chain *to_chain_p, mmdb::Residue *new_residue);
1146
1148 int new_positions_for_residue_atoms(const std::string &residue_cid, const std::vector<api::moved_atom_t> &moved_atoms);
1149
1151 int new_positions_for_atoms_in_residues(const std::vector<api::moved_residue_t> &moved_residues);
1152
1156 int new_positions_for_residue_atoms(mmdb::Residue *residue_p, const std::vector<api::moved_atom_t> &moved_atoms,
1157 bool do_backup);
1158
1161 int merge_molecules(const std::vector<mmdb::Manager *> &mols);
1162
1163 // My ligands don't jiggle-jiggle...
1164 //
1165 // Hey, what do you know, they actually do.
1166 float fit_to_map_by_random_jiggle(const residue_spec_t &res_spec, const clipper::Xmap<float> &xmap, float map_rmsd,
1167 int n_trials, float translation_scale_factor);
1168
1172 float fit_to_map_by_random_jiggle_using_atom_selection(const std::string &cid, const clipper::Xmap<float> &xmap, float map_rmsd,
1173 int n_trials, float translation_scale_factor);
1174
1175 int cis_trans_conversion(const std::string &atom_cid, mmdb::Manager *standard_residues_mol);
1176
1177 int replace_residue(const std::string &residue_cid, const std::string &new_residue_type, int imol_enc,
1178 const protein_geometry &geom);
1179
1180 // the above is a wrapper for this:
1181 // (which was a scripting function and now has been moved into coot utils)
1182 int mutate_by_overlap(mmdb::Residue *residue_p, const dictionary_residue_restraints_t &restraints);
1183
1185 int replace_fragment(atom_selection_container_t asc);
1186
1187 // replace the atoms of SelHnd, which is a selection of mol_ref into this molecule.
1188 // Use old_atom_index_handle for fast indexing.
1189 int replace_fragment(mmdb::Manager *mol_ref, int old_atom_index_handle, int SelHnd);
1190
1192 class rotamer_change_info_t {
1193 public:
1195 int rank;
1197 std::string name;
1202 rotamer_change_info_t(int rank, const std::string &name, float rp, int status) : rank(rank), name(name), richardson_probability(rp), status(status) {}
1203 rotamer_change_info_t() : rank(-1), name(""), richardson_probability(-1), status(0) {}
1204 };
1205
1207 rotamer_change_info_t change_to_next_rotamer(const coot::residue_spec_t &res_spec, const std::string &alt_conf, const coot::protein_geometry &pg);
1208
1209 rotamer_change_info_t change_to_previous_rotamer(const coot::residue_spec_t &res_spec, const std::string &alt_conf, const coot::protein_geometry &pg);
1210
1211 rotamer_change_info_t change_to_first_rotamer(const coot::residue_spec_t &res_spec, const std::string &alt_conf, const coot::protein_geometry &pg);
1212
1213 // rotamer_change_direction is 1 for increase rotamer index
1214 // rotamer_change_direction is -1 for decrease rotamer index
1215 // rotamer_change_direction is 0 for change to 0th
1216 // index cycling is handled by the function
1217 //
1218 rotamer_change_info_t change_rotamer_number(const coot::residue_spec_t &res_spec, const std::string &alt_conf,
1219 int rotamer_change_direction,
1220 const coot::protein_geometry &pg);
1221
1222 void associate_sequence_with_molecule(const std::string &chain_id, const std::string &sequence);
1223
1225 void assign_sequence(const clipper::Xmap<float> &xmap, const coot::protein_geometry &geom);
1226
1228 std::vector<std::pair<std::string, std::string> > get_sequence_info() const;
1229
1231 chain_mutation_info_container_t get_mutation_info() const;
1232
1233 // ----------------------- merge molecules
1234
1235 // merge molecules helper functions
1236
1237 bool is_het_residue(mmdb::Residue *residue_p) const;
1238 // return state, max_resno + 1, or 0, 1 of no residues in chain.
1239 //
1240 std::pair<short int, int> next_residue_number_in_chain(mmdb::Chain *w,
1241 bool new_res_no_by_hundreds=false) const;
1242
1243 mmdb::Residue *copy_and_add_residue_to_chain(mmdb::Chain *this_model_chain,
1244 mmdb::Residue *add_model_residue,
1245 bool new_resno_by_hundreds_flag=true);
1246 void copy_and_add_chain_residues_to_chain(mmdb::Chain *new_chain, mmdb::Chain *this_molecule_chain);
1247 std::vector<std::string> map_chains_to_new_chains(const std::vector<std::string> &adding_model_chains,
1248 const std::vector<std::string> &this_model_chains) const;
1249 // that's too complicated for try_add_by_consolidation(), we just want this:
1250 std::string suggest_new_chain_id(const std::string &current_chain_id) const;
1251 std::pair<bool, std::vector<std::string> > try_add_by_consolidation(mmdb::Manager *adding_mol);
1252 bool merge_molecules_just_one_residue_homogeneous(atom_selection_container_t molecule_to_add);
1253 bool merge_molecules_just_one_residue_at_given_spec(atom_selection_container_t molecule_to_add,
1254 residue_spec_t target_spec);
1255
1256 // return success status and spec if new residue if possible.
1257 std::pair<bool, coot::residue_spec_t> merge_ligand_to_near_chain(mmdb::Manager *mol);
1258
1259 // return success status and spec if new residue if possible.
1260 std::pair<int, std::vector<merge_molecule_results_info_t> >
1261 merge_molecules(const std::vector<atom_selection_container_t> &add_molecules);
1262
1263
1264 std::pair<int, double>
1265 get_torsion(const std::string &cid, const std::vector<std::string> &atom_names) const;
1266
1267
1268 void
1269 set_temperature_factors_using_cid(const std::string &cid, float temp_fact);
1270
1271 // ----------------------- refinement
1272
1273 coot::extra_restraints_t extra_restraints;
1274
1276 int read_extra_restraints(const std::string &file_name);
1278 std::vector<mmdb::Residue *> select_residues(const residue_spec_t &spec, const std::string &mode) const;
1280 std::vector<mmdb::Residue *> select_residues(const std::string &chain_id, int resno_start, int resno_end) const;
1282 std::vector<mmdb::Residue *> select_residues(const std::string &multi_cid, const std::string &mode) const;
1283
1285 int refine_direct(std::vector<mmdb::Residue *> rv, const std::string &alt_loc, const clipper::Xmap<float> &xmap,
1286 unsigned int max_number_of_threads,
1287 float map_weight, int n_cycles, const coot::protein_geometry &geom,
1288 bool do_rama_plot_restraints, float rama_plot_weight,
1289 bool do_torsion_restraints, float torsion_weight,
1290 bool refinement_is_quiet);
1291
1292 int minimize(const std::string &atom_selection_cid,
1293 int n_cycles,
1294 bool do_rama_plot_restraints, float rama_plot_weight,
1295 bool do_torsion_restraints, float torsion_weight, bool refinement_is_quiet,
1296 coot::protein_geometry *geom_p);
1297
1298 bool shiftfield_b_factor_refinement(const clipper::HKL_data<clipper::data32::F_sigF> &F_sigF,
1299 const clipper::HKL_data<clipper::data32::Flag> &free_flag);
1300
1301 void fix_atom_selection_during_refinement(const std::string &atom_selection_cid);
1302
1303 // refine all of this molecule - the links and non-bonded contacts will be determined from mol_ref;
1304 void init_all_molecule_refinement(int imol_ref_mol, coot::protein_geometry &geom,
1305 const clipper::Xmap<float> &xmap, float map_weight,
1306 ctpl::thread_pool *thread_pool);
1307
1308 // add or update.
1309 void add_target_position_restraint(const std::string &atom_cid, float pos_x, float pos_y, float pos_z);
1310
1311 //
1312 void turn_off_when_close_target_position_restraint();
1313
1314 std::vector<std::pair<mmdb::Atom *, clipper::Coord_orth> > atoms_with_position_restraints;
1315
1316 instanced_mesh_t add_target_position_restraint_and_refine(const std::string &atom_cid, float pos_x, float pos_y, float pos_z,
1317 int n_cyles,
1318 coot::protein_geometry *geom_p);
1320 void clear_target_position_restraint(const std::string &atom_cid);
1321
1326
1327 // something is happening to this pointer - where is it being reset?
1328 restraints_container_t *get_last_restraints() { return last_restraints; }
1329
1332
1336
1337 // make them yourself - easy as pie.
1338 void generate_self_restraints(float local_dist_max,
1339 const coot::protein_geometry &geom);
1340 void generate_chain_self_restraints(float local_dist_max,
1341 const std::string &chain_id,
1342 const coot::protein_geometry &geom);
1343 void generate_local_self_restraints(float local_dist_max,
1344 const std::vector<coot::residue_spec_t> &residue_specs,
1345 const coot::protein_geometry &geom);
1346 void generate_local_self_restraints(float local_dist_max,
1347 const std::string &multi_selection_cid,
1348 const coot::protein_geometry &geom);
1349 void generate_local_self_restraints(int selHnd, float local_dist_max,
1350 const coot::protein_geometry &geom);
1351
1352 void add_parallel_plane_restraint(coot::residue_spec_t spec_1,
1353 coot::residue_spec_t spec_2);
1354
1355 // which uses:
1356 std::vector<std::string> nucelotide_residue_name_to_base_atom_names(const std::string &rn) const;
1357 // for non-bases, normal amino acids (simple-minded, currently).
1358 std::vector<std::string> residue_name_to_plane_atom_names(const std::string &rn) const;
1359
1360 void clear_extra_restraints();
1361
1362 // --------------- rigid body fit
1363 int rigid_body_fit(const std::string &mult_cids, const clipper::Xmap<float> &xmap);
1364
1365 int rotate_around_bond(const std::string &residue_cid,
1366 const std::string &alt_conf,
1367 coot::atom_name_quad quad,
1368 double torsion_angle, protein_geometry &geom);
1369
1370 // ----------------------- map functions
1371
1372 void scale_map(float scale_factor);
1373
1374 bool is_EM_map() const;
1375
1376 float get_density_at_position(const clipper::Coord_orth &pos) const;
1377
1378 // return -1.0 on not-a-map
1379 float get_map_mean() const;
1380 // return -1.1 on not-a-map
1381 float get_map_rmsd_approx() const;
1382 int write_map(const std::string &file_name) const;
1383 void set_map_is_difference_map(bool flag);
1384 bool is_difference_map_p() const;
1385
1386 // gets updated in sfcalc_genmaps_using_bulk_solvent
1387 clipper::Xmap<float> updating_maps_previous_difference_map;
1388 // these are in the asymmetric unit
1389 std::vector<std::pair<clipper::Coord_orth, float> > updating_maps_diff_diff_map_peaks;
1390 void set_updating_maps_diff_diff_map_peaks(const std::vector<std::pair<clipper::Coord_orth, float> > &v) {
1391 updating_maps_diff_diff_map_peaks = v; }
1393 std::vector<std::pair<clipper::Coord_orth, float> > get_updating_maps_diff_diff_map_peaks(const clipper::Coord_orth &screen_centre) const;
1394
1397
1398 // changes the internal map mesh holder (hence not const)
1399 simple_mesh_t get_map_contours_mesh(clipper::Coord_orth position, float radius, float contour_level,
1400 bool use_thread_pool, ctpl::thread_pool *thread_pool_p);
1401 simple_mesh_t get_map_contours_mesh_using_other_map_for_colours(const clipper::Coord_orth &position, float radius, float contour_level,
1402 const clipper::Xmap<float> &xmap);
1403 simple_mesh_t get_map_contours_mesh_using_other_map_for_colours(const clipper::Coord_orth &position, float radius, float contour_level,
1404 const user_defined_colour_table_t &udct,
1405 const clipper::Xmap<float> &xmap);
1406
1408 class histogram_info_t {
1409 public:
1411 float base;
1415 std::vector<int> counts;
1417 float mean;
1420 histogram_info_t() : base(-1), bin_width(-1), mean(-1), variance(-1) {}
1421 histogram_info_t(float min_density, float bw, const std::vector<int> &c) :
1422 base(min_density), bin_width(bw), counts(c), mean(-1), variance(-1) {}
1423 };
1424
1429 histogram_info_t get_map_histogram(unsigned int n_bins, float zoom_factor) const;
1430
1431 // just look at the vertices of the map - not the whole thing
1432 // Sample the points from other_map
1434 get_map_vertices_histogram(const clipper::Xmap<float> &other_xmap,
1435 const clipper::Coord_orth &pt,
1436 float radius, float contour_level,
1437 bool use_thread_pool, ctpl::thread_pool *thread_pool_p,
1438 unsigned int n_bins);
1439
1440 void set_map_colour(colour_holder holder);
1441 void set_map_colour_saturation(float s) { radial_map_colour_saturation = s; }
1442
1446 void set_other_map_for_colouring_min_max(float min_v, float max_v);
1447 void set_other_map_for_colouring_invert_colour_ramp(bool state) {
1448 radial_map_colour_invert_flag = state;
1449 }
1450
1451 double sum_density_for_atoms_in_residue(const std::string &cid,
1452 const std::vector<std::string> &atom_names,
1453 const clipper::Xmap<float> &xmap) const;
1454
1459 public:
1461 std::string feature_type;
1463 residue_spec_t residue_spec; // use this for sorting a combination of interesting_place_t types.
1465 float x, y, z;
1467 std::string button_label;
1469 float feature_value; // e.g. peak-height (not all "interesting" feature values can be captured by a float of course)
1471 float badness; // a nubmer between 100.0 and 0.0 (inclusive) if it's negative then it's not set.
1475 interesting_place_t(const std::string &feature_type, const residue_spec_t &rs, const clipper::Coord_orth &pt, const std::string &bl) :
1477 x = pt.x(); y = pt.y(); z = pt.z();
1478 feature_value = -1; // something "unset"
1479 badness = -1.1; // "unset"
1480 }
1481
1482 interesting_place_t(const std::string &feature_type, const clipper::Coord_orth &pt, const std::string &button_label) :
1484 x = pt.x(); y = pt.y(); z = pt.z();
1485 feature_value = -1; // something "unset"
1486 badness = -1.1; // "unset"
1487 }
1488
1489 void set_feature_value(const float &f) { feature_value = f; }
1490 void set_badness_value(const float &b) { badness = b; }
1491 };
1492
1494 class difference_map_peaks_info_t {
1495 public:
1496 clipper::Coord_orth pos;
1497 float peak_height; // nrmsd
1498 // maybe other useful stuff here in future
1499 difference_map_peaks_info_t(const clipper::Coord_orth &p, float ph) : pos(p), peak_height(ph) {}
1500 };
1501
1502 // the molecule is passed so that the peaks are placed around the protein
1503 std::vector<interesting_place_t> difference_map_peaks(mmdb::Manager *mol, float n_rmsd) const;
1504
1505 texture_as_floats_t get_map_section_texture(int section_index, int axis,
1506 float data_value_for_bottom, float data_value_for_top) const;
1507
1511 int get_number_of_map_sections(int axis_id) const;
1512
1513 // ---------------------------------- blender --------------------------------------
1514
1515 blender_mesh_t blender_mesh;
1516 std::vector<float> get_vertices_for_blender() const;
1517 std::vector<int> get_triangles_for_blender() const;
1518 std::vector<float> get_colour_table_for_blender() const;
1519
1520 // pass other things here
1521 void make_mesh_for_bonds_for_blender(const std::string &mode, protein_geometry *geom, bool against_a_dark_background,
1522 float bond_width, float atom_radius_to_bond_width_ratio,
1523 int smoothness_factor);
1524
1532 const std::string &colour_scheme,
1533 const std::string &style,
1534 int secondary_structure_usage_flag);
1535
1536 void make_mesh_for_goodsell_style_for_blender(protein_geometry *geom_p,
1537 float colour_wheel_rotation_step,
1538 float saturation,
1539 float goodselliness);
1540
1541 void make_mesh_for_map_contours_for_blender(Cartesian position, float contour_level, float radius);
1542 void make_mesh_for_gaussian_surface_for_blender(float sigma, float contour_level, float box_radius, float grid_scale,float b_factor);
1543 };
1544}
1545
1546
1547#endif // COOT_MOLECULE_HH
Definition residue-and-atom-specs.hh:35
Definition instancing.hh:58
map histogram class
Definition coot-molecule.hh:1408
float base
base
Definition coot-molecule.hh:1411
float mean
mean
Definition coot-molecule.hh:1417
float variance
variance
Definition coot-molecule.hh:1419
float bin_width
bin width
Definition coot-molecule.hh:1413
std::vector< int > counts
counts
Definition coot-molecule.hh:1415
std::string button_label
button label
Definition coot-molecule.hh:1467
interesting_place_t(const std::string &feature_type, const clipper::Coord_orth &pt, const std::string &button_label)
constructor
Definition coot-molecule.hh:1482
float badness
synthetic badness (for "score by badness")
Definition coot-molecule.hh:1471
interesting_place_t(const std::string &feature_type, const residue_spec_t &rs, const clipper::Coord_orth &pt, const std::string &bl)
constructor
Definition coot-molecule.hh:1475
std::string feature_type
Feature.
Definition coot-molecule.hh:1461
interesting_place_t()
constructor
Definition coot-molecule.hh:1473
void set_feature_value(const float &f)
internal to libcootapi function to set the values
Definition coot-molecule.hh:1489
float x
Position.
Definition coot-molecule.hh:1465
float feature_value
actual value of the feature
Definition coot-molecule.hh:1469
residue_spec_t residue_spec
Residue specifier.
Definition coot-molecule.hh:1463
a container class for information about changing rotamers
Definition coot-molecule.hh:1192
int rank
the rank of the new rotamer
Definition coot-molecule.hh:1195
std::string name
new rotamer name
Definition coot-molecule.hh:1197
float richardson_probability
Richardson probability.
Definition coot-molecule.hh:1199
int status
status: did the change take place?
Definition coot-molecule.hh:1201
int add_alternative_conformation(const std::string &cid)
add an alternative conformation for the specified residue
std::vector< mmdb::Residue * > select_residues(const std::string &multi_cid, const std::string &mode) const
select residues given a multi-cid
int fill_partial_residues(const clipper::Xmap< float > &xmap, protein_geometry *geom)
add atoms to a partially-filled side chaain
std::vector< std::vector< std::string > > get_ncs_related_chains() const
Get the chains that are related by NCS:
void make_mesh_for_molecular_representation_for_blender(const std::string &cid, const std::string &colour_scheme, const std::string &style, int secondary_structure_usage_flag)
void add_colour_rule(const std::string &selection, const std::string &colour_name)
Add a colour rule: eg. ("//A", "red")
std::vector< std::pair< clipper::Coord_orth, float > > get_updating_maps_diff_diff_map_peaks(const clipper::Coord_orth &screen_centre) const
does the peaks-move operation.
void set_other_map_for_colouring_min_max(float min_v, float max_v)
bool copy_ncs_chain(const std::string &from_chain_id, const std::string &to_chain_id)
copy chain using NCS matrix
void M2T_updateIntParameter(const std::string &param_name, int value)
Update int parameter for MoleculesToTriangles molecular mesh.
void M2T_updateFloatParameter(const std::string &param_name, int value)
Update int parameter for MoleculesToTriangles molecular mesh.
molecule_t(const std::string &name_in, int mol_no_in, short int is_em_map)
constructor, when we know we are giving it an em map
Definition coot-molecule.hh:495
simple::molecule_t get_simple_molecule(int imol, const std::string &residue_cid, const bool draw_hydrogen_atoms_flag, coot::protein_geometry *geom_p)
void delete_colour_rules()
delete all the colour rules
molecule_t(atom_selection_container_t asc, int imol_no_in, const std::string &name_in)
constructor
Definition coot-molecule.hh:501
std::vector< std::string > get_types_in_molecule() const
get types
std::vector< plain_atom_overlap_t > get_overlaps(protein_geometry *geom_p)
not const because it can dynamically add dictionaries
std::vector< double > get_residue_CA_position(const std::string &cid) const
std::vector< coot::residue_spec_t > residues_near_residue(const std::string &residue_cid, float dist) const
int delete_hydrogen_atoms()
instanced_mesh_t all_molecule_contact_dots(const coot::protein_geometry &geom, unsigned int num_subdivisions) const
void assign_sequence(const clipper::Xmap< float > &xmap, const coot::protein_geometry &geom)
try to fit all of the sequences to all of the chains
std::vector< coot::geometry_distortion_info_container_t > geometric_distortions_for_one_residue_from_mol(const std::string &ligand_cid, bool with_nbcs, coot::protein_geometry &geom, ctpl::thread_pool &static_thread_pool)
int new_positions_for_atoms_in_residues(const std::vector< api::moved_residue_t > &moved_residues)
set new positions for the atoms of the specified residues
int merge_molecules(const std::vector< mmdb::Manager * > &mols)
void export_map_molecule_as_gltf(clipper::Coord_orth &position, float radius, float contour_level, const std::string &file_name)
export map molecule as glTF
std::vector< mmdb::Residue * > select_residues(const residue_spec_t &spec, const std::string &mode) const
refinement tool
int refine_direct(std::vector< mmdb::Residue * > rv, const std::string &alt_loc, const clipper::Xmap< float > &xmap, unsigned int max_number_of_threads, float map_weight, int n_cycles, const coot::protein_geometry &geom, bool do_rama_plot_restraints, float rama_plot_weight, bool do_torsion_restraints, float torsion_weight, bool refinement_is_quiet)
real space refinement
void clear_target_position_restraints()
clear any and all drag-atom target position restraints
std::vector< mmdb::Residue * > select_residues(const std::string &chain_id, int resno_start, int resno_end) const
resno_start and resno_end are inclusive
std::vector< residue_range_t > get_missing_residue_ranges() const
void set_user_defined_atom_colour_by_selections(const std::vector< std::pair< std::string, unsigned int > > &indexed_residues_cids, bool colour_applies_to_non_carbon_atoms_also, mmdb::Manager *mol)
user-defined atom selection to colour index.
void M2T_updateFloatParameter(const std::string &param_name, float value)
Update float parameter for MoleculesToTriangles molecular mesh.
coot::atom_overlaps_dots_container_t get_overlap_dots_for_ligand(const std::string &cid_ligand, protein_geometry *geom_p)
not const because it can dynamically add dictionaries
float fit_to_map_by_random_jiggle_using_atom_selection(const std::string &cid, const clipper::Xmap< float > &xmap, float map_rmsd, int n_trials, float translation_scale_factor)
int add_hydrogen_atoms(protein_geometry *geom)
bool residue_is_nucleic_acid(const std::string &cid) const
std::vector< double > get_residue_sidechain_average_position(const std::string &cid) const
void multiply_residue_temperature_factors(const std::string &cid, float factor)
void set_colour_wheel_rotation_base(float r)
set the colour wheel rotation base for the specified molecule
molecule_t(const std::string &name_in, int mol_no_in, const clipper::Xmap< float > &xmap_in, bool is_em_map_flag)
constructor
Definition coot-molecule.hh:498
void set_base_colour_for_bonds(float r, float g, float b)
set the base colour - to be used as a base for colour wheel rotation
std::vector< coot::geometry_distortion_info_container_t > geometric_distortions_for_selection_from_mol(const std::string &selection_cid, bool with_nbcs, coot::protein_geometry &geom, ctpl::thread_pool &static_thread_pool)
void export_model_molecule_as_gltf(const std::string &mode, const std::string &selection_cid, protein_geometry *geom, bool against_a_dark_background, float bonds_width, float atom_radius_to_bond_width_ratio, int smoothness_factor, bool draw_hydrogen_atoms_flag, bool draw_missing_residue_loops, const std::string &file_name)
export model molecule as glTF - this is the bonds and atoms API
int read_extra_restraints(const std::string &file_name)
read extra restraints (e.g. from ProSMART)
std::vector< std::pair< std::string, std::string > > colour_rules
Definition coot-molecule.hh:793
int fill_partial_residue(const residue_spec_t &res_spec, const std::string &alt_conf, const clipper::Xmap< float > &xmap, const protein_geometry &geom)
add atoms to a partially-filled side chaain
int replace_fragment(atom_selection_container_t asc)
std::string molecule_to_PDB_string() const
RDKit::ROMol * rdkit_mol(const std::string &ligand_cid)
float get_atom_overlap_score(protein_geometry *geom_p) const
get the atom overlap
molecule_t(const std::string &name_in, int mol_no_in)
constructor
Definition coot-molecule.hh:493
void clear_target_position_restraint(const std::string &atom_cid)
clear
void clear_refinement()
chain_mutation_info_container_t get_mutation_info() const
return the mismatches/mutations:
coot::atom_overlaps_dots_container_t get_overlap_dots(protein_geometry *geom_p)
not const because it can dynamically add dictionaries
std::vector< plain_atom_overlap_t > get_overlaps_for_ligand(const std::string &cid_ligand, protein_geometry *geom_p)
not const because it can dynamically add dictionaries
std::vector< coot::atom_distance_t > get_distances_between_atoms_of_residues(const std::string &cid_res_1, const std::string &cid_res_2, float dist_max) const
int get_number_of_map_sections(int axis_id) const
double get_radius_of_gyration() const
instanced_mesh_t contact_dots_for_ligand(const std::string &cid, const protein_geometry &geom, unsigned int num_subdivisions) const
int new_positions_for_residue_atoms(mmdb::Residue *residue_p, const std::vector< api::moved_atom_t > &moved_atoms, bool do_backup)
std::vector< std::pair< std::string, std::string > > get_sequence_info() const
simple return the associated sequences
void set_occupancy(const std::string &cid, float occ_new)
float get_suggested_initial_contour_level() const
std::vector< glm::vec4 > make_colour_table(bool against_a_dark_background) const
useful for debugging, perhaps
histogram_info_t get_map_histogram(unsigned int n_bins, float zoom_factor) const
int refine_using_last_restraints(int n_steps)
int new_positions_for_residue_atoms(const std::string &residue_cid, const std::vector< api::moved_atom_t > &moved_atoms)
set new positions for the atoms in the specified residue
bool delete_all_carbohydrate()
void set_user_defined_bond_colours(const std::map< unsigned int, std::array< float, 4 > > &colour_map)
coot::simple_mesh_t get_mesh_for_ligand_validation_vs_dictionary(const std::string &ligand_cid, coot::protein_geometry &geom, ctpl::thread_pool &static_thread_pool)
std::vector< std::pair< std::string, std::string > > get_colour_rules() const
std::vector< double > get_residue_average_position(const std::string &cid) const
std::string get_svg_for_2d_ligand_environment_view(const std::string &residue_cid, protein_geometry *geom, bool add_key) const
std::string molecule_to_mmCIF_string() const
rotamer_change_info_t change_to_next_rotamer(const coot::residue_spec_t &res_spec, const std::string &alt_conf, const coot::protein_geometry &pg)
change rotamers
Definition residue-and-atom-specs.hh:216
The basic mesh for transfering mesh geometry and colours.
Definition simple-mesh.hh:38
Definition generic-3d-lines.hh:12