Pteros  2.0
Molecular modeling library for human beings!
atom_proxy.h
1 /*
2  *
3  * This source code is part of
4  * ******************
5  * *** Pteros ***
6  * ******************
7  * molecular modeling library
8  *
9  * Copyright (c) 2009-2015, Semen Yesylevskyy
10  *
11  * All works, which use Pteros, should cite:
12  *
13  * Semen O. Yesylevskyy, "Pteros: Fast and easy to use open-source
14  * C++ library for molecular analysis",
15  * Journal of Computational Chemistry, 2012, 33(19), 1632–1636.
16  *
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of Artistic License:
19  * Read http://www.opensource.org/licenses/artistic-license-2.0.php
20  *
21 */
22 
23 #ifndef SELECTION_H
24 #define SELECTION_H
25 
26 #include <iostream>
27 
28 #include <string>
29 #include <memory>
30 #include <functional>
31 #include <Eigen/Core>
32 #include <Eigen/Geometry>
33 #include "pteros/core/system.h"
34 #include "pteros/core/typedefs.h"
35 
36 namespace pteros {
37 
38 // Forward declaration of friend classes
39 class System;
40 class Selection_parser;
41 class Atom_proxy;
42 
57 class Selection {
58  // System and Selection are friends because they are closely integrated.
59  friend class System;
60  friend class Selection_parser;
61  friend class Grid_searcher;
62 
63  public:
64  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67 
69  Selection();
70 
74  Selection(const System& sys);
75 
80  Selection(const System& sys, std::string str, int fr = 0);
81 
90  Selection(const System& sys, int ind1, int ind2);
91 
94  Selection(const System& sys, const std::vector<int>& ind);
95 
98  Selection(const System& sys,
99  std::vector<int>::iterator it1,
100  std::vector<int>::iterator it2);
101 
110  Selection(const System& sys,
111  const std::function<void(const System&,int,std::vector<int>&)>& callback,
112  int fr = 0);
113 
115  Selection(const Selection& sel);
116 
118  virtual ~Selection();
119 
122 
125  bool operator==(const Selection &other) const;
126 
129  bool operator!=(const Selection &other) const {
130  return !(*this == other);
131  }
132 
154  Atom_proxy operator[](int ind) const;
155 
156  // Writing selection to stream.
157  // Outputs indexes as a space separated list
158  friend std::ostream& operator<<(std::ostream& os, const Selection& sel);
159 
162  friend Selection operator|(const Selection& sel1, const Selection& sel2);
163 
166  friend Selection operator&(const Selection& sel1, const Selection& sel2);
167 
171  friend Selection operator-(const Selection& sel1, const Selection& sel2);
172 
175  Selection operator~() const;
177 
178  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
181 
183  void append(const Selection& sel);
184 
186  void append(int ind);
187 
189  void remove(const Selection& sel);
190 
192  void remove(int ind);
193 
195  void invert();
196 
199  void set_system(const System& sys);
200 
205  void modify(std::string str, int fr = 0);
206 
208  void modify(int ind1, int ind2);
209 
212  void modify(const std::vector<int>& ind);
213 
216  void modify(std::vector<int>::iterator it1, std::vector<int>::iterator it2);
217 
226  void modify(const std::function<void(const System&,int,std::vector<int>&)>& callback, int fr = 0);
227 
229  void modify(const System& sys, std::string str, int fr = 0);
230 
232  void modify(const System& sys, int ind1, int ind2);
233 
235  void modify(const System& sys, const std::vector<int>& ind);
236 
238  void modify(const System& sys,
239  std::vector<int>::iterator it1,
240  std::vector<int>::iterator it2);
241 
243  void modify(const System& sys, const std::function<void(const System&,int,std::vector<int>&)>& callback, int fr = 0);
244 
250  void apply();
251 
257  void update();
258 
263  void clear();
265 
266  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
268 
298  Selection select(std::string str);
300  Selection operator()(std::string str);
301 
303  Selection select(int ind1, int ind2);
304  Selection operator()(int ind1, int ind2);
305 
307  Selection select(const std::vector<int>& ind);
308  Selection operator()(const std::vector<int>& ind);
310 
311  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
314 
316  std::vector<int>::const_iterator index_begin() const { return index.begin(); }
317 
319  std::vector<int>::const_iterator index_end() const { return index.end(); }
320 
322  std::back_insert_iterator<std::vector<int> > index_back_inserter() {
323  return std::back_inserter(index);
324  }
325 
328  class iterator;
329 
331  iterator begin();
333  iterator end();
335 
336 
337  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
340 
342  int get_frame() const {return frame;}
343 
346  void set_frame(int fr);
347 
349  System* get_system() const { return system; }
350 
353  std::string get_text() const;
354 
356  std::vector<int> get_index() const { return index; }
357 
359  std::vector<char> get_chain() const;
360 
363  void set_chain(const std::vector<char>& data);
364 
366  void set_chain(char data);
367 
369  std::vector<char> get_unique_chain() const;
370 
373  std::vector<int> get_resid() const;
374 
376  std::vector<int> get_unique_resid() const;
377 
380  void set_resid(const std::vector<int>& data);
381 
383  void set_resid(int data);
384 
387  std::vector<int> get_resindex() const;
388 
390  std::vector<int> get_unique_resindex() const;
391 
393  std::vector<std::string> get_name() const;
394 
397  void set_name(const std::vector<std::string>& data);
398 
400  void set_name(std::string& data);
401 
403  std::vector<std::string> get_resname() const;
404 
407  void set_resname(const std::vector<std::string>& data);
408 
410  void set_resname(std::string& data);
411 
413  Eigen::MatrixXf get_xyz() const;
414 
416  void get_xyz(MatrixXf_ref res) const;
417 
419  void set_xyz(MatrixXf_const_ref coord);
420 
422  std::vector<float> get_mass() const;
423 
426  void set_mass(const std::vector<float> m);
427 
429  void set_mass(float data);
430 
432  std::vector<float> get_beta() const;
433 
436  void set_beta(std::vector<float>& data);
437 
439  void set_beta(float data);
440 
442  std::vector<float> get_occupancy() const;
443 
446  void set_occupancy(std::vector<float>& data);
447 
449  void set_occupancy(float data);
451 
452 
453  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
456 
467  Eigen::Vector3f center(bool mass_weighted = false, bool periodic = false) const;
468 
470  void minmax(Vector3f_ref min, Vector3f_ref max) const;
471 
473  float sasa(float probe_r = 0.14, float* total_volume = nullptr,
474  std::vector<float>* area_per_atom = nullptr,
475  std::vector<float>* volume_per_atom = nullptr) const;
476 
478  Eigen::MatrixXf average_structure(int b=0, int e=-1) const;
479 
484  Eigen::MatrixXf atom_traj(int ind, int b=0, int e=-1) const;
485 
493  void inertia(Vector3f_ref moments, Matrix3f_ref axes, bool periodic = false) const;
494 
502  float gyration(bool periodic = false) const;
503 
507  float distance(int i, int j, bool is_periodic = true,
508  Vector3i_const_ref dims = Eigen::Vector3i::Ones()) const;
509 
513  float angle(int i, int j, int k, bool is_periodic = true,
514  Vector3i_const_ref dims = Eigen::Vector3i::Ones()) const;
515 
519  float dihedral(int i, int j, int k, int l, bool is_periodic = true,
520  Vector3i_const_ref dims = Eigen::Vector3i::Ones()) const;
521 
523 
524 
525  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
528 
530  void translate(Vector3f_const_ref v);
531 
535  void rotate(int axis, float angle);
536 
541  void rotate(int axis, float angle, Vector3f_const_ref pivot);
542 
547  void rotate(Vector3f_const_ref direction, float angle, Vector3f_const_ref pivot);
548 
550  void rotate(Matrix3f_const_ref m);
551 
553  void rotate(Vector3f_const_ref angles, Vector3f_const_ref pivot);
554 
556  void wrap(Vector3i_const_ref dims = Eigen::Vector3i::Ones());
557 
564  void unwrap(Vector3i_const_ref dims = Eigen::Vector3i::Ones());
565 
573  int unwrap_bonds(float d = 0.2, int leading_index = 0,
574  Vector3i_const_ref dims = Eigen::Vector3i::Ones());
575 
581  Eigen::Affine3f principal_transform(bool is_periodic = false) const;
582 
590  void principal_orient(bool is_periodic = false);
592 
593 
594  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
597 
599  float rmsd(int fr) const;
600 
602  float rmsd(int fr1, int fr2) const;
603 
605  friend float rmsd(const Selection& sel1, const Selection& sel2);
606 
613  friend float rmsd(const Selection& sel1, int fr1, const Selection& sel2, int fr2);
614 
616  friend void fit(Selection& sel1, const Selection& sel2);
617 
619  void fit_trajectory(int ref_frame=0, int b=0, int e=-1);
620 
622  friend Eigen::Affine3f fit_transform(const Selection& sel1, const Selection& sel2);
623 
625  Eigen::Affine3f fit_transform(int fr1, int fr2) const;
626 
628  void fit(int fr1, int fr2);
629 
631  void apply_transform(const Eigen::Affine3f& t);
633 
634 
635  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
638 
642  Energy_components non_bond_energy(float cutoff=0.25, bool periodic=true) const;
643 
647  // Default value should be given in definition of friend function!
648  friend Energy_components non_bond_energy(const Selection& sel1,
649  const Selection& sel2,
650  float cutoff,
651  int fr,
652  bool periodic);
653 
655 
656 
657  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
660 
666  // Can't be made const because of internal calls
667  void write(std::string fname, int b=-1,int e=-1);
668 
669  void write(const std::unique_ptr<Mol_file>& handler, Mol_file_content what,int b=-1,int e=-1);
671 
672 
673  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
676 
678  int size() const {return index.size();}
679 
682  bool text_based() const {
683  return sel_text!="";
684  }
685 
688  bool coord_dependent() const {
689  return (bool)parser;
690  }
691 
695  void flatten();
696 
698 
699  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
702 
706  void split_by_connectivity(float d, std::vector<Selection>& res, bool periodic=true);
707 
709  void split_by_residue(std::vector<Selection>& res);
710 
712  void split_by_chain(std::vector<Selection>& chains);
713 
715  void split_by_contiguous_index(std::vector<Selection>& parts);
716 
718  void split_by_contiguous_residue(std::vector<Selection>& parts);
719 
723  void each_residue(std::vector<Selection>& sel) const;
725 
726 
727  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
737 
740  inline float& X(int ind){
741  return system->traj[frame].coord[index[ind]](0);
742  }
743 
744  inline const float& X(int ind) const {
745  return system->traj[frame].coord[index[ind]](0);
746  }
747 
749  inline float& X(int ind, int fr){
750  return system->traj[fr].coord[index[ind]](0);
751  }
752 
753  inline const float& X(int ind, int fr) const {
754  return system->traj[fr].coord[index[ind]](0);
755  }
756 
758  inline float& Y(int ind){
759  return system->traj[frame].coord[index[ind]](1);
760  }
761 
762  inline const float& Y(int ind) const {
763  return system->traj[frame].coord[index[ind]](1);
764  }
765 
767  inline float& Y(int ind, int fr){
768  return system->traj[fr].coord[index[ind]](1);
769  }
770 
771  inline const float& Y(int ind, int fr) const {
772  return system->traj[fr].coord[index[ind]](1);
773  }
774 
776  inline float& Z(int ind){
777  return system->traj[frame].coord[index[ind]](2);
778  }
779 
780  inline const float& Z(int ind) const {
781  return system->traj[frame].coord[index[ind]](2);
782  }
783 
785  inline float& Z(int ind, int fr){
786  return system->traj[fr].coord[index[ind]](2);
787  }
788 
789  inline const float& Z(int ind, int fr) const {
790  return system->traj[fr].coord[index[ind]](2);
791  }
792 
794  inline Eigen::Vector3f& XYZ(int ind){
795  return system->traj[frame].coord[index[ind]];
796  }
797 
798  inline const Eigen::Vector3f& XYZ(int ind) const {
799  return system->traj[frame].coord[index[ind]];
800  }
801 
804  inline Eigen::Vector3f* XYZ_ptr(int ind) const {
805  return &(system->traj[frame].coord[index[ind]]);
806  }
807 
809  inline Eigen::Vector3f& XYZ(int ind, int fr){
810  return system->traj[fr].coord[index[ind]];
811  }
812 
813  inline const Eigen::Vector3f& XYZ(int ind, int fr) const {
814  return system->traj[fr].coord[index[ind]];
815  }
816 
818  inline int& Type(int ind){
819  return system->atoms[index[ind]].type;
820  }
821 
822  inline const int& Type(int ind) const {
823  return system->atoms[index[ind]].type;
824  }
825 
827  inline std::string& Type_name(int ind){
828  return system->atoms[index[ind]].type_name;
829  }
830 
831  inline const std::string& Type_name(int ind) const {
832  return system->atoms[index[ind]].type_name;
833  }
834 
836  inline std::string& Resname(int ind){
837  return system->atoms[index[ind]].resname;
838  }
839 
840  inline const std::string& Resname(int ind) const {
841  return system->atoms[index[ind]].resname;
842  }
843 
845  inline char& Chain(int ind){
846  return system->atoms[index[ind]].chain;
847  }
848 
849  inline const char& Chain(int ind) const {
850  return system->atoms[index[ind]].chain;
851  }
852 
854  inline std::string& Name(int ind){
855  return system->atoms[index[ind]].name;
856  }
857 
858  inline const std::string& Name(int ind) const {
859  return system->atoms[index[ind]].name;
860  }
861 
863  inline float& Mass(int ind){
864  return system->atoms[index[ind]].mass;
865  }
866 
867  inline const float& Mass(int ind) const {
868  return system->atoms[index[ind]].mass;
869  }
870 
872  inline float& Charge(int ind){
873  return system->atoms[index[ind]].charge;
874  }
875 
876  inline const float& Charge(int ind) const {
877  return system->atoms[index[ind]].charge;
878  }
879 
881  inline float& Beta(int ind){
882  return system->atoms[index[ind]].beta;
883  }
884 
885  inline const float& Beta(int ind) const {
886  return system->atoms[index[ind]].beta;
887  }
888 
890  inline float& Occupancy(int ind){
891  return system->atoms[index[ind]].occupancy;
892  }
893 
894  inline const float& Occupancy(int ind) const {
895  return system->atoms[index[ind]].occupancy;
896  }
897 
899  inline int& Resid(int ind){
900  return system->atoms[index[ind]].resid;
901  }
902 
903  inline const int& Resid(int ind) const {
904  return system->atoms[index[ind]].resid;
905  }
906 
908  inline int& Index(int ind){
909  return index[ind];
910  }
911 
912  inline const int& Index(int ind) const {
913  return index[ind];
914  }
915 
917  inline std::string& Tag(int ind){
918  return system->atoms[index[ind]].tag;
919  }
920 
921  inline const std::string& Tag(int ind) const {
922  return system->atoms[index[ind]].tag;
923  }
924 
926  inline pteros::Atom& Atom_data(int ind){
927  return system->atoms[index[ind]];
928  }
929 
930  inline const pteros::Atom& Atom_data(int ind) const {
931  return system->atoms[index[ind]];
932  }
933 
935  inline int& Resindex(int ind){
936  return system->atoms[index[ind]].resindex;
937  }
938 
939  inline const int& Resindex(int ind) const {
940  return system->atoms[index[ind]].resindex;
941  }
942 
944  inline float VDW(int ind) const {
945  switch(system->atoms[index[ind]].name[0]){
946  case 'H': return 0.1;
947  case 'C': return 0.17;
948  case 'N': return 0.1625;
949  case 'O': return 0.149; //mean value used
950  case 'S': return 0.1782;
951  case 'P': return 0.1871;
952  default: return 0.17;
953  }
954  }
955 
964  inline Periodic_box& Box() {
965  return system->traj[frame].box;
966  }
967 
968  inline const Periodic_box& Box() const {
969  return system->traj[frame].box;
970  }
971 
980  inline float& Time() {
981  return system->traj[frame].time;
982  }
983 
984  inline const float& Time() const {
985  return system->traj[frame].time;
986  }
987 
989 
990 protected:
991  // Row text of selection
992  std::string sel_text;
993  // Indexes of atoms in selection
994  std::vector<int> index;
995  // Pointer to target system
996  System* system;
997 
998  // Stores current frame
999  int frame;
1000 
1001  // Holds an instance of selection parser
1002  std::unique_ptr<Selection_parser> parser;
1003  void allocate_parser();
1004  void sort_and_remove_duplicates();
1005 };
1006 
1007 //==============================================================================
1008 
1012 class Atom_proxy {
1013  friend class Selection::iterator;
1014 public:
1015  Atom_proxy(){}
1016  Atom_proxy(Selection* s, int i): sel(s), ind(i) {}
1017 
1020  inline int& Resid(){ return sel->Resid(ind); }
1021  inline const int& Resid() const { return sel->Resid(ind); }
1022 
1023  inline int& Index(){ return sel->Index(ind); }
1024  inline const int& Index() const { return sel->Index(ind); }
1025 
1026  inline std::string& Name(){ return sel->Name(ind); }
1027  inline const std::string& Name() const { return sel->Name(ind); }
1028 
1029  inline char& Chain(){ return sel->Chain(ind); }
1030  inline const char& Chain() const { return sel->Chain(ind); }
1031 
1032  inline std::string& Resname(){ return sel->Resname(ind); }
1033  inline const std::string& Resname() const { return sel->Resname(ind); }
1034 
1035  inline std::string& Tag(){ return sel->Tag(ind); }
1036  inline const std::string& Tag() const { return sel->Tag(ind); }
1037 
1038  inline float& Occupancy(){ return sel->Occupancy(ind); }
1039  inline const float& Occupancy() const { return sel->Occupancy(ind); }
1040 
1041  inline float& Beta(){ return sel->Beta(ind); }
1042  inline const float& Beta() const { return sel->Beta(ind); }
1043 
1044  inline int& Resindex(){ return sel->Resindex(ind); }
1045  inline const int& Resindex() const { return sel->Resindex(ind); }
1046 
1047  inline float& Mass(){ return sel->Mass(ind); }
1048  inline const float& Mass() const { return sel->Mass(ind); }
1049 
1050  inline float& Charge(){ return sel->Charge(ind); }
1051  inline const float& Charge() const { return sel->Charge(ind); }
1052 
1053  inline int& Type(){ return sel->Type(ind); }
1054  inline const int& Type() const { return sel->Type(ind); }
1055 
1056  inline std::string& Type_name(){ return sel->Type_name(ind); }
1057  inline const std::string& Type_name() const { return sel->Type_name(ind); }
1058 
1059  inline float& X(){ return sel->X(ind); }
1060  inline const float& X() const { return sel->X(ind); }
1061 
1062  inline float& Y(){ return sel->Y(ind); }
1063  inline const float& Y() const { return sel->Y(ind); }
1064 
1065  inline float& Z(){ return sel->Z(ind); }
1066  inline const float& Z() const { return sel->Z(ind); }
1067 
1068  inline Eigen::Vector3f& XYZ(){ return sel->XYZ(ind); }
1069  inline const Eigen::Vector3f& XYZ() const { return sel->XYZ(ind); }
1070 
1071  inline float& X(int fr){ return sel->X(ind,fr); }
1072  inline const float& X(int fr) const { return sel->X(ind,fr); }
1073 
1074  inline float& Y(int fr){ return sel->Y(ind,fr); }
1075  inline const float& Y(int fr) const { return sel->Y(ind,fr); }
1076 
1077  inline float& Z(int fr){ return sel->Z(ind,fr); }
1078  inline const float& Z(int fr) const { return sel->Z(ind,fr); }
1079 
1080  inline Eigen::Vector3f& XYZ(int fr){ return sel->XYZ(ind,fr); }
1081  inline const Eigen::Vector3f& XYZ(int fr) const { return sel->XYZ(ind,fr); }
1082 
1083  inline Atom& Atom_data(){ return sel->Atom_data(ind); }
1084  inline const Atom& Atom_data() const { return sel->Atom_data(ind); }
1085 
1087 
1089  bool operator==(const Atom_proxy& other) const {
1090  return (sel==other.sel && ind==other.ind);
1091  }
1092 
1094  bool operator!=(const Atom_proxy &other) const {
1095  return !(*this == other);
1096  }
1097 
1098 protected:
1099  Selection* sel;
1100  int ind;
1101 };
1102 
1103 //==============================================================================
1104 
1107 public:
1108  typedef Atom_proxy value_type;
1109  typedef int difference_type;
1110  typedef Atom_proxy* pointer;
1111  typedef Atom_proxy& reference;
1112  typedef std::forward_iterator_tag iterator_category;
1113 
1114  iterator(Selection* sel, int pos) { proxy.sel = sel; proxy.ind = pos; }
1115  iterator operator++() { iterator tmp = *this; proxy.ind++; return tmp; }
1116  iterator operator++(int junk) { proxy.ind++; return *this; }
1117  Atom_proxy& operator*() { return proxy; }
1118  Atom_proxy* operator->() { return &proxy; }
1119  bool operator==(const iterator& rhs) { return proxy == rhs.proxy; }
1120  bool operator!=(const iterator& rhs) { return proxy != rhs.proxy; }
1121 private:
1122  Atom_proxy proxy;
1123 };
1124 
1125 } // namespace pteros
1126 #endif /* SELECTION_H */
Selection parser class.
Definition: selection_parser.h:145
Eigen::Vector3f & XYZ(int ind)
Extracts X,Y and Z for current frame.
Definition: atom_proxy.h:794
float dihedral(int i, int j, int k, int l, bool is_periodic=true, Vector3i_const_ref dims=Eigen::Vector3i::Ones()) const
Get dihedral angle in degrees between three atoms (periodic in given dimensions if needed)...
Definition: selection.cpp:1862
friend Selection operator|(const Selection &sel1, const Selection &sel2)
Creates new Selection, which is the logical OR of two parent selections.
Definition: selection.cpp:504
Periodic_box & Box()
Returns periodic box of the frame pointed by selection The same as:
Definition: atom_proxy.h:964
float rmsd(int fr) const
RMSD between current and another frame.
Definition: selection.cpp:1189
void principal_orient(bool is_periodic=false)
Orient molecule by its principal axes.
Definition: selection.cpp:1988
System * get_system() const
Get pointer to the system, which is pointed by this selection.
Definition: atom_proxy.h:349
Selection & operator=(Selection sel)
Assignment operator.
Definition: selection.cpp:450
float gyration(bool periodic=false) const
Computes radius of gyration for selection.
Definition: selection.cpp:1833
friend Selection operator-(const Selection &sel1, const Selection &sel2)
Creates new Selection, by removing all atoms of sel2 from sel1.
Definition: selection.cpp:549
friend Selection operator&(const Selection &sel1, const Selection &sel2)
Creates new Selection, which is the logical AND of two parent selections.
Definition: selection.cpp:522
Eigen::Vector3f * XYZ_ptr(int ind) const
Returns pointer to the coordinates of given atom for current frame.
Definition: atom_proxy.h:804
int & Resid(int ind)
Extracts residue number.
Definition: atom_proxy.h:899
std::vector< char > get_chain() const
Get vector of all chains in selection.
Definition: selection.cpp:641
std::vector< int >::const_iterator index_end() const
Get const iterator for the end of index.
Definition: atom_proxy.h:319
iterator begin()
Begin iterator.
Definition: selection.cpp:617
std::vector< float > get_occupancy() const
Get occupancy.
Definition: selection.cpp:911
int size() const
Get the size of selection.
Definition: atom_proxy.h:678
Pteros namespace.
Definition: options.cpp:32
Atom_proxy operator[](int ind) const
Indexing operator.
Definition: selection.cpp:478
char & Chain(int ind)
Extracts chain.
Definition: atom_proxy.h:845
bool operator!=(const Selection &other) const
Inequality operator Selection are compared by their indexes.
Definition: atom_proxy.h:129
void split_by_contiguous_residue(std::vector< Selection > &parts)
Split selection into contiguous ranges of resindexes.
Definition: selection.cpp:1756
float & Y(int ind)
Extracts Y for current frame.
Definition: atom_proxy.h:758
Auxilary type used to incapsulate the atom and its current coordinates Used internally in Selection::...
Definition: atom_proxy.h:1012
The system of atoms.
Definition: system.h:95
void flatten()
"Flattens" selection by removing coordinate dependence and making it not text-based.
Definition: selection.cpp:1551
iterator end()
End iterator.
Definition: selection.cpp:621
bool text_based() const
Returns true if selection was created from text string and false if it was constructed &#39;by hand&#39; by a...
Definition: atom_proxy.h:682
void set_resname(const std::vector< std::string > &data)
Set resnames in selection from supplied vector.
Definition: selection.cpp:815
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:629
float angle(int i, int j, int k, bool is_periodic=true, Vector3i_const_ref dims=Eigen::Vector3i::Ones()) const
Get angle in degrees between three atoms (periodic in given dimensions if needed).
Definition: selection.cpp:1857
std::vector< int > get_unique_resindex() const
Get vector of unique resindexes&#39;s in selection.
Definition: selection.cpp:747
std::vector< char > get_unique_chain() const
Get vector of unique chains in selection.
Definition: selection.cpp:669
pteros::Atom & Atom_data(int ind)
Extracts whole atom.
Definition: atom_proxy.h:926
void set_system(const System &sys)
Sets new system for selection.
Definition: selection.cpp:262
void split_by_residue(std::vector< Selection > &res)
Split selection by residue index.
Definition: selection.cpp:1707
Energy_components non_bond_energy(float cutoff=0.25, bool periodic=true) const
Self-energy of selection computed within given interaction cut-off.
Definition: selection.cpp:1208
Selection class.
Definition: atom_proxy.h:57
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:1622
Components of the non-bond energy.
Definition: system.h:40
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:1407
std::back_insert_iterator< std::vector< int > > index_back_inserter()
Get back_insert_iterator for index.
Definition: atom_proxy.h:322
Selection select(std::string str)
Sub-selections allow selecting atoms inside existing selection (narrowing or refining existing select...
Definition: selection.cpp:279
std::vector< int > get_index() const
Get vector of all indexes in selection.
Definition: atom_proxy.h:356
int get_frame() const
Get current frame selection is pointing to.
Definition: atom_proxy.h:342
std::string & Type_name(int ind)
Extracts typename.
Definition: atom_proxy.h:827
Eigen::MatrixXf average_structure(int b=0, int e=-1) const
Computes average structure over the range of frames.
Definition: selection.cpp:851
Eigen::Affine3f principal_transform(bool is_periodic=false) const
Get transform for orienting selection by principal axes.
Definition: selection.cpp:1953
float & Z(int ind, int fr)
Extracts Z for given frame frame fr.
Definition: atom_proxy.h:785
float & X(int ind, int fr)
Extracts X for given frame frame fr.
Definition: atom_proxy.h:749
Class which represents a single atom.
Definition: atom.h:33
void modify(std::string str, int fr=0)
Modifies selection string in existing selection.
Definition: selection.cpp:354
void set_resid(const std::vector< int > &data)
Set resid&#39;s in selection from supplied vector.
Definition: selection.cpp:689
std::string & Tag(int ind)
Extracts tag.
Definition: atom_proxy.h:917
void split_by_contiguous_index(std::vector< Selection > &parts)
Split selection into contiguous ranges of indexes.
Definition: selection.cpp:1741
void invert()
Inverts selection in place by selection those atoms which were not selected.
Definition: selection.cpp:238
void inertia(Vector3f_ref moments, Matrix3f_ref axes, bool periodic=false) const
Computes the central momens of inertia and principal axes of inertia.
Definition: selection.cpp:1771
std::vector< float > get_beta() const
Get beta.
Definition: selection.cpp:882
void fit_trajectory(int ref_frame=0, int b=0, int e=-1)
Fit all frames in the trajectory to reference frame.
Definition: selection.cpp:1415
Selection()
Default constructor for absolutely empty selection.
Definition: selection.cpp:78
void wrap(Vector3i_const_ref dims=Eigen::Vector3i::Ones())
Wraps whole selection to the periodic box.
Definition: selection.cpp:1867
Random-access forward iterator for Selection.
Definition: atom_proxy.h:1106
void translate(Vector3f_const_ref v)
Translate selection by given vector.
Definition: selection.cpp:1058
void append(const Selection &sel)
Append another selection to this one.
Definition: selection.cpp:193
Eigen::MatrixXf atom_traj(int ind, int b=0, int e=-1) const
Extracts X,Y,Z for given atom index for specified range of frames (gets trajectory of given atom)...
Definition: selection.cpp:1607
void write(std::string fname, int b=-1, int e=-1)
Write structure or trajectory for selection.
Definition: selection.cpp:1500
float VDW(int ind) const
Computes VDW radius. Read only.
Definition: atom_proxy.h:944
int unwrap_bonds(float d=0.2, int leading_index=0, Vector3i_const_ref dims=Eigen::Vector3i::Ones())
Unwraps selection to make it whole (without jumps over periodic box boundary).
Definition: selection.cpp:1880
float & Mass(int ind)
Extracts atom mass.
Definition: atom_proxy.h:863
void set_frame(int fr)
Set current frame for selection.
Definition: selection.cpp:601
float & X(int ind)
Extracts X for current frame.
Definition: atom_proxy.h:740
void rotate(int axis, float angle)
Rotate selection around given axis relative to center of masses.
Definition: selection.cpp:1075
bool operator!=(const Atom_proxy &other) const
Inequality operator.
Definition: atom_proxy.h:1094
float & Charge(int ind)
Extracts atom charge.
Definition: atom_proxy.h:872
void apply_transform(const Eigen::Affine3f &t)
Apply fitting transformation.
std::vector< std::string > get_resname() const
Get vector of all resnames in selection.
Definition: selection.cpp:805
bool operator==(const Atom_proxy &other) const
Equality operator.
Definition: atom_proxy.h:1089
void set_mass(const std::vector< float > m)
Set atom masses in selection to the values from supplied vector.
Definition: selection.cpp:757
bool coord_dependent() const
Returns true if selection is coordinate-dependent and is able to recompute itself on the change of fr...
Definition: atom_proxy.h:688
float distance(int i, int j, bool is_periodic=true, Vector3i_const_ref dims=Eigen::Vector3i::Ones()) const
Get distance between two atoms (periodic in given dimensions if needed).
Definition: selection.cpp:1852
void split_by_chain(std::vector< Selection > &chains)
Split selection by chain.
Definition: selection.cpp:1724
Selection operator~() const
Creates new Selection, which is a logical negation of existing one.
Definition: selection.cpp:482
void set_chain(const std::vector< char > &data)
Set chains from supplied vector.
Definition: selection.cpp:650
void unwrap(Vector3i_const_ref dims=Eigen::Vector3i::Ones())
Unwraps selection to make it whole if possible (without jumps over periodic box boundary).
Definition: selection.cpp:1873
std::vector< float > get_mass() const
Get masses of all atoms in selection.
Definition: selection.cpp:717
void set_beta(std::vector< float > &data)
Set beta in selection to the values from supplied vector.
Definition: selection.cpp:891
void each_residue(std::vector< Selection > &sel) const
Selects each residue, which is referenced by selection.
Definition: selection.cpp:1577
std::string & Resname(int ind)
Extracts residue name.
Definition: atom_proxy.h:836
std::vector< int >::const_iterator index_begin() const
Get const iterator for begin of index.
Definition: atom_proxy.h:316
Eigen::MatrixXf get_xyz() const
Get coordinates of all atoms in this selection for the current frame.
Definition: selection.cpp:835
int & Index(int ind)
Extracts atom index in the system, which is pointed by selection.
Definition: atom_proxy.h:908
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:1309
virtual ~Selection()
Destructor.
Definition: selection.cpp:189
float & Time()
Returns time stamp of the frame pointed by selection The same as:
Definition: atom_proxy.h:980
Eigen::Vector3f & XYZ(int ind, int fr)
Extracts X,Y and Z for given frame frame fr.
Definition: atom_proxy.h:809
float & Y(int ind, int fr)
Extracts Y for given frame frame fr.
Definition: atom_proxy.h:767
void set_name(const std::vector< std::string > &data)
Set atom names in selection from supplied vector.
Definition: selection.cpp:786
float & Occupancy(int ind)
Extracts occupancy field.
Definition: atom_proxy.h:890
void minmax(Vector3f_ref min, Vector3f_ref max) const
Get minimal and maximal coordinates in selection.
Definition: selection.cpp:1466
int & Type(int ind)
Extracts type.
Definition: atom_proxy.h:818
float sasa(float probe_r=0.14, float *total_volume=nullptr, std::vector< float > *area_per_atom=nullptr, std::vector< float > *volume_per_atom=nullptr) const
Get the SASA. Returns area and computes volume and per-atom values if asked.
Definition: selection.cpp:2033
int & Resindex(int ind)
Extracts resindex.
Definition: atom_proxy.h:935
std::vector< int > get_resid() const
Get vector of all resid&#39;s in selection.
Definition: selection.cpp:680
void set_xyz(MatrixXf_const_ref coord)
Set coordinates of this selection for current frame.
Definition: selection.cpp:870
std::vector< int > get_resindex() const
Get vector of all resindexes in selection.
Definition: selection.cpp:708
Eigen::Vector3f center(bool mass_weighted=false, bool periodic=false) const
Get the center of selection.
Definition: selection.cpp:975
void apply()
Recomputes selection without re-parsing selection text.
Definition: selection.cpp:594
void clear()
Clears selection and frees memory.
Definition: selection.cpp:269
void set_occupancy(std::vector< float > &data)
Set occupancy in selection to the values from supplied vector.
Definition: selection.cpp:920
bool operator==(const Selection &other) const
Equality operator Selection are compared by their indexes.
Definition: selection.cpp:474
std::vector< int > get_unique_resid() const
Get vector of unique resid&#39;s in selection.
Definition: selection.cpp:726
std::string & Name(int ind)
Extracts atom name.
Definition: atom_proxy.h:854
float & Beta(int ind)
Extracts B-factor.
Definition: atom_proxy.h:881
float & Z(int ind)
Extracts Z for current frame.
Definition: atom_proxy.h:776
std::vector< std::string > get_name() const
Get vector of all atom names in selection.
Definition: selection.cpp:776
Class encapsulating all operations with arbitrary triclinic periodic boxes This class stores the peri...
Definition: periodic_box.h:47
void update()
Recomputes selection completely.
Definition: selection.cpp:589