Commit f52d009d authored by Jens Wehner's avatar Jens Wehner

introduced votca::index

parent e3684a32
Pipeline #91932553 failed with stages
in 7 minutes and 12 seconds
......@@ -25,6 +25,7 @@
#include <votca/tools/eigen.h>
#include <votca/tools/identity.h>
#include <votca/tools/name.h>
#include <votca/tools/types.h>
namespace TOOLS = votca::tools;
namespace votca {
......@@ -46,10 +47,10 @@ class BaseBead {
virtual ~BaseBead() = default;
/// Gets the id of the bead
long getId() const { return id_.getId(); }
Index getId() const { return id_.getId(); }
/// Sets the id of the bead
void setId(long id) { id_.setId(id); }
void setId(Index id) { id_.setId(id); }
/// Gets the name of the bead
std::string getName() const { return name_.getName(); }
......@@ -127,7 +128,7 @@ class BaseBead {
TopologyItem topology_item_;
MoleculeItem molecule_item_;
TOOLS::Identity<long> id_;
TOOLS::Identity<Index> id_;
TOOLS::Name name_;
TOOLS::Name type_;
......
......@@ -54,7 +54,7 @@ class Bead : public BaseBead {
* get the residu number of the bead
* \return residue id
*/
const long &getResnr() const { return residue_number_; }
const Index &getResnr() const { return residue_number_; }
/**
* get the charge of the bead
......@@ -78,7 +78,7 @@ class Bead : public BaseBead {
*
* \return bead symmetry
*/
tools::byte_t getSymmetry() const { return symmetry_; }
Index getSymmetry() const { return symmetry_; }
/**
* set the velocity of the bead
......@@ -257,7 +257,7 @@ class Bead : public BaseBead {
* If it is a mapped beads, returns te bead id the cg bead was created from
* \return vector of bead ids of reference atoms
*/
const std::vector<long> &ParentBeads() { return parent_beads_; };
const std::vector<Index> &ParentBeads() { return parent_beads_; };
/**
* \brief Clears out all parent beads
......@@ -267,17 +267,17 @@ class Bead : public BaseBead {
/**
* \brief Adds the id of a parent bead
**/
void AddParentBead(long parent_bead_id) {
void AddParentBead(Index parent_bead_id) {
parent_beads_.push_back(parent_bead_id);
}
protected:
std::vector<long> parent_beads_;
std::vector<Index> parent_beads_;
tools::byte_t symmetry_;
Index symmetry_;
double charge_;
long residue_number_;
Index residue_number_;
Eigen::Vector3d velocity_, bead_force_, u_, v_, w_;
......@@ -288,8 +288,8 @@ class Bead : public BaseBead {
bool bead_force_set_;
/// constructor
Bead(Topology *owner, long id, std::string type, tools::byte_t symmetry,
std::string name, long resnr, double m, double q)
Bead(Topology *owner, Index id, std::string type, Index symmetry,
std::string name, Index resnr, double m, double q)
: symmetry_(symmetry), charge_(q), residue_number_(resnr) {
topology_item_._parent = owner;
setId(id);
......
......@@ -21,6 +21,7 @@
#include <list>
#include <string>
#include <votca/tools/eigen.h>
#include <votca/tools/types.h>
namespace votca {
namespace csg {
......@@ -38,13 +39,13 @@ class Bead;
class BeadList {
public:
/// \brief Select all beads of type <select>
long Generate(Topology &top, const std::string &select);
Index Generate(Topology &top, const std::string &select);
/// \brief Select all beads of type <select> withn a radius <radius> of
/// reference vector <ref>
long GenerateInSphericalSubvolume(Topology &top, const std::string &select,
Eigen::Vector3d ref, double radius);
Index GenerateInSphericalSubvolume(Topology &top, const std::string &select,
Eigen::Vector3d ref, double radius);
long size() const { return _beads.size(); }
Index size() const { return _beads.size(); }
bool empty() const { return _beads.empty(); }
......
......@@ -154,14 +154,14 @@ class BeadMotif : public BeadStructure<BaseBead> {
*
* \param[in] - id of the first and second beads that are connected
**/
void ConnectBeads(long bead1_id, long bead2_id);
void ConnectBeads(Index bead1_id, Index bead2_id);
private:
MotifType type_ = MotifType::undefined;
bool junctionsUpToDate_ = false;
bool type_up_to_date_ = false;
std::vector<long> junctions_;
std::vector<Index> junctions_;
TOOLS::ReducedGraph reduced_graph_;
void InitializeGraph_();
......
......@@ -77,7 +77,7 @@ T breakIntoMotifs(BeadStructure<BaseBead> &beadstructure) {
* separate structures 1 of type 'loop' and the other of type line.
**/
std::pair<std::unordered_map<int, BeadMotif>, BeadMotifConnector>
std::pair<std::unordered_map<Index, BeadMotif>, BeadMotifConnector>
breakIntoSimpleMotifs(BeadMotif beadmotif);
} // namespace csg
......
......@@ -81,7 +81,7 @@ class BeadStructure {
/**
* \brief Get the bead with the specified id
**/
T *getBead(long id);
T *getBead(Index id);
/**
* \brief Create a connection between two beads in the structure
......@@ -89,12 +89,12 @@ class BeadStructure {
* A bead cannot be connected to itself. It also may not be connected to a
* bead that has not yet been added to the structure.
**/
void ConnectBeads(long bead1_id, long bead2_id);
void ConnectBeads(Index bead1_id, Index bead2_id);
/**
* \brief Return a vector of all the beads neighboring the index
**/
std::vector<T *> getNeighBeads(int index);
std::vector<T *> getNeighBeads(Index index);
TOOLS::Graph getGraph();
/**
......@@ -109,7 +109,7 @@ class BeadStructure {
**/
bool isStructureEquivalent(BeadStructure<T> &beadstructure);
bool BeadExist(long bead_id) const { return beads_.count(bead_id); }
bool BeadExist(Index bead_id) const { return beads_.count(bead_id); }
protected:
void InitializeGraph_();
......@@ -123,8 +123,8 @@ class BeadStructure {
std::string structure_id_ = "";
TOOLS::Graph graph_;
std::set<TOOLS::Edge> connections_;
std::unordered_map<long int, T *> beads_;
std::unordered_map<long int, TOOLS::GraphNode> graphnodes_;
std::unordered_map<Index, T *> beads_;
std::unordered_map<Index, TOOLS::GraphNode> graphnodes_;
};
/**********************
......@@ -139,7 +139,7 @@ void BeadStructure<T>::InitializeGraph_() {
connections_vector.push_back(edge);
}
for (std::pair<const long int, T *> &id_bead_ptr_pair : beads_) {
for (std::pair<const Index, T *> &id_bead_ptr_pair : beads_) {
graphnodes_[id_bead_ptr_pair.first] =
BaseBeadToGraphNode_(id_bead_ptr_pair.second);
}
......@@ -198,7 +198,7 @@ void BeadStructure<T>::AddBead(T *bead) {
}
template <class T>
void BeadStructure<T>::ConnectBeads(long bead1_id, long bead2_id) {
void BeadStructure<T>::ConnectBeads(Index bead1_id, Index bead2_id) {
if (!(beads_.count(bead1_id)) || !(beads_.count(bead2_id))) {
std::string err =
"Cannot connect beads in bead structure that do not exist";
......@@ -228,7 +228,7 @@ bool BeadStructure<T>::isSingleStructure() {
InitializeGraph_();
if (single_structureUpToDate_ == false) {
std::vector<long> vertices = graph_.getVertices();
std::vector<Index> vertices = graph_.getVertices();
if (vertices.size() == 0) {
single_structure_ = false;
return single_structure_;
......@@ -266,20 +266,20 @@ bool BeadStructure<T>::isStructureEquivalent(BeadStructure<T> &beadstructure) {
}
template <class T>
std::vector<T *> BeadStructure<T>::getNeighBeads(int index) {
std::vector<T *> BeadStructure<T>::getNeighBeads(Index index) {
if (!graphUpToDate) {
InitializeGraph_();
}
std::vector<long> neighbor_ids = graph_.getNeighVertices(index);
std::vector<Index> neighbor_ids = graph_.getNeighVertices(index);
std::vector<T *> neighbeads;
for (long &node_id : neighbor_ids) {
for (Index &node_id : neighbor_ids) {
neighbeads.push_back(beads_[node_id]);
}
return neighbeads;
}
template <class T>
T *BeadStructure<T>::getBead(long index) {
T *BeadStructure<T>::getBead(Index index) {
assert(beads_.count(index));
return beads_[index];
}
......
......@@ -32,15 +32,15 @@ namespace csg {
*/
class BeadType : public TopologyItem {
public:
const int &getId() const { return _id; }
const Index &getId() const { return _id; }
const std::string &getName() const { return _name; }
void setName(const std::string &name) { _name = name; }
private:
int _id;
Index _id;
std::string _name;
BeadType(Topology *parent, int id, const std::string &name)
BeadType(Topology *parent, Index id, const std::string &name)
: TopologyItem(parent), _id(id), _name(name) {}
friend class Topology;
};
......
......@@ -60,7 +60,7 @@ class CGMoleculeDef {
struct beaddef_t {
std::string _name;
std::string _type;
tools::byte_t _symmetry;
Index _symmetry;
std::string _mapping;
std::vector<std::string> _subbeads;
tools::Property *_options;
......
......@@ -108,19 +108,19 @@ class CsgApplication : public tools::Application {
Topology *top_ref = nullptr) = 0;
/// \brief returns worker id
int getId() { return _id; }
Index getId() { return _id; }
protected:
CsgApplication *_app = nullptr;
Topology _top, _top_cg;
TopologyMap *_map = nullptr;
int _id = -1;
Index _id = -1;
void Run(void) override;
void setApplication(CsgApplication *app) { _app = app; }
void setId(int id) { _id = id; }
void setId(Index id) { _id = id; }
friend class CsgApplication;
};
......@@ -151,9 +151,9 @@ class CsgApplication : public tools::Application {
std::list<CGObserver *> _observers;
bool _do_mapping;
std::vector<Worker *> _myWorkers;
int _nframes;
Index _nframes;
bool _is_first_frame;
int _nthreads;
Index _nthreads;
tools::Mutex _nframesMutex;
tools::Mutex _traj_readerMutex;
......
......@@ -28,9 +28,9 @@ namespace votca {
namespace csg {
void imcio_write_dS(const std::string &file, const tools::Table &dS,
const std::list<int> *list = nullptr);
const std::list<Index> *list = nullptr);
void imcio_write_matrix(const std::string &file, const Eigen::MatrixXd &gmc,
const std::list<int> *list = nullptr);
const std::list<Index> *list = nullptr);
void imcio_write_index(
const std::string &file,
const std::vector<std::pair<std::string, tools::RangeParser> > &ranges);
......
......@@ -54,44 +54,44 @@ class Interaction {
// the group id is set by topology, when interaction is added to it
// \todo if the group name is changed later, group id should be updated by
// topology
long getGroupId() {
Index getGroupId() {
assert(_group_id != -1);
return _group_id;
}
void setGroupId(long id) { _group_id = id; }
void setGroupId(Index id) { _group_id = id; }
void setIndex(const long &index) {
void setIndex(const Index &index) {
_index = index;
RebuildName();
}
const long &getIndex() const {
const Index &getIndex() const {
assert(_index != -1);
return _index;
}
void setMolecule(const long &mol) {
void setMolecule(const Index &mol) {
_mol = mol;
RebuildName();
}
const long &getMolecule() const {
const Index &getMolecule() const {
assert(_mol != -1);
return _mol;
}
virtual Eigen::Vector3d Grad(const Topology &top, long bead) = 0;
long BeadCount() { return _beads.size(); }
long getBeadId(long bead) {
virtual Eigen::Vector3d Grad(const Topology &top, Index bead) = 0;
Index BeadCount() { return _beads.size(); }
Index getBeadId(Index bead) {
assert(bead > -1 && boost::lexical_cast<size_t>(bead) < _beads.size());
return _beads[bead];
}
protected:
long _index = -1;
Index _index = -1;
std::string _group = "";
long _group_id = -1;
Index _group_id = -1;
std::string _name = "";
long _mol = -1;
std::vector<long> _beads;
Index _mol = -1;
std::vector<Index> _beads;
void RebuildName();
};
......@@ -122,22 +122,22 @@ inline void Interaction::RebuildName() {
*/
class IBond : public Interaction {
public:
IBond(long bead1, long bead2) {
IBond(Index bead1, Index bead2) {
_beads.resize(2);
_beads[0] = bead1;
_beads[1] = bead2;
}
IBond(std::list<long> &beads) {
IBond(std::list<Index> &beads) {
assert(beads.size() >= 2);
_beads.resize(2);
for (long i = 0; i < 2; ++i) {
for (Index i = 0; i < 2; ++i) {
_beads[i] = beads.front();
beads.pop_front();
}
}
double EvaluateVar(const Topology &top) override;
Eigen::Vector3d Grad(const Topology &top, long bead) override;
Eigen::Vector3d Grad(const Topology &top, Index bead) override;
private:
};
......@@ -147,23 +147,23 @@ class IBond : public Interaction {
*/
class IAngle : public Interaction {
public:
IAngle(long bead1, long bead2, long bead3) {
IAngle(Index bead1, Index bead2, Index bead3) {
_beads.resize(3);
_beads[0] = bead1;
_beads[1] = bead2;
_beads[2] = bead3;
}
IAngle(std::list<long> &beads) {
IAngle(std::list<Index> &beads) {
assert(beads.size() >= 3);
_beads.resize(3);
for (long i = 0; i < 3; ++i) {
for (Index i = 0; i < 3; ++i) {
_beads[i] = beads.front();
beads.pop_front();
}
}
double EvaluateVar(const Topology &top) override;
Eigen::Vector3d Grad(const Topology &top, long bead) override;
Eigen::Vector3d Grad(const Topology &top, Index bead) override;
private:
};
......@@ -173,24 +173,24 @@ class IAngle : public Interaction {
*/
class IDihedral : public Interaction {
public:
IDihedral(long bead1, long bead2, long bead3, long bead4) {
IDihedral(Index bead1, Index bead2, Index bead3, Index bead4) {
_beads.resize(4);
_beads[0] = bead1;
_beads[1] = bead2;
_beads[2] = bead3;
_beads[3] = bead4;
}
IDihedral(std::list<long> &beads) {
IDihedral(std::list<Index> &beads) {
assert(beads.size() >= 4);
_beads.resize(4);
for (long i = 0; i < 4; ++i) {
for (Index i = 0; i < 4; ++i) {
_beads[i] = beads.front();
beads.pop_front();
}
}
double EvaluateVar(const Topology &top) override;
Eigen::Vector3d Grad(const Topology &top, long bead) override;
Eigen::Vector3d Grad(const Topology &top, Index bead) override;
private:
};
......@@ -199,7 +199,7 @@ inline double IBond::EvaluateVar(const Topology &top) {
return top.getDist(_beads[0], _beads[1]).norm();
}
inline Eigen::Vector3d IBond::Grad(const Topology &top, long bead) {
inline Eigen::Vector3d IBond::Grad(const Topology &top, Index bead) {
Eigen::Vector3d r = top.getDist(_beads[0], _beads[1]);
r.normalize();
return (bead == 0) ? -r : r;
......@@ -211,7 +211,7 @@ inline double IAngle::EvaluateVar(const Topology &top) {
return std::acos(v1.dot(v2) / sqrt(v1.squaredNorm() * v2.squaredNorm()));
}
inline Eigen::Vector3d IAngle::Grad(const Topology &top, long bead) {
inline Eigen::Vector3d IAngle::Grad(const Topology &top, Index bead) {
Eigen::Vector3d v1(top.getDist(_beads[1], _beads[0]));
Eigen::Vector3d v2(top.getDist(_beads[1], _beads[2]));
......@@ -251,7 +251,7 @@ inline double IDihedral::EvaluateVar(const Topology &top) {
std::acos(n1.dot(n2) / sqrt(n1.squaredNorm() * n2.squaredNorm()));
}
inline Eigen::Vector3d IDihedral::Grad(const Topology &top, long bead) {
inline Eigen::Vector3d IDihedral::Grad(const Topology &top, Index bead) {
Eigen::Vector3d v1(top.getDist(_beads[0], _beads[1]));
Eigen::Vector3d v2(top.getDist(_beads[1], _beads[2]));
Eigen::Vector3d v3(top.getDist(_beads[2], _beads[3]));
......@@ -268,7 +268,7 @@ inline Eigen::Vector3d IDihedral::Grad(const Topology &top, long bead) {
(n1.squaredNorm() * n2.squaredNorm()))));
switch (bead) {
case (0): {
for (long i = 0; i < 3; i++) {
for (Index i = 0; i < 3; i++) {
returnvec[i] = n2.dot(v2.cross(e.col(i))) / (n1.norm() * n2.norm()) -
n1.dot(n2) * n1.dot(v2.cross(e.col(i))) /
(n2.norm() * std::pow(n1.norm(), 3));
......@@ -277,7 +277,7 @@ inline Eigen::Vector3d IDihedral::Grad(const Topology &top, long bead) {
break;
}
case (1): {
for (long i = 0; i < 3; i++) {
for (Index i = 0; i < 3; i++) {
returnvec[i] =
(n1.dot(v3.cross(e.col(i))) +
n2.dot(e.col(i).cross(v1) + e.col(i).cross(v2))) /
......@@ -291,7 +291,7 @@ inline Eigen::Vector3d IDihedral::Grad(const Topology &top, long bead) {
break;
};
case (2): {
for (long i = 0; i < 3; i++) {
for (Index i = 0; i < 3; i++) {
returnvec[i] =
(n1.dot(e.col(i).cross(v2) + e.col(i).cross(v3)) +
n2.dot(v1.cross(e.col(i)))) /
......@@ -305,7 +305,7 @@ inline Eigen::Vector3d IDihedral::Grad(const Topology &top, long bead) {
break;
};
case (3): { //
for (long i = 0; i < 3; i++) {
for (Index i = 0; i < 3; i++) {
returnvec[i] = n1.dot(v2.cross(e.col(i))) / (n1.norm() * n2.norm()) -
n1.dot(n2) * n2.dot(v2.cross(e.col(i))) /
(n1.norm() * std::pow(n2.norm(), 3));
......
......@@ -42,7 +42,7 @@ class Interaction;
class Molecule : public TopologyItem {
public:
/// get the molecule ID
long getId() const { return _id; }
Index getId() const { return _id; }
/// get the name of the molecule
const std::string &getName() const { return _name; }
......@@ -53,18 +53,18 @@ class Molecule : public TopologyItem {
/// Add a bead to the molecule
void AddBead(Bead *bead, const std::string &name);
/// get the id of a bead in the molecule
Bead *getBead(long bead) { return _beads[bead]; }
long getBeadId(int bead) { return _beads[bead]->getId(); }
long getBeadIdByName(const std::string &name);
Bead *getBead(Index bead) { return _beads[bead]; }
Index getBeadId(Index bead) { return _beads[bead]->getId(); }
Index getBeadIdByName(const std::string &name);
/// get the number of beads in the molecule
long BeadCount() const { return _beads.size(); }
Index BeadCount() const { return _beads.size(); }
const std::vector<Bead *> &Beads() const { return _beads; }
std::vector<Bead *> &Beads() { return _beads; }
/// find a bead by it's name
long getBeadByName(const std::string &name);
std::string getBeadName(int bead) { return _bead_names[bead]; }
Index getBeadByName(const std::string &name);
std::string getBeadName(Index bead) { return _bead_names[bead]; }
/// Add an interaction to the molecule
void AddInteraction(Interaction *ic) { _interactions.push_back(ic); }
......@@ -83,11 +83,11 @@ class Molecule : public TopologyItem {
private:
// maps a name to a bead id
std::map<std::string, long> _beadmap;
std::map<std::string, Index> _beadmap;
std::vector<Interaction *> _interactions;
// id of the molecules
long _id;
Index _id;
// name of the molecule
std::string _name;
......@@ -98,14 +98,14 @@ class Molecule : public TopologyItem {
void *_userdata;
/// constructor
Molecule(Topology *parent, long id, std::string name)
Molecule(Topology *parent, Index id, std::string name)
: TopologyItem(parent), _id(id), _name(name) {}
friend class Topology;
};
inline long Molecule::getBeadIdByName(const std::string &name) {
long i = getBeadByName(name);
inline Index Molecule::getBeadIdByName(const std::string &name) {
Index i = getBeadByName(name);
if (i < 0) {
{
return i;
......
......@@ -39,7 +39,7 @@ class NBListGrid : public NBList {
Eigen::Vector3d _box_a, _box_b, _box_c;
Eigen::Vector3d _norm_a, _norm_b, _norm_c;
int _box_Na, _box_Nb, _box_Nc;
Index _box_Na, _box_Nb, _box_Nc;
std::vector<cell_t> _grid;
Topology *_top;
......@@ -47,14 +47,14 @@ class NBListGrid : public NBList {
void InitializeGrid(const Eigen::Matrix3d &box);
cell_t &getCell(const Eigen::Vector3d &r);
cell_t &getCell(const int &a, const int &b, const int &c);
cell_t &getCell(const Index &a, const Index &b, const Index &c);
void TestBead(cell_t &cell, Bead *bead);
void TestCell(cell_t &cell, Bead *bead);
};
inline NBListGrid::cell_t &NBListGrid::getCell(const int &a, const int &b,
const int &c) {
inline NBListGrid::cell_t &NBListGrid::getCell(const Index &a, const Index &b,
const Index &c) {
return _grid[a + _box_Na * b + _box_Na * _box_Nb * c];
}
......
......@@ -42,7 +42,7 @@ class NBListGrid_3Body : public NBList_3Body {
Eigen::Vector3d _box_a, _box_b, _box_c;
Eigen::Vector3d _norm_a, _norm_b, _norm_c;
int _box_Na, _box_Nb, _box_Nc;
Index _box_Na, _box_Nb, _box_Nc;
std::vector<cell_t> _grid;
Topology *_top;
......@@ -50,14 +50,14 @@ class NBListGrid_3Body : public NBList_3Body {
void InitializeGrid(const Eigen::Matrix3d &box);
cell_t &getCell(const Eigen::Vector3d &r);
cell_t &getCell(const int &a, const int &b, const int &c);
cell_t &getCell(const Index &a, const Index &b, const Index &c);
void TestBead(cell_t &cell, Bead *bead);
};
inline NBListGrid_3Body::cell_t &NBListGrid_3Body::getCell(const int &a,
const int &b,
const int &c) {
inline NBListGrid_3Body::cell_t &NBListGrid_3Body::getCell(const Index &a,
const Index &b,
const Index &c) {
return _grid[a + _box_Na * b + _box_Na * _box_Nb * c];
}
......
......@@ -20,6 +20,7 @@
#include <map>
#include <vector>
#include <votca/tools/types.h>
namespace votca {
namespace csg {
......@@ -46,7 +47,7 @@ class PairList {
pair_type *back() { return _pairs.back(); }
bool empty() const { return _pairs.empty(); }
long size() const { return long(_pairs.size()); }
Index size() const { return Index(_pairs.size()); }
void Cleanup();
......@@ -78,8 +79,8 @@ inline void PairList<element_type, pair_type>::AddPair(pair_type *p) {
template <typename element_type, typename pair_type>
inline void PairList<element_type, pair_type>::Cleanup() {
for (iterator iter = _pairs.begin(); iter != _pairs.end(); ++iter) {
delete *iter;
for (auto &pair : _pairs) {
delete pair;
}
_pairs.clear();
_pair_map.clear();
......
......@@ -55,16 +55,16 @@ class PDBWriter : public TrajectoryWriter {
std::string getResname(Topology &conf, Bead *bead);
template <class Atom>