10 namespace pairpotential {
18 class QuaternionRotate;
36 virtual void from_json(
const json& j);
37 virtual void to_json(
json& j)
const;
60 bool keep_positions =
false;
61 bool allow_overlap =
false;
62 int max_trials = 20
'000; //!< Maximum number of container overlap checks 65 operator()(const Geometry::GeometryBase& geo, MoleculeData& molecule, 66 const ParticleVector& ignored_other_particles = ParticleVector()) override; 67 void from_json(const json& j) override; 68 void to_json(json& j) const override; 76 std::vector<Point> positions; 77 std::vector<double> charges; 79 void copyTo(ParticleVector& particles) const; //!< Copy conformation into particle vector 89 class ExclusionsSimple 91 bool any_exclusions = false; //!< true if at least one excluded interaction is present 92 int size; //!< number of particles within the group; matrix = size × size 94 unsigned char; //!< obs: std::vector<bool> uses packing with performance implications 95 std::shared_ptr<std::vector<char_bool>> 96 excluded_pairs; //!< 1D exclusion matrix; shared ptr saves copying 99 using AtomPair = std::pair<int, int>; 101 static ExclusionsSimple create(int atoms_cnt, const std::vector<std::pair<int, int>>& pairs); 102 explicit ExclusionsSimple(int size = 0); 104 void add(int i, int j); 105 void add(const std::vector<AtomPair>& pairs); 107 bool isExcluded(int i, int j) const; 108 bool empty() const; //!< true if no excluded interactions at all 109 friend void from_json(const json& j, ExclusionsSimple& exclusions); 110 friend void to_json(json& j, const ExclusionsSimple& exclusions); 113 inline bool ExclusionsSimple::isExcluded(int i, int j) const 118 // use the bracket syntax to skip checks to speed-up reading 119 return any_exclusions && static_cast<bool>((*excluded_pairs)[i * size + j]); 122 inline bool ExclusionsSimple::empty() const 124 return !any_exclusions; 127 void from_json(const json& j, ExclusionsSimple& exclusions); 128 void to_json(json& j, const ExclusionsSimple& exclusions); 140 class ExclusionsVicinity 144 unsigned char; //!< obs: std::vector<bool> uses packing with performance implications 145 using AtomPair = std::pair<int, int>; 148 int atoms_cnt = 0; //!< count of atoms in the molecule; unmutable 149 int max_bond_distance = 0; //!< max distance (difference) between indices of excluded particles 150 std::shared_ptr<std::vector<char_bool>> 151 excluded_pairs; //!< 1D exclusion matrix; shared ptr saves copying 153 int toIndex(int i, int j) const; 154 AtomPair fromIndex(int n) const; 161 static ExclusionsVicinity create(int atoms_cnt, const std::vector<AtomPair>& pairs); 167 explicit ExclusionsVicinity(int atoms_cnt = 0, int max_difference = 0); 170 void add(int i, int j); 171 void add(const std::vector<std::pair<int, int>>& pairs); 172 bool isExcluded(int i, 174 const; //!< @param i, j indices of atoms within molecule with excluded nonbonded interaction 175 bool empty() const; //!< true if no excluded interactions at all 176 friend void to_json(json& j, const ExclusionsVicinity& exclusions); 179 inline bool ExclusionsVicinity::isExcluded(int i, int j) const 184 // use bracket syntax to skip checks to speed-up reading 185 return (j - i <= max_bond_distance && static_cast<bool>((*excluded_pairs)[toIndex(i, j)])); 188 inline bool ExclusionsVicinity::empty() const 190 return max_bond_distance == 0; 193 inline int ExclusionsVicinity::toIndex(int i, int j) const 195 return i * max_bond_distance + (j - i - 1); 198 inline ExclusionsVicinity::AtomPair ExclusionsVicinity::fromIndex(const int n) const 200 auto i = n / max_bond_distance; 201 auto j = n % max_bond_distance + i + 1; 205 // void from_json(const json &j, ExclusionsVicinity &exclusions); // not implemented 206 void to_json(json& j, const ExclusionsVicinity& exclusions); 214 using index_type = int; 217 json json_cfg; //!< data useful only for to_json 219 bool implicit = false; //!< Is molecule implicit and explicitly absent from simulation cell? 222 ExclusionsVicinity exclusions; //!< Implementation of isPairExcluded; 225 std::shared_ptr<MoleculeInserter> inserter = nullptr; //!< Functor for insertion into space 227 index_type& id(); //!< Type id 228 const index_type& id() const; //!< Type id 229 void createMolecularConformations(const json& j); //!< Add conformations if appropriate 230 void setConformationWeights(const json& j); //!< Add weights for conformations 232 std::string name; //!< Molecule name 233 bool atomic = false; //!< True if atomic group (salt etc.) 235 false; //!< True if compressible group (scales internally upon volume change) 236 bool rigid = false; //!< True if particle should be considered as rigid 237 double activity = 0.0; //!< Chemical activity (mol/l) 239 std::vector<AtomData::index_type> atoms; //!< Sequence of atoms in molecule (atom id's)
242 size_t numConformations()
const;
248 bool isImplicit()
const;
249 bool isPairExcluded(
int i,
int j)
const;
250 bool isMolecular()
const;
251 bool isAtomic()
const;
258 void setInserter(std::shared_ptr<MoleculeInserter> ins);
277 inline bool MoleculeData::isPairExcluded(
int i,
int j)
const 279 return exclusions.isExcluded(i, j);
284 void from_json(
const json& j, std::vector<MoleculeData>& v);
287 extern std::vector<MoleculeData>
molecules;
317 bool is_used =
false;
318 std::string molecule_name;
320 decltype(MoleculeData::bonds) bonds;
321 std::vector<std::pair<int, int>> exclusion_pairs;
325 isFasta(
const json& j);
326 void readCompoundValues(
328 void readAtomic(
const json& j);
330 readParticles(
const json& j);
331 void readBonds(
const json& j);
332 void readFastaBonds(
const json& j);
333 void readExclusions(
const json& j);
334 static std::shared_ptr<MoleculeInserter> createInserter(
const json& j);
356 void readFile(
ParticleVector& particles,
const std::string& filename)
const;
373 using AtomPair = std::pair<int, int>;
374 using AtomPairList = std::vector<AtomPair>;
375 using BondVector = decltype(MoleculeData::bonds);
378 std::map<int, AtomList>
380 std::vector<std::set<AtomList>> paths;
384 void createBondMap(
const BondVector& bonds);
385 void generatePaths(
int bonded_distance);
395 void generatePairs(AtomPairList& pairs,
int bond_distance);
424 using AtomicAndMolecularPair = std::pair<const StoichiometryMap&, const StoichiometryMap&>;
426 StoichiometryMap::value_type;
427 using MapFilter = std::function<bool(const ReactionData::StoichiometryPair&)>;
428 enum class Direction : char
434 const static MapFilter is_implicit_group;
435 const static MapFilter not_implicit_group;
436 const static MapFilter not_implicit_atom;
437 const static MapFilter is_atomic_group;
438 const static MapFilter is_molecular_group;
444 Direction direction = Direction::RIGHT;
445 std::vector<std::string> left_names, right_names;
451 double lnK_unmodified = 0.0;
452 std::string reaction_str;
462 findAtomOrMolecule(
const std::string& atom_or_molecule_name);
465 void setDirection(Direction);
467 Direction getDirection()
const;
468 void reverseDirection();
469 AtomicAndMolecularPair getProducts()
const;
470 AtomicAndMolecularPair getReactants()
const;
471 double freeEnergy()
const;
472 bool containsAtomicSwap()
const;
473 const std::string& getReactionString()
const;
475 std::pair<std::set<int>, std::set<int>>
476 participatingAtomsAndMolecules()
const;
478 bool only_neutral_molecules =
false;
487 std::pair<std::vector<std::string>, std::vector<std::string>>
493 extern std::vector<ReactionData>
reactions;
nlohmann::json json
JSON object.
Definition: json_support.h:10
Eigen::Vector3d Point
3D vector used for positions, velocities, forces etc.
Definition: coordinates.h:7
StoichiometryMap::value_type StoichiometryPair
first = id; second = stoichiometic coeff.
Definition: molecule.h:426
Random random
global instance of Random
Definition: random.cpp:62
General properties of reactionsEnd of class.
Definition: molecule.h:420
Random number generator.
Definition: random.h:34
Rotation routine using the Eigen library.
Definition: rotate.h:12
MoleculeData & findMoleculeByName(std::string_view name)
Finds a molecule by its name in the global Faunus molecules lexicon.
Definition: molecule.cpp:1306
std::vector< int > AtomList
a path created from 1-2 bonds (e.g., harmonic or FENE) as an ordered list of atoms involved; atoms ar...
Definition: molecule.h:372
std::map< int, int > StoichiometryMap
key = id; value = stoichiometic coeff.
Definition: molecule.h:423
Common ancestor of Faunus specific runtime errors.
Definition: core.h:50
Constructs MoleculeData from JSON.
Definition: molecule.h:315
std::vector< Faunus::AtomData > atoms
Global instance of atom list.
Definition: atomdata.cpp:242
Random position and orientation - typical for rigid bodies.
Definition: molecule.h:32
An interface for all geometries.Base class for all geometries.
Definition: geometry.h:107
std::vector< Particle > ParticleVector
Storage type for collections of particles.
Definition: particle.h:253
General properties for molecules.
Definition: molecule.h:211
This file contains auxiliary functionality that have no dependencies other than STL and can hence be ...
Cell list class templates.
Definition: actions.cpp:11
std::pair< std::vector< std::string >, std::vector< std::string > > parseReactionString(const std::string &process_string)
This parses a string containing a reaction, e.g.
Definition: molecule.cpp:1321
std::vector< MoleculeData > molecules
List of molecule types.
Definition: molecule.cpp:22
Fills the particle vector from various sources, e.g., files or JSON array.
Definition: molecule.h:344
Generate all possible atom pairs within a given bond distance.
Definition: molecule.h:367
An exception to indicate an unknown molecule name in the input.
Definition: molecule.h:292
std::vector< ReactionData > reactions
List of reactions.
Definition: molecule.cpp:23
Inserts molecules into random positions in the container.
Definition: molecule.h:47
WeightedDistribution< ParticleVector > conformations
Conformations of molecule.
Definition: molecule.h:241
std::vector< MoleculeData::index_type > parseMolecules(const json &j)
Definition: molecule.cpp:1345