Pteros  2.0
Molecular modeling library for human beings!
selection.h
1 /*
2  * This file is a part of
3  *
4  * ============================================
5  * ### Pteros molecular modeling library ###
6  * ============================================
7  *
8  * https://github.com/yesint/pteros
9  *
10  * (C) 2009-2021, Semen Yesylevskyy
11  *
12  * All works, which use Pteros, should cite the following papers:
13  *
14  * 1. Semen O. Yesylevskyy, "Pteros 2.0: Evolution of the fast parallel
15  * molecular analysis library for C++ and python",
16  * Journal of Computational Chemistry, 2015, 36(19), 1480–1488.
17  * doi: 10.1002/jcc.23943.
18  *
19  * 2. Semen O. Yesylevskyy, "Pteros: Fast and easy to use open-source C++
20  * library for molecular analysis",
21  * Journal of Computational Chemistry, 2012, 33(19), 1632–1636.
22  * doi: 10.1002/jcc.22989.
23  *
24  * This is free software distributed under Artistic License:
25  * http://www.opensource.org/licenses/artistic-license-2.0.php
26  *
27 */
28 
29 
30 #pragma once
31 
32 #include <string>
33 //#include <memory>
34 #include <map>
35 #include <vector>
36 #include <functional>
37 #include <Eigen/Core>
38 //#include <Eigen/Geometry>
39 #include "pteros/core/atom_handler.h"
40 #include "pteros/core/system.h"
41 #include "pteros/core/typedefs.h"
42 
43 namespace pteros {
44 
45 // Forward declaration of friend classes
46 class System;
47 class SelectionParser;
48 
49 
65 class Selection {
66  friend class System;
67  friend class SelectionParser;
68  friend class Grid_searcher;
69 
70  public:
71  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 
76  Selection();
77 
81  explicit Selection(const System& sys);
82 
87  Selection(const System& sys, std::string str, int fr = 0);
88 
96  Selection(const System& sys, int ind1, int ind2);
97 
100  Selection(const System& sys, const std::vector<int>& ind);
101 
104  Selection(const System& sys,
105  std::vector<int>::iterator it1,
106  std::vector<int>::iterator it2);
107 
116  Selection(const System& sys,
117  const std::function<void(const System&,int,std::vector<int>&)>& callback,
118  int fr = 0);
119 
121  Selection(const Selection& other);
122 
124  virtual ~Selection();
125 
127  Selection& operator=(const Selection& other);
128 
131  bool operator==(const Selection &other) const;
132 
135  bool operator!=(const Selection &other) const {
136  return !(*this == other);
137  }
138 
160  AtomHandler operator[](int ind);
161 
172  AtomHandler operator[](const std::pair<int,int>& ind_fr);
173 
176  friend std::ostream& operator<<(std::ostream& os, const Selection& sel);
177 
180  friend Selection operator|(const Selection& sel1, const Selection& sel2);
181 
184  friend Selection operator&(const Selection& sel1, const Selection& sel2);
185 
189  friend Selection operator-(const Selection& sel1, const Selection& sel2);
190 
193  Selection operator~() const;
195 
196  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
199 
201  void append(const Selection& sel);
202 
204  void append(int ind);
205 
207  void append(const std::vector<Selection>& sel_vec);
208 
210  void remove(const Selection& sel);
211 
213  void remove(int ind);
214 
216  void invert();
217 
220  void set_system(const System& sys);
221 
226  void modify(std::string str, int fr = 0);
227 
229  void modify(int ind1, int ind2);
230 
233  void modify(const std::vector<int>& ind);
234 
237  void modify(std::vector<int>::iterator it1, std::vector<int>::iterator it2);
238 
247  void modify(const std::function<void(const System&,int,std::vector<int>&)>& callback, int fr = 0);
248 
250  void modify(const System& sys, std::string str, int fr = 0);
251 
253  void modify(const System& sys, int ind1, int ind2);
254 
256  void modify(const System& sys, const std::vector<int>& ind);
257 
259  void modify(const System& sys,
260  std::vector<int>::iterator it1,
261  std::vector<int>::iterator it2);
262 
264  void modify(const System& sys, const std::function<void(const System&,int,std::vector<int>&)>& callback, int fr = 0);
265 
271  void apply();
272 
278  void update();
279 
284  void clear();
286 
287  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
289 
319  Selection select(std::string str);
321  Selection operator()(std::string str);
322 
324  Selection select(int ind1, int ind2);
325  Selection operator()(int ind1, int ind2);
326 
328  Selection select(const std::vector<int>& ind);
329  Selection operator()(const std::vector<int>& ind);
331 
332  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
335 
337  std::vector<int>::const_iterator index_begin() const { return _index.begin(); }
338 
340  std::vector<int>::const_iterator index_end() const { return _index.end(); }
341 
343  std::back_insert_iterator<std::vector<int> > index_back_inserter() {
344  return std::back_inserter(_index);
345  }
346 
349  class iterator;
350 
352  iterator begin();
354  iterator end();
356 
357 
358  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
361 
363  int get_frame() const {return frame;}
364 
367  void set_frame(int fr);
368 
370  System* get_system() const { return system; }
371 
374  std::string get_text() const;
375 
377  std::vector<int> get_index() const { return _index; }
378 
380  std::vector<char> get_chain(bool unique=false) const;
381 
384  void set_chain(const std::vector<char>& data);
385 
387  void set_chain(char data);
388 
389 
392  std::vector<int> get_resid(bool unique=false) const;
393 
396  void set_resid(const std::vector<int>& data);
397 
399  void set_resid(int data);
400 
401 
403  std::vector<std::string> get_name(bool unique=false) const;
404 
407  void set_name(const std::vector<std::string>& data);
408 
410  void set_name(std::string data);
411 
412 
414  std::vector<std::string> get_resname(bool unique=false) const;
415 
418  void set_resname(const std::vector<std::string>& data);
419 
421  void set_resname(std::string data);
422 
423 
426  std::vector<int> get_resindex(bool unique=false) const;
427 
428 
432  Eigen::MatrixXf get_xyz(bool make_row_major_matrix = false) const;
433 
435  void set_xyz(MatrixXf_const_ref coord);
436 
437 
439  std::vector<float> get_mass() const;
440 
443  void set_mass(const std::vector<float>& m);
444 
446  void set_mass(float data);
447 
448 
450  std::vector<float> get_beta() const;
451 
454  void set_beta(const std::vector<float>& data);
455 
457  void set_beta(float data);
458 
459 
461  std::vector<float> get_occupancy() const;
462 
465  void set_occupancy(const std::vector<float>& data);
466 
468  void set_occupancy(float data);
469 
470 
472  std::vector<float> get_charge() const;
473 
476  void set_charge(const std::vector<float>& data);
477 
479  void set_charge(float data);
480 
482  float get_total_charge() const;
483 
485  std::vector<std::string> get_tag(bool unique=false) const;
486 
489  void set_tag(const std::vector<std::string>& data);
490 
492  void set_tag(std::string data);
493 
494 
498  Eigen::MatrixXf get_vel(bool make_row_major_matrix = false) const;
499 
501  void set_vel(MatrixXf_const_ref data);
502 
506  Eigen::MatrixXf get_force(bool make_row_major_matrix = false) const;
507 
509  void set_force(MatrixXf_const_ref coord);
510 
512 
513 
514  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
517 
520  bool is_large();
521 
532  Eigen::Vector3f center(bool mass_weighted = false,
533  Array3i_const_ref pbc = noPBC,
534  int pbc_atom = -1) const;
535 
536  // Get the center of selection with user-supplied weights
537  Eigen::Vector3f center(const std::vector<float>& weights,
538  Array3i_const_ref pbc = noPBC,
539  int pbc_atom = -1) const;
540 
542  void minmax(Vector3f_ref min, Vector3f_ref max) const;
543 
545  float powersasa(float probe_r = 0.14,
546  std::vector<float>* area_per_atom = nullptr,
547  float* total_volume = nullptr,
548  std::vector<float>* volume_per_atom = nullptr) const;
549 
551  float sasa(float probe_r = 0.14, std::vector<float>* area_per_atom = nullptr, int n_sphere_points = 960) const;
552 
554  Eigen::MatrixXf average_structure(int b=0, int e=-1, bool make_row_major_matrix = false) const;
555 
560  Eigen::MatrixXf atom_traj(int ind, int b=0, int e=-1, bool make_row_major_matrix = false) const;
561 
569  void inertia(Vector3f_ref moments, Matrix3f_ref axes,
570  Array3i_const_ref pbc = noPBC,
571  int pbc_atom = -1) const;
572 
580  float gyration(Array3i_const_ref pbc = noPBC, int pbc_atom = -1) const;
581 
582  /* Computes dipole moment of selection in Debye
583  If the size of selection is larger than 1/2 of the box size in
584  any dimension you will get incorrect results if periodic is set to true.
585  This is not checked automatically!
586  In this case use one of unwrapping options first.
587  */
588  Eigen::Vector3f dipole(bool as_charged=false, Array3i_const_ref pbc = fullPBC, int pbc_atom = -1) const;
589 
593  float distance(int i, int j, Array3i_const_ref pbc = fullPBC) const;
594 
598  float angle(int i, int j, int k, Array3i_const_ref pbc = fullPBC) const;
599 
603  float dihedral(int i, int j, int k, int l, Array3i_const_ref pbc = fullPBC) const;
605 
606 
607  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
610 
612  void translate(Vector3f_const_ref v);
613 
615  void translate_to(Vector3f_const_ref p,
616  bool mass_weighted = false,
617  Array3i_const_ref pbc = noPBC,
618  int pbc_atom = -1);
619 
624  void rotate(Vector3f_const_ref pivot, Vector3f_const_ref axis, float angle);
625 
627  void mirror(int dim, float around=0);
628 
630  void mirror(Vector3f_const_ref normal, Vector3f_const_ref point=Eigen::Vector3f::Zero());
631 
633  void wrap(Array3i_const_ref pbc = fullPBC);
634 
642  void unwrap(Array3i_const_ref pbc = fullPBC, int pbc_atom = -1);
643 
651  int unwrap_bonds(float d, Array3i_const_ref pbc = fullPBC, int pbc_atom = -1);
652 
658  Eigen::Affine3f principal_transform(Array3i_const_ref pbc = noPBC, int pbc_atom = -1) const;
659 
667  void principal_orient(Array3i_const_ref pbc = noPBC, int pbc_atom = -1);
668 
670  int num_residues() const;
672 
673 
674  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
677 
679  float rmsd(int fr) const;
680 
682  float rmsd(int fr1, int fr2) const;
683 
685  friend float rmsd(const Selection& sel1, const Selection& sel2);
686 
693  friend float rmsd(const Selection& sel1, int fr1, const Selection& sel2, int fr2);
694 
696  friend void fit(Selection& sel1, const Selection& sel2);
697 
699  void fit_trajectory(int ref_frame=0, int b=0, int e=-1);
700 
702  friend Eigen::Affine3f fit_transform(const Selection& sel1, const Selection& sel2);
703 
705  Eigen::Affine3f fit_transform(int fr1, int fr2) const;
706 
708  void fit(int fr1, int fr2);
709 
711  void apply_transform(const Eigen::Affine3f& t);
713 
714 
715  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
718 
721  Eigen::Vector2f non_bond_energy(float cutoff=0, bool pbc = true) const;
722 
723 
725 
726 
727  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
730 
736  void write(std::string fname, int b=-1,int e=-1) const;
737 
738  void write(const std::unique_ptr<FileHandler>& handler, FileContent what,int b=-1,int e=-1) const;
740 
741 
742  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
745 
747  int size() const {return _index.size();}
748 
751  bool text_based() const;
752 
755  bool coord_dependent() const;
756 
760  void flatten();
761 
764  std::string to_gromacs_ndx(std::string name) const;
765 
768  friend void copy_coord(const Selection& from, int from_fr, Selection& to, int to_fr);
769 
772  friend void copy_coord(const Selection& from, Selection& to);
773 
776  int find_index(int global_index) const;
777 
781  std::vector<std::vector<int>> get_internal_bonds(float d, bool periodic=true) const;
783 
784  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
787 
792  void split_by_connectivity(float d, std::vector<Selection>& res, bool periodic=true);
793 
795  void split_by_residue(std::vector<Selection>& res);
796 
798  void split_by_molecule(std::vector<Selection>& res);
799 
801  void split_by_chain(std::vector<Selection>& chains);
802 
804  void split_by_contiguous_index(std::vector<Selection>& parts);
805 
807  void split_by_contiguous_residue(std::vector<Selection>& parts);
808 
816  template<class F>
817  void split(std::vector<Selection>& parts, F callback){
818  using namespace std;
819  parts.clear();
820  using Ret = decltype(callback(*this,0));
821  map<Ret,vector<int> > m;
822  for(int i=0; i<size(); ++i){
823  m[callback(*this,i)].push_back(index(i));
824  }
825  // Create selections
826  typename map<Ret,vector<int> >::iterator it;
827  for(it=m.begin();it!=m.end();it++){
828  parts.emplace_back(*system, it->second.begin(), it->second.end());
829  }
830  }
831 
832 
836  void each_residue(std::vector<Selection>& sel) const;
838 
839  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
843 
845  void dssp(std::string fname) const;
846 
848  void dssp(std::ostream& os) const;
849 
863  std::string dssp() const;
865 
866  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
875 
878  inline float& x(int ind) { return system->traj[frame].coord[_index[ind]](0); }
879  inline float x(int ind) const { return system->traj[frame].coord[_index[ind]](0); }
881  inline float& x(int ind, int fr) { return system->traj[fr].coord[_index[ind]](0); }
882  inline float x(int ind, int fr) const { return system->traj[fr].coord[_index[ind]](0); }
883 
885  inline float& y(int ind) { return system->traj[frame].coord[_index[ind]](1); }
886  inline float y(int ind) const { return system->traj[frame].coord[_index[ind]](1); }
888  inline float& y(int ind, int fr) { return system->traj[fr].coord[_index[ind]](1); }
889  inline float y(int ind, int fr) const { return system->traj[fr].coord[_index[ind]](1); }
890 
892  inline float& z(int ind) { return system->traj[frame].coord[_index[ind]](2); }
893  inline float z(int ind) const { return system->traj[frame].coord[_index[ind]](2); }
895  inline float& z(int ind, int fr) { return system->traj[fr].coord[_index[ind]](2); }
896  inline float z(int ind, int fr) const { return system->traj[fr].coord[_index[ind]](2); }
897 
899  inline Eigen::Vector3f& xyz(int ind) { return system->traj[frame].coord[_index[ind]]; }
900  inline const Eigen::Vector3f& xyz(int ind) const { return system->traj[frame].coord[_index[ind]]; }
902  inline Eigen::Vector3f& xyz(int ind, int fr) { return system->traj[fr].coord[_index[ind]]; }
903  inline const Eigen::Vector3f& xyz(int ind, int fr) const { return system->traj[fr].coord[_index[ind]]; }
904 
907  inline Eigen::Vector3f* xyz_ptr(int ind) const { return &(system->traj[frame].coord[_index[ind]]); }
908  inline Eigen::Vector3f* xyz_ptr(int ind, int fr) const { return &(system->traj[fr].coord[_index[ind]]); }
909 
911  inline Eigen::Vector3f& vel(int ind) { return system->traj[frame].vel[_index[ind]]; }
912  inline const Eigen::Vector3f& vel(int ind) const { return system->traj[frame].vel[_index[ind]]; }
914  inline Eigen::Vector3f& vel(int ind, int fr) { return system->traj[fr].vel[_index[ind]]; }
915  inline const Eigen::Vector3f& vel(int ind, int fr) const { return system->traj[fr].vel[_index[ind]]; }
916 
918  inline Eigen::Vector3f& force(int ind) { return system->traj[frame].force[_index[ind]]; }
919  inline const Eigen::Vector3f& force(int ind) const { return system->traj[frame].force[_index[ind]]; }
921  inline Eigen::Vector3f& force(int ind, int fr) { return system->traj[fr].force[_index[ind]]; }
922  inline const Eigen::Vector3f& force(int ind, int fr) const { return system->traj[fr].force[_index[ind]]; }
923 
924 #define DEFINE_ACCESSOR(T,prop) \
925  inline T& prop(int ind){ return system->atoms[_index[ind]].prop; } \
926  inline const T& prop(int ind) const { return system->atoms[_index[ind]].prop; }
927 
929  DEFINE_ACCESSOR(int,type)
931  DEFINE_ACCESSOR(std::string,type_name)
933  DEFINE_ACCESSOR(std::string,resname)
935  DEFINE_ACCESSOR(char,chain)
937  DEFINE_ACCESSOR(std::string,name)
939  DEFINE_ACCESSOR(float,mass)
941  DEFINE_ACCESSOR(float,charge)
943  DEFINE_ACCESSOR(float,beta)
945  DEFINE_ACCESSOR(float,occupancy)
947  DEFINE_ACCESSOR(int,resid)
949  DEFINE_ACCESSOR(std::string,tag)
950 
951 
952  inline int index(int ind) const { return _index[ind]; }
953 
955  inline Atom& atom(int ind){ return system->atoms[_index[ind]]; }
956  inline const Atom& atom(int ind) const { return system->atoms[_index[ind]]; }
957 
959  DEFINE_ACCESSOR(int,resindex)
961  DEFINE_ACCESSOR(int,atomic_number)
962 
963 
964  float vdw(int ind) const;
967 
969  std::string element_name(int ind) const;
970 
979  inline PeriodicBox& box() { return system->traj[frame].box; }
980  inline const PeriodicBox& box() const { return system->traj[frame].box; }
981 
990  inline float& time() { return system->traj[frame].time; }
991  inline const float& time() const { return system->traj[frame].time; }
992 
994 
995 protected:
996  // Raw text of selection
997  std::string sel_text;
998  // Indexes of atoms in selection
999  std::vector<int> _index;
1000  // Pointer to target system
1001  System* system;
1002 
1003  // Stores current frame
1004  int frame;
1005 
1006  // Holds an instance of selection parser
1007  std::unique_ptr<SelectionParser> parser;
1008  void allocate_parser();
1009  void sort_and_remove_duplicates();
1010  void process_pbc_atom(int& a) const;
1011  void get_local_bonds_from_topology(std::vector<std::vector<int>>& con) const;
1012 };
1013 
1014 //-----------------------------------------------------------------------
1017 public:
1018  using value_type = AtomHandler;
1019  using difference_type = size_t;
1020  using pointer = AtomHandler*;
1021  using reference = AtomHandler&;
1022  using iterator_category = std::random_access_iterator_tag;
1023 
1024  iterator(const Selection& sel, int i){
1025  index_it = sel.index_begin() + i;
1026  proxy.set(sel,*index_it);
1027  }
1028  iterator operator++(int junk) { iterator tmp = *this; advance_proxy(); return tmp; }
1029  iterator& operator++() { advance_proxy(); return *this; }
1030  iterator& operator+(int i) {advance_proxy(i); return *this;}
1031  iterator& operator-(int i) {advance_proxy(-i); return *this;}
1032  reference operator*() { return proxy; }
1033  pointer operator->() { return &proxy; }
1034  bool operator==(const iterator& rhs) { return index_it == rhs.index_it; }
1035  bool operator!=(const iterator& rhs) { return !(*this==rhs); }
1036 
1037 private:
1038  AtomHandler proxy;
1039  // We have to keep an iterator for index array of parent selection
1040  std::vector<int>::const_iterator index_it;
1041 
1042  void advance_proxy(int n=1){
1043  int offset = *index_it; // save current index
1044  index_it += n;
1045  offset = *index_it-offset; // compute offset to new index
1046  proxy.ind = *index_it;
1047  proxy.atom_ptr += offset;
1048  proxy.coord_ptr += offset;
1049  }
1050 };
1051 
1053 bool check_selection_overlap(const std::vector<Selection> &sel_vec);
1054 
1055 
1059 Eigen::Vector2f non_bond_energy(const Selection& sel1,
1060  const Selection& sel2,
1061  float cutoff = 0,
1062  int fr = -1,
1063  bool pbc = true);
1064 
1065 } // namespace pteros
1066 
1067 
1068 
1069 
1070 
pteros::Selection
Selection class.
Definition: selection.h:65
pteros::Selection::index_end
std::vector< int >::const_iterator index_end() const
Get const iterator for the end of index.
Definition: selection.h:340
pteros::Selection::get_text
std::string get_text() const
Get selection text If selection is not textual returns generated index-based text "index i j k....
Definition: selection.cpp:761
pteros::Selection::update
void update()
Recomputes selection completely.
Definition: selection.cpp:651
pteros::Selection::operator!=
bool operator!=(const Selection &other) const
Inequality operator Selection are compared by their indexes.
Definition: selection.h:135
pteros::Selection::distance
float distance(int i, int j, Array3i_const_ref pbc=fullPBC) const
Get distance between two atoms (periodic in given dimensions if needed).
Definition: selection.cpp:1905
pteros::Selection::y
float & y(int ind)
Extracts Y for current frame.
Definition: selection.h:885
pteros::Selection::split_by_molecule
void split_by_molecule(std::vector< Selection > &res)
Split selection by molecule definition from topology.
Definition: selection.cpp:1735
pteros::Selection::modify
void modify(std::string str, int fr=0)
Modifies selection string in existing selection.
Definition: selection.cpp:387
pteros::Selection::set_charge
void set_charge(const std::vector< float > &data)
Set charge in selection to the values from supplied vector.
pteros::Selection::time
float & time()
Returns time stamp of the frame pointed by selection The same as:
Definition: selection.h:990
pteros::Selection::operator-
friend Selection operator-(const Selection &sel1, const Selection &sel2)
Creates new Selection, by removing all atoms of sel2 from sel1.
Definition: selection.cpp:592
pteros::Selection::operator~
Selection operator~() const
Creates new Selection, which is a logical negation of existing one.
Definition: selection.cpp:523
pteros::Selection::set_resid
void set_resid(const std::vector< int > &data)
Set resid's in selection from supplied vector.
pteros::Selection::xyz
Eigen::Vector3f & xyz(int ind, int fr)
Extracts X,Y and Z for given frame fr.
Definition: selection.h:902
pteros::Selection::principal_transform
Eigen::Affine3f principal_transform(Array3i_const_ref pbc=noPBC, int pbc_atom=-1) const
Get transform for orienting selection by principal axes.
Definition: selection.cpp:2006
pteros::Selection::get_occupancy
std::vector< float > get_occupancy() const
Get occupancy.
pteros::Selection::get_total_charge
float get_total_charge() const
Computes total charge of selection.
Definition: selection.cpp:860
pteros::Selection::operator==
bool operator==(const Selection &other) const
Equality operator Selection are compared by their indexes.
Definition: selection.cpp:511
pteros::Selection::gyration
float gyration(Array3i_const_ref pbc=noPBC, int pbc_atom=-1) const
Computes radius of gyration for selection.
Definition: selection.cpp:1867
pteros::Selection::fit_transform
friend Eigen::Affine3f fit_transform(const Selection &sel1, const Selection &sel2)
Returns fitting transformation for two given selections of the same size.
Definition: selection.cpp:1220
pteros::Selection::operator=
Selection & operator=(const Selection &other)
Assignment operator.
Definition: selection.cpp:484
pteros::Selection::get_charge
std::vector< float > get_charge() const
Get charge.
pteros::Selection::split_by_connectivity
void split_by_connectivity(float d, std::vector< Selection > &res, bool periodic=true)
Split current selection into several selections according to the interatomic distances.
Definition: selection.cpp:1641
pteros::Selection::size
int size() const
Get the size of selection.
Definition: selection.h:747
pteros::Selection::operator&
friend Selection operator&(const Selection &sel1, const Selection &sel2)
Creates new Selection, which is the logical AND of two parent selections.
Definition: selection.cpp:565
pteros::Selection::get_name
std::vector< std::string > get_name(bool unique=false) const
Get vector of all atom names in selection.
pteros::Selection::find_index
int find_index(int global_index) const
Finds local index in selection of provided global index Returns -1 if not found.
Definition: selection.cpp:1518
pteros::Selection::split_by_contiguous_index
void split_by_contiguous_index(std::vector< Selection > &parts)
Split selection into contiguous ranges of indexes.
Definition: selection.cpp:1774
pteros::Selection::get_resindex
std::vector< int > get_resindex(bool unique=false) const
Get vector of all resindexes in selection.
pteros::Selection::copy_coord
friend void copy_coord(const Selection &from, int from_fr, Selection &to, int to_fr)
Copy coordinates from one selection to the other using given frames.
Definition: selection.cpp:1140
pteros::Selection::box
PeriodicBox & box()
Returns periodic box of the frame pointed by selection The same as:
Definition: selection.h:979
pteros::Selection::rotate
void rotate(Vector3f_const_ref pivot, Vector3f_const_ref axis, float angle)
Rotate selection around given axis relative to given pivot.
Definition: selection.cpp:1073
pteros::Selection::fit
friend void fit(Selection &sel1, const Selection &sel2)
Fit two selection of the same size. sel1 is modified to be fit to sel2.
Definition: selection.cpp:1313
pteros::Selection::unwrap
void unwrap(Array3i_const_ref pbc=fullPBC, int pbc_atom=-1)
Unwraps selection to make it whole if possible (without jumps over periodic box boundary).
Definition: selection.cpp:1926
pteros::Selection::z
float & z(int ind)
Extracts Z for current frame.
Definition: selection.h:892
pteros::Selection::get_internal_bonds
std::vector< std::vector< int > > get_internal_bonds(float d, bool periodic=true) const
Get all bonds within this selection returned as local selection indexes in form 1->[2,...
Definition: selection.cpp:1528
pteros::Selection::translate
void translate(Vector3f_const_ref v)
Translate selection by given vector.
Definition: selection.cpp:1060
pteros::Selection::end
iterator end()
End iterator.
Definition: selection.cpp:680
pteros::Selection::set_mass
void set_mass(const std::vector< float > &m)
Set atom masses in selection to the values from supplied vector.
pteros::Selection::split_by_contiguous_residue
void split_by_contiguous_residue(std::vector< Selection > &parts)
Split selection into contiguous ranges of resindexes.
Definition: selection.cpp:1788
pteros::Selection::apply
void apply()
Recomputes selection without re-parsing selection text.
Definition: selection.cpp:656
pteros::Selection::index_back_inserter
std::back_insert_iterator< std::vector< int > > index_back_inserter()
Get back_insert_iterator for index.
Definition: selection.h:343
pteros::Selection::append
void append(const Selection &sel)
Append another selection to this one.
Definition: selection.cpp:209
pteros::Selection::dihedral
float dihedral(int i, int j, int k, int l, Array3i_const_ref pbc=fullPBC) const
Get dihedral angle in degrees between three atoms (periodic in given dimensions if needed).
Definition: selection.cpp:1915
pteros::System
The system of atoms.
Definition: system.h:93
pteros::Selection::set_xyz
void set_xyz(MatrixXf_const_ref coord)
Set coordinates of this selection for current frame.
Definition: selection.cpp:787
pteros::Selection::inertia
void inertia(Vector3f_ref moments, Matrix3f_ref axes, Array3i_const_ref pbc=noPBC, int pbc_atom=-1) const
Computes the central momens of inertia and principal axes of inertia.
Definition: selection.cpp:1802
pteros::Selection::fit_trajectory
void fit_trajectory(int ref_frame=0, int b=0, int e=-1)
Fit specified frames in the trajectory to reference frame.
Definition: selection.cpp:1341
pteros::Selection::set_system
void set_system(const System &sys)
Sets new system for selection.
Definition: selection.cpp:296
pteros::Selection::z
float & z(int ind, int fr)
Extracts Z for given frame frame fr.
Definition: selection.h:895
pteros::Selection::xyz_ptr
Eigen::Vector3f * xyz_ptr(int ind) const
Returns pointer to the coordinates of given atom for current frame.
Definition: selection.h:907
pteros::Selection::begin
iterator begin()
Begin iterator.
Definition: selection.cpp:676
pteros::Selection::non_bond_energy
Eigen::Vector2f non_bond_energy(float cutoff=0, bool pbc=true) const
Self-energy of selection computed within given interaction cut-off.
Definition: selection.cpp:1321
pteros::Selection::flatten
void flatten()
"Flattens" selection by removing coordinate dependence and making it not text-based.
Definition: selection.cpp:1493
pteros::Selection::translate_to
void translate_to(Vector3f_const_ref p, bool mass_weighted=false, Array3i_const_ref pbc=noPBC, int pbc_atom=-1)
Translate center of masses of selection to given point.
Definition: selection.cpp:1066
pteros::Selection::rmsd
float rmsd(int fr) const
RMSD between current and another frame.
Definition: selection.cpp:1122
pteros::Selection::get_vel
Eigen::MatrixXf get_vel(bool make_row_major_matrix=false) const
Get velocities of all atoms in this selection for the current frame By default columnt of the matrix ...
Definition: selection.cpp:798
pteros::Selection::set_tag
void set_tag(const std::vector< std::string > &data)
Set tags in selection to the values from supplied vector.
pteros::Selection::write
void write(std::string fname, int b=-1, int e=-1) const
Write structure or trajectory for selection.
Definition: selection.cpp:1421
pteros::Selection::get_beta
std::vector< float > get_beta() const
Get beta.
pteros::Selection::~Selection
virtual ~Selection()
Destructor.
Definition: selection.cpp:205
pteros::Selection::vel
Eigen::Vector3f & vel(int ind, int fr)
Extracts velocity for given frame fr.
Definition: selection.h:914
pteros::Selection::coord_dependent
bool coord_dependent() const
Returns true if selection is coordinate-dependent and is able to recompute itself on the change of fr...
Definition: selection.cpp:1489
pteros::Selection::operator|
friend Selection operator|(const Selection &sel1, const Selection &sel2)
Creates new Selection, which is the logical OR of two parent selections.
Definition: selection.cpp:547
pteros::AtomHandler
Auxilary type used to incapsulate the atom and its current coordinates Used internally in Selection::...
Definition: atom_handler.h:49
pteros::Selection::set_occupancy
void set_occupancy(const std::vector< float > &data)
Set occupancy in selection to the values from supplied vector.
pteros::Selection::split
void split(std::vector< Selection > &parts, F callback)
Split selection by the values returned by custom callback function.
Definition: selection.h:817
pteros::Selection::set_name
void set_name(const std::vector< std::string > &data)
Set atom names in selection from supplied vector.
pteros::Selection::mirror
void mirror(int dim, float around=0)
Mirror selection along one of coordinates around given point.
Definition: selection.cpp:1077
pteros::Selection::set_resname
void set_resname(const std::vector< std::string > &data)
Set resnames in selection from supplied vector.
pteros::Selection::get_resid
std::vector< int > get_resid(bool unique=false) const
Get vector of all resid's in selection.
pteros::Selection::powersasa
float powersasa(float probe_r=0.14, std::vector< float > *area_per_atom=nullptr, float *total_volume=nullptr, std::vector< float > *volume_per_atom=nullptr) const
Get the SASA using powersasa algorithm. Returns area and computes volume and per-atom values if asked...
Definition: selection.cpp:2156
pteros::Selection::text_based
bool text_based() const
Returns true if selection was created from text string and false if it was constructed 'by hand' by a...
Definition: selection.cpp:1485
pteros::Selection::get_mass
std::vector< float > get_mass() const
Get masses of all atoms in selection.
pteros::Selection::get_tag
std::vector< std::string > get_tag(bool unique=false) const
Get tags.
pteros::Selection::vdw
float vdw(int ind) const
Extracts resindex.
Definition: selection.cpp:1611
pteros::Selection::set_chain
void set_chain(const std::vector< char > &data)
Set chains from supplied vector.
pteros::Selection::iterator
Random-access forward iterator for Selection.
Definition: selection.h:1016
pteros::Selection::get_force
Eigen::MatrixXf get_force(bool make_row_major_matrix=false) const
Get forces of all atoms in this selection for the current frame By default columnt of the matrix cont...
Definition: selection.cpp:829
pteros::Selection::clear
void clear()
Clears selection and frees memory.
Definition: selection.cpp:303
pteros::Selection::atom_traj
Eigen::MatrixXf atom_traj(int ind, int b=0, int e=-1, bool make_row_major_matrix=false) const
Extracts X,Y,Z for given atom index for specified range of frames (gets trajectory of given atom).
Definition: selection.cpp:1621
pteros::Selection::is_large
bool is_large()
Checks if selection is larger than 1/2 of the box size in any dimension.
Definition: selection.cpp:897
pteros::Selection::get_system
System * get_system() const
Get pointer to the system, which is pointed by this selection.
Definition: selection.h:370
pteros::Selection::set_force
void set_force(MatrixXf_const_ref coord)
Set forces of this selection for current frame.
Definition: selection.cpp:845
pteros::Selection::force
Eigen::Vector3f & force(int ind, int fr)
Extracts force for given frame fr.
Definition: selection.h:921
pteros::Selection::index_begin
std::vector< int >::const_iterator index_begin() const
Get const iterator for begin of index.
Definition: selection.h:337
pteros::Selection::atom
Atom & atom(int ind)
Extracts whole atom.
Definition: selection.h:955
pteros::Selection::operator<<
friend std::ostream & operator<<(std::ostream &os, const Selection &sel)
Writing selection to stream.
Definition: selection.cpp:584
pteros::Selection::invert
void invert()
Inverts selection in place by selecting those atoms which were not selected.
Definition: selection.cpp:272
pteros::Selection::get_resname
std::vector< std::string > get_resname(bool unique=false) const
Get vector of all resnames in selection.
pteros::Selection::principal_orient
void principal_orient(Array3i_const_ref pbc=noPBC, int pbc_atom=-1)
Orient molecule by its principal axes.
Definition: selection.cpp:2042
pteros::Selection::force
Eigen::Vector3f & force(int ind)
Extracts force for current frame.
Definition: selection.h:918
pteros::Selection::get_chain
std::vector< char > get_chain(bool unique=false) const
Get vector of all chains in selection.
pteros::PeriodicBox
Class encapsulating all operations with arbitrary triclinic periodic boxes This class stores the peri...
Definition: periodic_box.h:43
pteros::Selection::center
Eigen::Vector3f center(bool mass_weighted=false, Array3i_const_ref pbc=noPBC, int pbc_atom=-1) const
Get the center of selection.
Definition: selection.cpp:911
pteros::Selection::sasa
float sasa(float probe_r=0.14, std::vector< float > *area_per_atom=nullptr, int n_sphere_points=960) const
Get SASA using Shrake and Rupley algorithm (slower than powersasa and can't compute volumes)
Definition: selection.cpp:2167
pteros::Selection::unwrap_bonds
int unwrap_bonds(float d, Array3i_const_ref pbc=fullPBC, int pbc_atom=-1)
Unwraps selection to make it whole (without jumps over periodic box boundary).
Definition: selection.cpp:1939
pteros::Selection::x
float & x(int ind, int fr)
Extracts X for given frame frame fr.
Definition: selection.h:881
pteros::Selection::get_index
std::vector< int > get_index() const
Get vector of all indexes in selection.
Definition: selection.h:377
pteros::SelectionParser
Selection parser class.
Definition: selection_parser.h:59
pteros::Selection::num_residues
int num_residues() const
Returns total number of residues in selection. Partial residues are also included.
Definition: selection.cpp:2047
pteros::Selection::Selection
Selection()
Default constructor for empty selection.
Definition: selection.cpp:89
pteros::Selection::average_structure
Eigen::MatrixXf average_structure(int b=0, int e=-1, bool make_row_major_matrix=false) const
Computes average structure over the range of frames.
Definition: selection.cpp:867
pteros::Selection::wrap
void wrap(Array3i_const_ref pbc=fullPBC)
Wraps whole selection to the periodic box.
Definition: selection.cpp:1920
pteros::Selection::xyz
Eigen::Vector3f & xyz(int ind)
Extracts X,Y and Z for current frame.
Definition: selection.h:899
pteros::Selection::angle
float angle(int i, int j, int k, Array3i_const_ref pbc=fullPBC) const
Get angle in degrees between three atoms (periodic in given dimensions if needed).
Definition: selection.cpp:1910
pteros::Selection::set_vel
void set_vel(MatrixXf_const_ref data)
Set velocities of this selection for current frame.
Definition: selection.cpp:814
pteros::Selection::set_frame
void set_frame(int fr)
Set current frame for selection.
Definition: selection.cpp:663
pteros::Selection::operator[]
AtomHandler operator[](int ind)
Indexing operator.
Definition: selection.cpp:515
pteros::Selection::set_beta
void set_beta(const std::vector< float > &data)
Set beta in selection to the values from supplied vector.
pteros::Selection::split_by_residue
void split_by_residue(std::vector< Selection > &res)
Split selection by residue index.
Definition: selection.cpp:1719
pteros::Selection::minmax
void minmax(Vector3f_ref min, Vector3f_ref max) const
Get minimal and maximal coordinates in selection.
Definition: selection.cpp:1387
pteros::Selection::split_by_chain
void split_by_chain(std::vector< Selection > &chains)
Split selection by chain.
Definition: selection.cpp:1758
pteros::Selection::each_residue
void each_residue(std::vector< Selection > &sel) const
Selects each residue, which is referenced by selection.
Definition: selection.cpp:1555
pteros::Selection::element_name
std::string element_name(int ind) const
Extracts element name based on element_number. Read only.
Definition: selection.cpp:1615
pteros::Selection::get_frame
int get_frame() const
Get current frame selection is pointing to.
Definition: selection.h:363
pteros::Selection::dssp
std::string dssp() const
Determines secondary structure with DSSP algorithm and return it as a code string.
Definition: selection.cpp:1602
pteros::Selection::y
float & y(int ind, int fr)
Extracts Y for given frame frame fr.
Definition: selection.h:888
pteros::Atom
Class which represents a single atom.
Definition: atom.h:39
pteros::Selection::to_gromacs_ndx
std::string to_gromacs_ndx(std::string name) const
Returns a string formatted as Gromacs ndx file containing the current selection with given name.
Definition: selection.cpp:1499
pteros::Selection::index
int index(int ind) const
Extracts type.
Definition: selection.h:952
pteros::Selection::apply_transform
void apply_transform(const Eigen::Affine3f &t)
Apply transformation.
Definition: selection.cpp:1130
pteros::Selection::get_xyz
Eigen::MatrixXf get_xyz(bool make_row_major_matrix=false) const
Get coordinates of all atoms in this selection for the current frame By default columnt of the matrix...
Definition: selection.cpp:773
pteros::Selection::x
float & x(int ind)
Extracts X for current frame.
Definition: selection.h:878
pteros::Selection::remove
void remove(const Selection &sel)
Remove all atoms of sel from current selection.
Definition: selection.cpp:253
pteros::Selection::select
Selection select(std::string str)
Sub-selections allow selecting atoms inside existing selection (narrowing or refining existing select...
Definition: selection.cpp:313
pteros::Selection::vel
Eigen::Vector3f & vel(int ind)
Extracts velocity for current frame.
Definition: selection.h:911