Skip to content

Commit

Permalink
Encapsulate bond parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Jan 9, 2024
1 parent da16280 commit 993cb26
Show file tree
Hide file tree
Showing 31 changed files with 167 additions and 434 deletions.
11 changes: 1 addition & 10 deletions src/core/bonded_interactions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

target_sources(
espresso_core
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/angle_cosine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/angle_cossquare.cpp
${CMAKE_CURRENT_SOURCE_DIR}/bonded_interaction_data.cpp
${CMAKE_CURRENT_SOURCE_DIR}/bonded_tab.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fene.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rigid_bond.cpp
${CMAKE_CURRENT_SOURCE_DIR}/thermalized_bond.cpp
${CMAKE_CURRENT_SOURCE_DIR}/thermalized_bond_utils.cpp)
target_sources(espresso_core PRIVATE bonded_interaction_data.cpp)
7 changes: 3 additions & 4 deletions src/core/bonded_interactions/angle_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANGLE_COMMON_H
#define ANGLE_COMMON_H

#pragma once

/** \file
* Common code for functions calculating angle forces.
*/
Expand Down Expand Up @@ -95,5 +96,3 @@ angle_generic_force(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2,
auto f_mid = -(f_left + f_right);
return std::make_tuple(f_mid, f_left, f_right);
}

#endif /* ANGLE_COMMON_H */
35 changes: 0 additions & 35 deletions src/core/bonded_interactions/angle_cosine.cpp

This file was deleted.

14 changes: 9 additions & 5 deletions src/core/bonded_interactions/angle_cosine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANGLE_COSINE_H
#define ANGLE_COSINE_H

#pragma once

/** \file
* Routines to calculate the angle energy or/and and force
* for a particle triple using the potential described in
Expand Down Expand Up @@ -50,7 +51,12 @@ struct AngleCosineBond {

static constexpr int num = 2;

AngleCosineBond(double bend, double phi0);
AngleCosineBond(double bend, double phi0) {
this->bend = bend;
this->phi0 = phi0;
this->cos_phi0 = cos(phi0);
this->sin_phi0 = sin(phi0);
}

std::tuple<Utils::Vector3d, Utils::Vector3d, Utils::Vector3d>
forces(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const;
Expand Down Expand Up @@ -98,5 +104,3 @@ inline double AngleCosineBond::energy(Utils::Vector3d const &vec1,
// trig identity: cos(phi - phi0) = cos(phi)cos(phi0) + sin(phi)sin(phi0)
return bend * (1 - (cos_phi * cos_phi0 + sin_phi * sin_phi0));
}

#endif /* ANGLE_COSINE_H */
33 changes: 0 additions & 33 deletions src/core/bonded_interactions/angle_cossquare.cpp

This file was deleted.

14 changes: 9 additions & 5 deletions src/core/bonded_interactions/angle_cossquare.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANGLE_COSSQUARE_H
#define ANGLE_COSSQUARE_H

#pragma once

/** \file
* Routines to calculate the angle energy or/and and force
* for a particle triple using the potential described in
Expand All @@ -31,6 +32,7 @@
#include <utils/Vector.hpp>
#include <utils/math/sqr.hpp>

#include <cmath>
#include <tuple>

/** Parameters for three-body angular potential (cossquare). */
Expand All @@ -46,7 +48,11 @@ struct AngleCossquareBond {

static constexpr int num = 2;

AngleCossquareBond(double bend, double phi0);
AngleCossquareBond(double bend, double phi0) {
this->bend = bend;
this->phi0 = phi0;
this->cos_phi0 = cos(phi0);
}

std::tuple<Utils::Vector3d, Utils::Vector3d, Utils::Vector3d>
forces(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const;
Expand Down Expand Up @@ -87,5 +93,3 @@ inline double AngleCossquareBond::energy(Utils::Vector3d const &vec1,
auto const cos_phi = calc_cosine(vec1, vec2, true);
return 0.5 * bend * Utils::sqr(cos_phi - cos_phi0);
}

#endif /* ANGLE_COSSQUARE_H */
7 changes: 3 additions & 4 deletions src/core/bonded_interactions/angle_harmonic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANGLE_HARMONIC_H
#define ANGLE_HARMONIC_H

#pragma once

/** \file
* Routines to calculate the angle energy or/and and force
* for a particle triple using the potential described in
Expand Down Expand Up @@ -91,5 +92,3 @@ inline double AngleHarmonicBond::energy(Utils::Vector3d const &vec1,
auto const phi = acos(cos_phi);
return 0.5 * bend * Utils::sqr(phi - phi0);
}

#endif /* ANGLE_HARMONIC_H */
7 changes: 3 additions & 4 deletions src/core/bonded_interactions/bonded_coulomb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CORE_BN_IA_BONDED_COULOMB_HPP
#define CORE_BN_IA_BONDED_COULOMB_HPP

#pragma once

/** \file
* Routines to calculate the bonded Coulomb potential between
* particle pairs.
Expand Down Expand Up @@ -85,5 +86,3 @@ BondedCoulomb::energy(double const q1q2, Utils::Vector3d const &dx) const {
return .0;
#endif
}

#endif
7 changes: 3 additions & 4 deletions src/core/bonded_interactions/bonded_coulomb_sr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CORE_BN_IA_BONDED_COULOMB_SR_HPP
#define CORE_BN_IA_BONDED_COULOMB_SR_HPP

#pragma once

/** \file
* Routines to calculate the short-range part of the bonded Coulomb potential
* between particle pairs. Can be used to subtract certain intramolecular
Expand Down Expand Up @@ -98,5 +99,3 @@ inline boost::optional<double> BondedCoulombSR::energy(
return 0.;
#endif
}

#endif
20 changes: 19 additions & 1 deletion src/core/bonded_interactions/bonded_interaction_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bonded_interaction_data.hpp"
#include "rigid_bond.hpp"
#include "system/System.hpp"
#include "thermalized_bond.hpp"

#include <boost/range/numeric.hpp>
#include <boost/variant.hpp>
Expand Down Expand Up @@ -59,7 +61,23 @@ double maximal_cutoff_bonded() {
}

void BondedInteractionsMap::on_ia_change() {
n_thermalized_bonds = 0;
#ifdef BOND_CONSTRAINT
n_rigid_bonds = 0;
#endif
for (auto &kv : *this) {
if (boost::get<ThermalizedBond>(&(*kv.second)) != nullptr) {
++n_thermalized_bonds;
}
#ifdef BOND_CONSTRAINT
if (boost::get<RigidBond>(&(*kv.second)) != nullptr) {
++n_rigid_bonds;
}
#endif
}
if (System::is_system_set()) {
System::get_system().on_short_range_ia_change();
auto &system = System::get_system();
system.on_short_range_ia_change();
system.on_thermostat_param_change(); // thermalized bonds
}
}
8 changes: 8 additions & 0 deletions src/core/bonded_interactions/bonded_interaction_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,18 @@ class BondedInteractionsMap {
auto get_zero_based_type(int bond_id) const {
return contains(bond_id) ? at(bond_id)->which() : 0;
}
auto get_n_thermalized_bonds() const { return n_thermalized_bonds; }
#ifdef BOND_CONSTRAINT
auto get_n_rigid_bonds() const { return n_rigid_bonds; }
#endif

private:
container_type m_params = {};
key_type next_key = static_cast<key_type>(0);
int n_thermalized_bonds = 0;
#ifdef BOND_CONSTRAINT
int n_rigid_bonds = 0;
#endif
void on_ia_change();
};

Expand Down
6 changes: 2 additions & 4 deletions src/core/bonded_interactions/bonded_interaction_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CORE_BN_IA_BONDED_INTERACTION_UTILS_HPP
#define CORE_BN_IA_BONDED_INTERACTION_UTILS_HPP

#pragma once

#include "bonded_interaction_data.hpp"

Expand Down Expand Up @@ -67,5 +67,3 @@ inline bool pair_bond_enum_exists_between(Particle const &p1,
return pair_bond_enum_exists_on<BondType>(p1, p2) or
pair_bond_enum_exists_on<BondType>(p2, p1);
}

#endif
6 changes: 3 additions & 3 deletions src/core/bonded_interactions/bonded_interactions.dox
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
*
* @subsection bondedIA_new_struct Defining the new interaction
*
* Every interaction resides in its own source .cpp and .hpp files. A simple
* example for a bonded interaction is the FENE bond in @ref fene.hpp and
* @ref fene.cpp. Use these two files as templates for your interaction.
* Every interaction resides in its own source .hpp file. A simple
* example for a bonded interaction is the FENE bond in @ref fene.hpp.
* Use this file as template for your new interaction.
*
* The first step is to create a new @c struct which represents your new
* bond type inside the .hpp file. It needs to have the following members:
Expand Down
61 changes: 0 additions & 61 deletions src/core/bonded_interactions/bonded_tab.cpp

This file was deleted.

Loading

0 comments on commit 993cb26

Please sign in to comment.