Pteros  2.0
Molecular modeling library for human beings!
pteros::System Class Reference

The system of atoms. More...

#include <system.h>

Public Member Functions

AtomIterator atoms_begin ()
 Iterators and indexing {.
 
AtomIterator atoms_end ()
 
std::vector< Frame >::iterator traj_begin ()
 
std::vector< Frame >::iterator traj_end ()
 
AtomHandler operator[] (const std::pair< int, int > &ind_fr)
 
Constructors and operators
 System ()
 Default constructor.
 
 System (std::string fname)
 Constructor creating system from file.
 
 System (const System &other)
 Copy constructor.
 
Systemoperator= (const System &other)
 Assignment operator.
 
 System (const Selection &sel)
 Constructing new System from Selection of other system.
 
virtual ~System ()
 Destructor.
 
Adding, deleting and ordering groups of atoms

These methods update resindexes automatically.

Selection append (const System &sys)
 Append other system to this one Returns selection corresponding to appended atoms.
 
Selection append (const Selection &sel, bool current_frame=false)
 Append atoms from selection to this system. More...
 
Selection append (const Atom &at, Vector3f_const_ref coord)
 Append single atom to this system Returns selection corresponding to appended atom.
 
Selection append (const AtomHandler &at)
 Append Atom_proxy object to this system Returns selection corresponding to appended atom. More...
 
void rearrange (const std::vector< std::string > &sel_strings)
 Rearranges the atoms in the order of provided selection strings. More...
 
void rearrange (const std::vector< Selection > &sel_vec)
 Rearranges the atoms in the order of provided selections. More...
 
void rearrange (const std::vector< std::string > &begin_strings, const std::vector< std::string > &end_strings)
 Rearranges the atoms in the order of provided selection strings. More...
 
void rearrange (const std::vector< Selection > &begin_vec, const std::vector< Selection > &end_vec)
 Rearranges the atoms in the order of provided selections. More...
 
std::vector< std::pair< std::string, int > > rearrange_by_resname ()
 Rearranges the atoms in the alphabetical order of residue names. More...
 
void keep (const std::string &sel_str)
 Keep only atoms given by selection string.
 
void keep (const Selection &sel)
 Keep only atoms from given selection.
 
void remove (const std::string &sel_str)
 Remove atoms given by selection string.
 
void remove (Selection &sel)
 Remove atoms of given selection. More...
 
void distribute (const Selection sel, Vector3i_const_ref ncopies, Matrix3f_const_ref shift)
 Creates multiple copies of selection in the system and distributes them in a grid given by 3 translation vectors. More...
 
General properties
int num_frames () const
 Returns the number of frames in selection.
 
int num_atoms () const
 Returns the number of atoms in selection.
 
Selecting atoms.

These functions are just convenience adaptors for constructors of Selection class:

// Conventional way:
sys = System("structure.pdb");
Selection sel(s,"name CA");
// Shorter way:
auto sel = sys.select("name CA");
// Even shorter way using operator ():
auto sel = sys("name CA");

It also allows writing "one-liners" like this:

System("file.pdb").select("name CA").write("ca.pdb");
Selection select (std::string str, int fr=0)
 
Selection operator() (std::string str, int fr=0)
 
Selection select (int ind1, int ind2)
 
Selection operator() (int ind1, int ind2)
 
Selection select (const std::vector< int > &ind)
 
Selection operator() (const std::vector< int > &ind)
 
Selection select (std::vector< int >::iterator it1, std::vector< int >::iterator it2)
 
Selection operator() (std::vector< int >::iterator it1, std::vector< int >::iterator it2)
 
Selection select (const std::function< void(const System &, int, std::vector< int > &)> &callback, int fr=0)
 
Selection operator() (const std::function< void(const System &, int, std::vector< int > &)> &callback, int fr=0)
 
Selection select_all () const
 Convenience functions to select all.
 
Selection operator() ()
 
File IO
void load (std::string fname, int b=0, int e=-1, int skip=0, std::function< bool(System *, int)> on_frame=0)
 Read structure, trajectory or topology from file. More...
 
bool load (const std::unique_ptr< FileHandler > &handler, FileContent what, std::function< bool(System *, int)> on_frame=0)
 Load data into System from the pre-opened file handler. More...
 
void write (std::string fname, int b=-1, int e=-1) const
 
void write (const std::unique_ptr< FileHandler > &handler, FileContent what, int b=-1, int e=-1) const
 
std::vector< std::pair< std::string, Selection > > load_gromacs_ndx (std::string fname)
 Load Gromacs .ndx file and crease selections acording to it from existing system Returns a vector of pairs {name,Selection}.
 
Input filtering
void set_filter (std::string str)
 Filters narrow set of atoms and coordinates which are loaded from data files. More...
 
void set_filter (int ind1, int ind2)
 
void set_filter (const std::vector< int > &ind)
 
void set_filter (std::vector< int >::iterator it1, std::vector< int >::iterator it2)
 
Operations with frames
int frame_dup (int fr)
 Duplicates given frame and adds it to the end of frame vector.
 
void frame_append (const Frame &fr)
 Appends provided frame to trajectory.
 
void frame_copy (int fr1, int fr2)
 Copy all frame data from fr1 to fr2. Fr2 is overwritten!
 
void frame_delete (int b=0, int e=-1)
 Delete specified range of frames. More...
 
void frame_swap (int fr1, int fr2)
 Swaps two specified frames.
 
Inline accessors
PeriodicBoxbox (int fr=0)
 Read/write access for periodic box for given frame.
 
const PeriodicBoxbox (int fr=0) const
 Read only access for periodic box for given frame.
 
float & time (int fr=0)
 Read/Write access to the time stamp of given frame.
 
const float & time (int fr=0) const
 Read only access to the time stamp of given frame.
 
Eigen::Vector3f & xyz (int ind, int fr=0)
 Read/Write access for given coordinate of given frame.
 
const Eigen::Vector3f & xyz (int ind, int fr=0) const
 Read only access for given coordinate of given frame.
 
Eigen::Vector3f & vel (int ind, int fr=0)
 Read/Write access for given velocity of given frame.
 
const Eigen::Vector3f & vel (int ind, int fr=0) const
 Read only access for given velocity of given frame.
 
Eigen::Vector3f & force (int ind, int fr=0)
 Read/Write access for given force of given frame.
 
const Eigen::Vector3f & force (int ind, int fr=0) const
 Read only access for given force of given frame.
 
Atomatom (int ind)
 Read/Write access for given atom.
 
const Atomatom (int ind) const
 Read only access for given atom.
 
Frameframe (int fr)
 Get read/write reference for given frame.
 
const Frameframe (int fr) const
 Get read only reference for given frame.
 
Manipulating sets of atoms by indexes.

These methods do not update resindexes automatically.

Selection atoms_dup (const std::vector< int > &ind)
 Adds new atoms, which are duplicates of existing ones by index. Atoms are placed at the end of the system.
 
Selection atoms_add (const std::vector< Atom > &atm, const std::vector< Eigen::Vector3f > &crd)
 Adds new atoms from supplied vectors of atoms and coordinates. Atoms are placed at the end of the system.
 
void atoms_delete (const std::vector< int > &ind)
 Delete the set of atoms by indexes.
 
void atom_move (int i, int j)
 Move atom i to other position. Atom is inserted instead of atom j, shift is performed towards previous position of i.
 
Selection atom_clone (int source)
 Duplicate single target atom and puts it immediately after the source. More...
 
void atom_swap (int i, int j)
 Swap two atoms.
 
Selection atom_add_1h (int target, int at1, int at2, int at3, float dist=0.109, bool pbc=true)
 Add single hydrogen to target atom according to positions of 3 adjacent atoms assuming tetrahedral symmetry.
 
Selection atom_add_2h (int target, int at1, int at2, float dist=0.109, bool pbc=true)
 Add two hydrogens to target atom according to positions of 2 adjacent atoms assuming tetrahedral symmetry.
 
Selection atom_add_3h (int target, int at1, float dist=0.109, bool pbc=true)
 Add 3 hydrogens to target atom according to positions of single adjacent atom assuming tetrahedral symmetry.
 
Periodicity-related functions
void wrap (int fr, Array3i_const_ref pbc=fullPBC)
 Wrap all system to the periodic box for given frame.
 
Measuring functions
float distance (int i, int j, int fr, Array3i_const_ref pbc=fullPBC) const
 Get distance between two atoms for given frame (periodic in given dimensions if needed).
 
float angle (int i, int j, int k, int fr, Array3i_const_ref pbc=fullPBC) const
 Get angle in degrees between three atoms for given frame (periodic in given dimensions if needed).
 
float dihedral (int i, int j, int k, int l, int fr, Array3i_const_ref pbc=fullPBC) const
 Get dihedral angle in degrees between three atoms for given frame (periodic in given dimensions if needed).
 
Utility functions
void clear ()
 Clears the system and prepares for loading completely new structure.
 
bool force_field_ready ()
 
ForceFieldget_force_field ()
 Returns internal Force_field object.
 
void assign_resindex (int start=0)
 Assign unique resindexes This is usually done automatically upon loading a structure from file.
 
void sort_by_resindex ()
 Sorts atoms by resindex arranging atoms with the same resindexes into contigous pieces. More...
 
void clear_vel ()
 Delete velocities from all frames. More...
 
void clear_force ()
 Delete forces from all frames. More...
 
Eigen::Vector2f get_energy_for_list (const std::vector< Eigen::Vector2i > &pairs, const std::vector< float > &dist, std::vector< Eigen::Vector2f > *pair_en=nullptr)
 Low level energy evaluation function Returns total energy Individual pair energies could be returned to pair_en if provided.
 

Detailed Description

The system of atoms.

The System is a container for atoms and their coordinates, which are typically loaded from file. All properties of atoms, except the coordinates, are stored in atoms vector. Coordinates are stored as a resizable vector of trajectory frames. The system knows about selections associated with it and sends them signals if selections should adapt to the changes of coordinates of atom properties. Copying and assignment of systems is allowed, but associated selections are not copied.

Member Function Documentation

◆ append() [1/2]

Selection System::append ( const Selection sel,
bool  current_frame = false 
)

Append atoms from selection to this system.

Selection may belong to any system, not necessary current. Returns selection corresponding to appended atoms.

Parameters
current_frameif true only the coordinates of current frame in sel are added to all frames of the system.

◆ append() [2/2]

Selection System::append ( const AtomHandler at)

Append Atom_proxy object to this system Returns selection corresponding to appended atom.

Usage:

Selection sel(s,"name CA");
System new_s;
for(auto& at: sel){
new_s.append(at);
}

◆ rearrange() [1/4]

void System::rearrange ( const std::vector< std::string > &  sel_strings)

Rearranges the atoms in the order of provided selection strings.

Atom, which are not selected are appended at the end in their previous order.

Note
Selections should not overlap (exception is thrown if they are).

◆ rearrange() [2/4]

void System::rearrange ( const std::vector< Selection > &  sel_vec)

Rearranges the atoms in the order of provided selections.

Atoms, which are not selected are appended as is at the end.

Note
Selections should not overlap (exception is thrown if they are).

◆ rearrange() [3/4]

void System::rearrange ( const std::vector< std::string > &  begin_strings,
const std::vector< std::string > &  end_strings 
)

Rearranges the atoms in the order of provided selection strings.

Parameters
begin_stringsselection strings to begin with.
end_stringsselection strings to end with. Atoms, which are not selected are placed as is between begin and end.
Note
Selections should not overlap (exception is thrown if they are).

◆ rearrange() [4/4]

void System::rearrange ( const std::vector< Selection > &  begin_vec,
const std::vector< Selection > &  end_vec 
)

Rearranges the atoms in the order of provided selections.

Parameters
begin_vecselections to begin with.
end_vecselections to end with. Atoms, which are not selected are placed as is between begin and end.
Note
Selections should not overlap (exception is thrown if they are).

◆ rearrange_by_resname()

std::vector< std::pair< string, int > > System::rearrange_by_resname ( )

Rearranges the atoms in the alphabetical order of residue names.

Useful for liquid systems and membranes where each residue is a whole molecule.

Warning
If the molecules contain more than one resiude they will be broken!
Returns
vector of (residue name,number) pairs.

◆ remove()

void System::remove ( Selection sel)

Remove atoms of given selection.

Warning
Selection becomes invalid after that and is cleared!

◆ distribute()

void System::distribute ( const Selection  sel,
Vector3i_const_ref  ncopies,
Matrix3f_const_ref  shift 
)

Creates multiple copies of selection in the system and distributes them in a grid given by 3 translation vectors.

Vectors are stored column-wise as shift.col(i)

◆ load() [1/2]

void System::load ( std::string  fname,
int  b = 0,
int  e = -1,
int  skip = 0,
std::function< bool(System *, int)>  on_frame = 0 
)

Read structure, trajectory or topology from file.

Parameters
bFirst frame to read
eLast frame to read (-1 means up to the end of trajectory)
skipRead only each skip frames
on_frameCallback function, which takes pointer to the System as a first argument and the index of current stored frame as the second. If callback returns false loading stops.

◆ load() [2/2]

bool System::load ( const std::unique_ptr< FileHandler > &  handler,
FileContent  what,
std::function< bool(System *, int)>  on_frame = 0 
)

Load data into System from the pre-opened file handler.

This is rather low-level method which provides fine control over what should be read. It can be called several times to read trajectory frames one by one from the same pre-opened file.

◆ set_filter()

void System::set_filter ( std::string  str)

Filters narrow set of atoms and coordinates which are loaded from data files.

Only atoms specified by filter are kept in the system. They follow the same rules as ordinary selections but can't be coordinate-dependent and can't be set by callbacs.

Note
Filters do not make loading faster. In fact it becomes slower (up to 2 times for very large frames) and consumes twise as much memory during loading. However when loading finishes the system will contain only selected atoms. If many frames are stored in the system overall memory consumption will be much smaller.

Filter could only be set to empty system (it throws an error otherwise), thus the way of using them is the following:

// Create empty system
System sys;
// Set filter
sys.set_filter("name CA");
// All calls to load will use filter now
sys.load("some_protein.pdb");
sys.load("trajectory.xtc");
Warning
Filters could not be used when loading topologies! load() throws an error if attempting to load topology with filter.

◆ frame_delete()

void System::frame_delete ( int  b = 0,
int  e = -1 
)

Delete specified range of frames.

If only

Parameters
bis supplied deletes all frames from b to the end. If only
eis supplied deletes all frames from 0 to e

◆ atom_clone()

Selection System::atom_clone ( int  source)

Duplicate single target atom and puts it immediately after the source.

If using many times this procedure is slower than doing atoms_dup() and than assign_resindex().

◆ sort_by_resindex()

void System::sort_by_resindex ( )

Sorts atoms by resindex arranging atoms with the same resindexes into contigous pieces.

Could be called after atom additions or duplications.

◆ clear_vel()

void System::clear_vel ( )

Delete velocities from all frames.

Does nothing if no velocities.

◆ clear_force()

void System::clear_force ( )

Delete forces from all frames.

Does nothing if no forces.


The documentation for this class was generated from the following files:
pteros::System::System
System()
Default constructor.
Definition: system.cpp:51