Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Piece wize basebead #460

Merged
merged 27 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f8a37a9
Updated include gaurd
JoshuaSBrown Nov 23, 2019
c0faaa3
Added pragma once to basebead
JoshuaSBrown Nov 23, 2019
209cd8f
Added constants include
JoshuaSBrown Nov 23, 2019
170c5e8
Flatten id of basebead
JoshuaSBrown Nov 23, 2019
37a3f96
Added noexcept keyword and getElement method
JoshuaSBrown Nov 23, 2019
25010ed
Switched print from long int to int
JoshuaSBrown Nov 23, 2019
59ab977
Remove molecule item, replace with id
JoshuaSBrown Nov 23, 2019
07bc87e
Replaced getMolecule with getMoleculeId
JoshuaSBrown Nov 23, 2019
828349e
Replaced getMolecule with getMoleculeId in map.cc
JoshuaSBrown Nov 23, 2019
8f8cda1
Replaced setMolecule with setMoleculeId in molecule.cc
JoshuaSBrown Nov 23, 2019
937fd43
Replaces setMolecule and getMolecule with setMoleculeId and getMolecu…
JoshuaSBrown Nov 23, 2019
61e5dc2
Updated basebead test to use molecule id
JoshuaSBrown Nov 23, 2019
4e9bd4b
Removed redundant method call
JoshuaSBrown Nov 23, 2019
14e9101
Updated test_bead to use molecule id
JoshuaSBrown Nov 23, 2019
a0fa449
Updated nblist_3body by removing redundant method call
JoshuaSBrown Nov 23, 2019
8d50c62
Added comments removed include
JoshuaSBrown Nov 23, 2019
43841bf
Fixed use of int to explicit Index type
JoshuaSBrown Nov 23, 2019
090f7b3
Return index instead of int for id
JoshuaSBrown Nov 23, 2019
5f57d1c
Merge branch 'master' into piece-wize-basebead
JoshuaSBrown Nov 23, 2019
3f0dd3c
Revert print statement to using long
JoshuaSBrown Nov 23, 2019
e051f11
Merge branch 'piece-wize-basebead' of https://www.github.com/votca/cs…
JoshuaSBrown Nov 23, 2019
5b2390f
Merge branch 'master' into piece-wize-basebead
JoshuaSBrown Dec 6, 2019
5cc0e70
Merge branch 'master' into piece-wize-basebead
JoshuaSBrown Dec 7, 2019
83572fd
Moved initialization to elist
JoshuaSBrown Dec 7, 2019
d1e726a
Merge branch 'master' into piece-wize-basebead
JoshuaSBrown Dec 8, 2019
3d4c110
Merge branch 'master' into piece-wize-basebead
junghans Dec 8, 2019
e237f6e
Merge branch 'piece-wize-basebead' of https://github.com/votca/csg in…
JoshuaSBrown Dec 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 43 additions & 26 deletions include/votca/csg/basebead.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
* limitations under the License.
*
*/

#ifndef _VOTCA_CSG_BASEBEAD_H
#define _VOTCA_CSG_BASEBEAD_H
#pragma once
#ifndef VOTCA_CSG_BASEBEAD_H
#define VOTCA_CSG_BASEBEAD_H

#include <assert.h>
#include <memory>
#include <votca/csg/moleculeitem.h>
#include <votca/csg/topologyitem.h>
#include <votca/tools/constants.h>
#include <votca/tools/eigen.h>
#include <votca/tools/identity.h>
#include <votca/tools/name.h>
#include <votca/tools/types.h>
namespace TOOLS = votca::tools;
Expand All @@ -47,22 +46,33 @@ class BaseBead {
virtual ~BaseBead() = default;

/// Gets the id of the bead
Index getId() const { return id_.getId(); }
Index getId() const noexcept { return id_; }

/// Sets the id of the bead
void setId(Index id) { id_.setId(id); }
void setId(const Index &id) noexcept { id_ = id; }

/// Gets the name of the bead
std::string getName() const { return name_.getName(); }

/// Sets the name of the bead
void setName(std::string name) { return name_.setName(name); }

/// Sets the molecule the bead is attached too
void setMolecule(Molecule *molecule) { molecule_item_.setMolecule(molecule); }
/**
* @brief assign the bead to a molecule with the provided id
*
* @param molecule_id
*/
void setMoleculeId(const Index &molecule_id) noexcept {
molecule_id_ = molecule_id;
}

/// Gets the molecule pointer the bead is attached too
Molecule *getMolecule() const { return molecule_item_.getMolecule(); }
/**
* @brief Get the id of the molecule the bead is a part of, if the molecule
* id has not been set return topology_constants::unassigned_molecule_id
*
* @return
*/
Index getMoleculeId() const noexcept { return molecule_id_; }

/// Gets the topology pointer the bead is attached too
Topology *getParent() const { return topology_item_.getParent(); }
Expand All @@ -71,25 +81,33 @@ class BaseBead {
* get the bead type
* \return const string
*/
virtual const std::string getType() const { return type_.getName(); }
virtual const std::string getType() const noexcept { return type_; }

/**
* set the bead type
* \param bead type object
*/
virtual void setType(std::string type) { type_.setName(type); }
virtual void setType(const std::string &type) noexcept { type_ = type; }

/**
* @brief Returns the element type of the bead
*
* @return either the element symbol i.e. "Si" for silcon or unassigned if it
* has not been specified.
*/
std::string getElement() const noexcept { return element_symbol_; }

/**
* get the mass of the base bead
* \return - base bead mass
*/
virtual const double &getMass() const { return mass_; }
virtual const double &getMass() const noexcept { return mass_; }

/**
* set the mass of the base bead
* \param - base bead mass
*/
virtual void setMass(const double &m) { mass_ = m; }
virtual void setMass(const double &m) noexcept { mass_ = m; }

/**
* set the position of the base bead
Expand All @@ -113,24 +131,23 @@ class BaseBead {
}

/** does this configuration store positions? */
bool HasPos() const { return bead_position_set_; }
bool HasPos() const noexcept { return bead_position_set_; }

/** set has position to true */
void HasPos(bool true_or_false) { bead_position_set_ = true_or_false; }
void HasPos(const bool &true_or_false) noexcept {
bead_position_set_ = true_or_false;
}

protected:
BaseBead()
: topology_item_(nullptr),
molecule_item_(nullptr),
mass_(0.0),
bead_position_set_(false){};
BaseBead() : topology_item_(nullptr), mass_(0.0), bead_position_set_(false){};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can initialize them below in th elist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would set the values of these things not in the constructor but when they are declared in the private section of the class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change please


TopologyItem topology_item_;
MoleculeItem molecule_item_;

TOOLS::Identity<Index> id_;
std::string type_ = tools::topology_constants::unassigned_bead_type;
Index id_ = tools::topology_constants::unassigned_residue_id;
Index molecule_id_ = tools::topology_constants::unassigned_molecule_id;
std::string element_symbol_ = tools::topology_constants::unassigned_element;
TOOLS::Name name_;
TOOLS::Name type_;

double mass_;
Eigen::Vector3d bead_position_;
Expand All @@ -151,4 +168,4 @@ inline const Eigen::Vector3d &BaseBead::getPos() const {
} // namespace csg
} // namespace votca

#endif // _VOTCA_CSG_BASEBEAD_H
#endif // VOTCA_CSG_BASEBEAD_H
2 changes: 1 addition & 1 deletion src/libcsg/exclusionlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void ExclusionList::CreateExclusions(Topology *top) {

bool ExclusionList::IsExcluded(Bead *bead1, Bead *bead2) {
exclusion_t *excl;
if (bead1->getMolecule() != bead2->getMolecule()) {
if (bead1->getMoleculeId() != bead2->getMoleculeId()) {
JensWehner marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
if (bead2->getId() < bead1->getId()) {
Expand Down
3 changes: 1 addition & 2 deletions src/libcsg/map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ void Map_Sphere::Apply() {
", " + bead->getName() + " (id " +
boost::lexical_cast<string>(bead->getId() + 1) + ")" +
+" , molecule " +
boost::lexical_cast<string>(bead->getMolecule()->getId() + 1) +
")");
boost::lexical_cast<string>(bead->getMoleculeId() + 1) + ")");
}
cg += iter._weight * (r + r0);
bPos = true;
Expand Down
8 changes: 4 additions & 4 deletions src/libcsg/modules/io/lammpsdatareader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ void LAMMPSDataReader::ReadAtoms_(Topology &top) {
residue_index, mass, charge);

mol->AddBead(b, bead_type_name);
b->setMolecule(mol);
b->setMoleculeId(mol->getId());

} else {
b = top.getBead(atomIndex - startingIndex);
Expand Down Expand Up @@ -533,7 +533,7 @@ void LAMMPSDataReader::ReadBonds_(Topology &top) {
ic->setGroup("BONDS");
ic->setIndex(bondId);
auto b = top.getBead(atom1Index);
auto mi = b->getMolecule();
auto mi = top.getMolecule(b->getMoleculeId());
ic->setMolecule(atomIdToMoleculeId_[atom1Index]);
top.AddBondedInteraction(ic);
mi->AddInteraction(ic);
Expand Down Expand Up @@ -591,7 +591,7 @@ void LAMMPSDataReader::ReadAngles_(Topology &top) {
ic->setGroup("ANGLES");
ic->setIndex(angleId);
auto b = top.getBead(atom1Index);
auto mi = b->getMolecule();
auto mi = top.getMolecule(b->getMoleculeId());
ic->setMolecule(atomIdToMoleculeId_[atom1Index]);
top.AddBondedInteraction(ic);
mi->AddInteraction(ic);
Expand Down Expand Up @@ -662,7 +662,7 @@ void LAMMPSDataReader::ReadDihedrals_(Topology &top) {
ic->setGroup("DIHEDRALS");
ic->setIndex(dihedralId);
auto b = top.getBead(atom1Index);
auto mi = b->getMolecule();
auto mi = top.getMolecule(b->getMoleculeId());
ic->setMolecule(atomIdToMoleculeId_[atom1Index]);
top.AddBondedInteraction(ic);
mi->AddInteraction(ic);
Expand Down
2 changes: 1 addition & 1 deletion src/libcsg/molecule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void Molecule::AddBead(Bead *bead, const string &name) {
_bead_names.push_back(name);
_beadmap[name] = _beads.size() - 1;

bead->setMolecule(this);
bead->setMoleculeId(_id);
}

long Molecule::getBeadByName(const string &name) {
Expand Down
7 changes: 2 additions & 5 deletions src/tests/test_basebead.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ BOOST_AUTO_TEST_CASE(test_basebead_getters_setters) {
BOOST_CHECK_EQUAL(xyz3.isApprox(xyz_ref, 1e-5), true);

Topology top;
auto mol = top.CreateMolecule("Molecule1");
basebead.setMolecule(mol);
auto mol2 = basebead.getMolecule();
bool molecules_equal = mol2->getName() == "Molecule1";
BOOST_CHECK(molecules_equal);
basebead.setMoleculeId(0);
BOOST_CHECK_EQUAL(basebead.getMoleculeId(), 0);
}
BOOST_AUTO_TEST_SUITE_END()
6 changes: 2 additions & 4 deletions src/tests/test_bead.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE(test_bead_setters) {
string molecule_name = "TestMol";
Molecule *mol = top.CreateMolecule(molecule_name);

b->setMolecule(mol);
b->setMoleculeId(mol->getId());

BOOST_CHECK_CLOSE(b->getMass(), newMass, 1e-5);
BOOST_CHECK_CLOSE(b->getQ(), newCharge, 1e-5);
Expand All @@ -104,9 +104,7 @@ BOOST_AUTO_TEST_CASE(test_bead_setters) {
auto new_xyz_vel = b->getVel();
BOOST_CHECK(new_xyz_vel.isApprox(xyz_vel, 1e-7));

auto mol_new = b->getMolecule();
bool same = !(molecule_name.compare(mol_new->getName()));
BOOST_CHECK(same);
BOOST_CHECK_EQUAL(b->getMoleculeId(), mol->getId());
}

BOOST_AUTO_TEST_SUITE_END()
3 changes: 0 additions & 3 deletions src/tests/test_nblist_3body.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ BOOST_AUTO_TEST_CASE(test_nblist_3body_generate_list) {
charge);
b->setPos(pos);
mol->AddBead(b, bead_type_name);
b->setMolecule(mol);

name = "dummy2";
resnr = 0;
Expand All @@ -73,7 +72,6 @@ BOOST_AUTO_TEST_CASE(test_nblist_3body_generate_list) {
b = top.CreateBead(Bead::spherical, name, bead_type_name, resnr, mass,
charge);
mol->AddBead(b, bead_type_name);
b->setMolecule(mol);
pos = Eigen::Vector3d::UnitX();
b->setPos(pos);

Expand All @@ -84,7 +82,6 @@ BOOST_AUTO_TEST_CASE(test_nblist_3body_generate_list) {
b = top.CreateBead(Bead::spherical, name, bead_type_name, resnr, mass,
charge);
mol->AddBead(b, bead_type_name);
b->setMolecule(mol);
pos[0] = 1.0;
pos[1] = 1.0;
pos[2] = 0.0;
Expand Down
3 changes: 0 additions & 3 deletions src/tests/test_nblistgrid_3body.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ BOOST_AUTO_TEST_CASE(test_nblist_3body_generate_list) {
pos[2] = 0.0;
b->setPos(pos);
mol->AddBead(b, bead_type_name);
b->setMolecule(mol);

name = "dummy2";
resnr = 0;
Expand All @@ -75,7 +74,6 @@ BOOST_AUTO_TEST_CASE(test_nblist_3body_generate_list) {
b = top.CreateBead(Bead::spherical, name, bead_type_name, resnr, mass,
charge);
mol->AddBead(b, bead_type_name);
b->setMolecule(mol);
pos[0] = 1.0;
pos[1] = 0.0;
pos[2] = 0.0;
Expand All @@ -88,7 +86,6 @@ BOOST_AUTO_TEST_CASE(test_nblist_3body_generate_list) {
b = top.CreateBead(Bead::spherical, name, bead_type_name, resnr, mass,
charge);
mol->AddBead(b, bead_type_name);
b->setMolecule(mol);
pos[0] = 1.0;
pos[1] = 1.0;
pos[2] = 0.0;
Expand Down