faunus
Namespaces | Classes | Typedefs | Functions | Variables
Faunus Namespace Reference

Cell list class templates. More...

Namespaces

 analysis
 Adding a new analysis requires the following steps:
 
 ChemistryUnits
 Chemistry units.
 
 Energy
 
 Geometry
 Simulation geometries and related operations.
 
 pairpotential
 Namespace for particle pair-potentials.
 
 PhysicalConstants
 Physical constants.
 
 Region
 Subspaces around particles, molecules etc.
 
 Scatter
 Routines related to scattering.
 
 SpheroCylinder
 The algorithms found here are mainly direct conversions from Robert Vacha's spherocylinder C code (~2008-2010).
 
 Tabulate
 Class templates for tabulation of pair potentials.
 

Classes

class  AminoAcidModelReader
 
class  AminoAcidModelWriter
 
class  AngularScan
 Rotate and translate two molecules to explore all poses. More...
 
class  Average
 Class to collect averages. More...
 
class  AverageObj
 Simple class to average data contained in objects. More...
 
class  AverageObjStdev
 
class  AverageStdev
 Class to collect averages and standard deviation. More...
 
struct  BasePointerVector
 Helper class for storing vectors of base pointers. More...
 
struct  Change
 Specify changes made to a system. More...
 
struct  Charge
 Charge (monopole) property. More...
 
class  Cigar
 Patchy sphero cylinder a.k.a.Sphero-cylinder properties. More...
 
class  CoarseGrainedFastaFileReader
 Reads FASTA file and generate one particle per amino acid. More...
 
struct  ConfigurationError
 Exception to be thrown when parsing json configuration. More...
 
struct  Conformation
 Possible structure for molecular conformations. More...
 
class  Decorrelation
 "Decorrelation" class from https://dx.doi.org/10.1002/jcc.20746 More...
 
struct  Dipole
 Dipole properties. More...
 
class  DynamicArray2D
 
class  DynamicArray3D
 
class  ElasticRange
 Turns a pair of iterators into an elastic range. More...
 
class  Electrolyte
 Stores information about salts for calculation of Debye screening length etc. More...
 
class  Equidistant2DTable
 
class  ExclusionsSimple
 Determines if two particles within a group are excluded from mutual nonbonded interactions. More...
 
class  ExclusionsVicinity
 Determines if two particles within a group are excluded from mutual nonbonded interactions. More...
 
struct  GenericError
 Common ancestor of Faunus specific runtime errors. More...
 
class  GromacsReader
 
class  GromacsWriter
 
class  Group
 End of Group class. More...
 
class  InsertMoleculesInSpace
 Insert molecules into space. More...
 
class  InteractionData
 A stub to hold various parameters of interactions. More...
 
struct  IOError
 Exception to be thrown on IO errors. More...
 
struct  IterRange
 Turns a pair of iterators into a range. More...
 
class  Legendre
 Evaluate n'th degree Legendre polynomial. More...
 
class  MetropolisMonteCarlo
 Class to handle Monte Carlo moves. More...
 
class  MoleculeBuilder
 Constructs MoleculeData from JSON. More...
 
class  MoleculeData
 General properties for molecules. More...
 
struct  MoleculeInserter
 Random position and orientation - typical for rigid bodies. More...
 
class  MoleculeStructureReader
 Fills the particle vector from various sources, e.g., files or JSON array. More...
 
class  NeighboursGenerator
 Generate all possible atom pairs within a given bond distance. More...
 
struct  ordered_pair
 Ordered pair where first<=second More...
 
class  PairMatrix
 Container for data between pairs. More...
 
class  Particle
 Particle class for storing positions, id, and other properties. More...
 
struct  ParticlePropertyBase
 Base class for particle properties. More...
 
class  ParticleTemplate
 Particle template. More...
 
struct  Polarizable
 
class  PQRReader
 
class  PQRWriter
 
struct  Quadrupole
 
class  Quantize
 Round and bin numbers for use with tables and histograms. More...
 
class  QuaternionRotate
 Rotation routine using the Eigen library. More...
 
struct  Radius
 Radius property. More...
 
class  Random
 Random number generator. More...
 
class  RandomInserter
 Inserts molecules into random positions in the container. More...
 
class  ReactionData
 General properties of reactionsEnd of class. More...
 
struct  RowMajorOffset
 memory offset for arbitrary dimensions, row-major layout More...
 
struct  SingleUseJSON
 Like json, but delete entries after access. More...
 
class  Space
 Placeholder for atoms and molecules. More...
 
class  SparseHistogram
 Histogram for an arbitrary set of values using a sparse memory layout (map) More...
 
class  SpheroCylinderData
 Static properties for patchy sphero cylinders (PSC) More...
 
class  SpheroCylinderXYZReader
 
class  SpheroCylinderXYZWriter
 Modified XYZ format that also saves spherocylinder direction and patch (ported from Faunus v1) More...
 
class  Stopwatch
 Simple struct to measure duration of code. More...
 
class  StructureFileReader
 Base class to load simple structure files such as XYZ, AAM, PQR etc. More...
 
class  StructureFileWriter
 Base class to writeKeyValuePairs simple structure files such as XYZ, AAM, PQR etc. More...
 
struct  SystemAction
 Performs a task or "action" on the system, typically before or after a simulation. More...
 
class  Table
 Dynamic table for 1d data. More...
 
class  Table2D
 General class for handling 2D tables - xy data, for example. More...
 
struct  Tensor
 Tensor class Tensor class. More...
 
class  TimeRelativeOfTotal
 Timer for measuring relative time consumption. More...
 
class  TipFromTheManual
 Class for showing help based on input errors. More...
 
struct  TrajectoryFrame
 Simple data structure to store a trajectory frame in native Faunus format. More...
 
class  TranslationalEntropy
 Entropy change due to particle fluctuations. More...
 
struct  UnknownAtomError
 An exception to indicate an unknown atom name in the input. More...
 
struct  UnknownMoleculeError
 An exception to indicate an unknown molecule name in the input. More...
 
class  WeightedDistribution
 Stores a series of elements with given weight. More...
 
class  XTCReader
 Reads frames from an XTC file (GROMACS compressed trajectory file format). More...
 
struct  XTCTrajectoryFrame
 Base data structure for native XTC format as used in Gromacs and supported by the C library. More...
 
class  XTCWriter
 Writes frames into an XTC file (GROMACS compressed trajectory file format). More...
 
class  XYZReader
 XYZ file loader. More...
 
class  XYZWriter
 

Typedefs

using Point = Eigen::Vector3d
 3D vector used for positions, velocities, forces etc.
 
using json = nlohmann::json
 JSON object.
 
using PointVector = std::vector< Point >
 Vector of 3D vectors.
 
using ParticleVector = std::vector< Particle >
 Storage type for collections of particles.
 
using RandomNumberEngine = std::mt19937
 

Functions

std::unique_ptr< SystemActioncreateAction (std::string_view name, const json &properties, Space &spc)
 Create single action from JSON input.
 
std::vector< std::unique_ptr< SystemAction > > createActionList (const json &input, Space &spc)
 Create vector of actions from JSON list input.
 
void from_json (const json &j, InteractionData &a)
 
void from_single_use_json (SingleUseJSON &j, InteractionData &a)
 
void to_json (json &j, const InteractionData &a)
 
void to_json (json &j, const AtomData &a)
 
void set_dp_and_dprot (const json &j, AtomData &atomdata)
 Handles optional translational and rotational displacement.
 
void from_json (const json &j, AtomData &a)
 
void from_json (const json &j, std::vector< Faunus::AtomData > &atom_vector)
 
 TEST_SUITE_BEGIN ("AtomData")
 
 TEST_CASE ("[Faunus] AtomData")
 
 TEST_SUITE_END ()
 
AtomData & findAtomByName (std::string_view name)
 Finds an atom by its name in the global Faunus atoms lexicon. More...
 
void from_json (const json &j, SpheroCylinderData &psc)
 
void to_json (json &j, const SpheroCylinderData &psc)
 
 NLOHMANN_JSON_SERIALIZE_ENUM (SpheroCylinderData::PatchType, {{SpheroCylinderData::PatchType::Invalid, nullptr}, {SpheroCylinderData::PatchType::Full, "full"}, {SpheroCylinderData::PatchType::Capped, "capped"}, {SpheroCylinderData::PatchType::None, "none"}}) class AtomData
 General properties for atoms. More...
 
void from_json (const json &j, std::vector< AtomData > &atom_vector)
 Construct vector of atoms from json array. More...
 
auto findName (RequireNamedElements auto &range, std::string_view name)
 Finds the first element with a member attribute name matching the input. More...
 
auto findName (const RequireNamedElements auto &range, std::string_view name)
 
template<RequireNamedElements T>
auto names2ids (const T &database, const std::vector< std::string > &names)
 Search for name in database and return id() More...
 
template<typename T >
constexpr auto arange (const T start, const T stop, const T step)
 Return evenly spaced values within a given interval. More...
 
 TEST_CASE ("[Faunus] arange")
 
Point xyz2rth (const Point &, const Point &origin={0, 0, 0}, const Point &dir={0, 0, 1}, const Point &dir2={1, 0, 0})
 Convert cartesian- to cylindrical-coordinates. More...
 
Point xyz2rtp (const Point &, const Point &origin={0, 0, 0})
 Convert cartesian- to spherical-coordinates. More...
 
Point rtp2xyz (const Point &rtp, const Point &origin={0, 0, 0})
 Convert spherical- to cartesian-coordinates. More...
 
template<typename dbl = double, class iter , class memberptr >
auto asEigenMatrix (iter begin, iter end, memberptr m)
 Eigen::Map facade to data members in STL container. More...
 
template<typename dbl = double, class iter , class memberptr >
auto asEigenVector (iter begin, iter end, memberptr m)
 
 TEST_CASE ("[Faunus] Equidistant2DTable")
 
template<std::floating_point T>
T erfc_x (T x)
 Approximation of erfc-function. More...
 
 TEST_CASE ("[Faunus] erfc_x")
 
template<typename T >
T erf_x (T x)
 Approximate 1 - erfc_x. More...
 
template<class Tint = std::int32_t>
double exp_cawley (double y)
 Approximate exp() function. More...
 
double exp_untested (double y)
 
 TEST_CASE ("[Faunus] exp_cawley")
 
 TEST_CASE ("[Faunus] exp_untested")
 
template<typename float_t = double, char iterations = 1>
float_t inv_sqrt (float_t x)
 Fast inverse square-root approximation. More...
 
template<class T1 , class T2 >
auto distance (T1 first, T2 last)
 Distance between two arbitrary contiguous iterators.
 
template<class Trange >
size_t range_size (Trange &rng)
 Size of a Ranges object using the cpp20::distance()
 
json loadJSON (const std::string &filename)
 Read json filename into json object (w. syntax check)
 
double roundValue (double value, int number_of_digits=3)
 Round to n number of significant digits.
 
void roundJSON (json &j, int number_of_digits=3)
 Round float objects to n number of significant digits.
 
double getValueInfinity (const json &j, const std::string &key)
 Extract floating point from json and allow for 'inf' and '-inf'.
 
std::tuple< const std::string &, const json & > jsonSingleItem (const json &j)
 Returns a key-value pair from a JSON object which contains a single key. More...
 
template<typename T >
std::optional< Tget_optional (const json &j, std::string_view key)
 Extract JSON value associated with key into std::optional More...
 
template<typename SparseMatrixType >
bool streamMarket (const SparseMatrixType &mat, std::ostream &out, bool symmetric=false)
 Save Matrix Market sparse matrix. More...
 
 TEST_CASE ("[Faunus] RowMajor3DMatrix")
 
 TEST_CASE ("[Faunus] PairMatrix")
 
template<class T >
constexpr T powi (T x, unsigned int n)
 n'th integer power of float More...
 
 TEST_CASE ("[Faunus] powi")
 
template<class Tx , class Ty >
Table2D< Tx, Ty > operator- (Table2D< Tx, Ty > &a, Table2D< Tx, Ty > &b)
 Subtract two tables.
 
template<class Tx , class Ty >
Table2D< Tx, Ty > operator+ (Table2D< Tx, Ty > &a, Table2D< Tx, Ty > &b)
 Addition two tables.
 
 TEST_SUITE_BEGIN ("Auxiliary")
 
 TEST_CASE ("[Faunus] for_each_pair")
 
 TEST_CASE ("[Faunus] ordered_pair")
 
 TEST_CASE ("[Faunus] Text manipulation")
 
 TEST_CASE ("numeric_cast")
 
template<std::integral TOut, std::floating_point TIn>
TOut numeric_cast (const TIn number)
 Convert floating point number to integral number. More...
 
template<std::forward_iterator Titer, typename Tfunction , typename T = double, typename Taggregate_function >
T for_each_unique_pair (Titer begin, Titer end, Tfunction f, Taggregate_function aggregator=std::plus< T >())
 Iterate over pairs in container, call a function on the elements, and sum results. More...
 
template<std::ranges::range T>
T erase_range (T target, const T &values)
 Erase from target range all values found in values range.
 
template<std::floating_point T, std::integral Tint = int>
Tint to_bin (T x, T dx=1)
 Round a floating point to integer for use with histogram binning. More...
 
template<StringStreamable T>
auto splitConvert (const std::string &words)
 Convert space separated words into vector of type T. More...
 
template<std::ranges::range Range>
std::string joinToString (const Range &values) requires StringStreamable< std
 Convert range of values into space separated string. More...
 
template<typename T >
void to_json (nlohmann::json &j, const BasePointerVector< T > &b)
 
template<typename T >
void from_json (const nlohmann::json &j, BasePointerVector< T > &b)
 
 TEST_CASE ("[Faunus] Average")
 
 TEST_CASE ("[Faunus] AverageStd")
 
 TEST_CASE ("[Faunus] AverageObj")
 
void displayError (spdlog::logger &logger, const std::exception &e, int level=0)
 Nicely displays nested exceptions using a logger. More...
 
void to_json (json &j, const Electrolyte &electrolyte)
 
std::optional< ElectrolytemakeElectrolyte (const json &j)
 Create ionic salt object from json.
 
void to_json (json &j, const Group &group)
 
void from_json (const json &j, Group &group)
 
 TEST_SUITE_BEGIN ("Group")
 
 TEST_CASE ("[Faunus] swap_to_back")
 
 TEST_CASE ("[Faunus] ElasticRange")
 
 TEST_CASE ("[Faunus] Group")
 
template<typename T >
void swap_to_back (T first, T last, T end)
 Move range [first:last] to [end] by swapping elements.
 
template<unsigned int mask>
std::function< bool(const Group &)> getGroupFilter ()
 Get lambda function matching given enum Select mask.
 
 TEST_CASE ("[Faunus] openCompressedOutputStream")
 
 TEST_CASE ("XTCFrame")
 
ParticleVector fastaToParticles (std::string_view fasta_sequence, double bond_length=7.0, const Point &origin={0, 0, 0})
 Create particle vector from FASTA sequence with equally spaced atoms. More...
 
std::unique_ptr< StructureFileWritercreateStructureFileWriter (const std::string &suffix)
 Create structure writer. More...
 
ParticleVector loadStructure (std::string_view filename, bool prefer_charges_from_file=true)
 Load structure file into particle vector. More...
 
std::vector< AtomData::index_type > fastaToAtomIds (std::string_view fasta_sequence)
 Convert FASTA sequence to atom id sequence. More...
 
 TEST_CASE ("[Faunus] StructureFileReader and StructureFileWriter")
 
 TEST_CASE ("[Faunus] CoarseGrainedFastaFileReader")
 
std::string addGrowingSuffix (const std::string &)
 Add growing suffix filename until non-existing name is found.
 
 TEST_SUITE_BEGIN ("Molecule")
 
void to_json (json &j, const MoleculeData &a)
 
 TEST_CASE ("[Faunus] MoleculeData")
 
 TEST_CASE ("NeighboursGenerator")
 
 TEST_CASE ("[Faunus] MoleculeBuilder")
 
void from_json (const json &j, MoleculeData &a)
 
void from_json (const json &j, std::vector< MoleculeData > &v)
 
 TEST_CASE ("[Faunus] MoleculeStructureReader")
 
void from_json (const json &j, ExclusionsSimple &exclusions)
 
void to_json (json &j, const ExclusionsSimple &exclusions)
 
void to_json (json &j, const ExclusionsVicinity &exclusions)
 
 TEST_CASE ("[Faunus] ExclusionsVicinity")
 
void from_json (const json &j, MoleculeInserter &inserter)
 
void to_json (json &j, const MoleculeInserter &inserter)
 
 TEST_CASE ("[Faunus] Conformation")
 
void from_json (const json &j, ReactionData &a)
 
void to_json (json &j, const ReactionData &reaction)
 
 TEST_CASE ("[Faunus] ReactionData")
 
MoleculeDatafindMoleculeByName (std::string_view name)
 Finds a molecule by its name in the global Faunus molecules lexicon. More...
 
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. More...
 
std::vector< MoleculeData::index_type > parseMolecules (const json &j)
 
void from_json (const json &, MetropolisMonteCarlo::State &)
 Build state from json object.
 
void to_json (json &j, const MetropolisMonteCarlo &monte_carlo)
 
template<class Tvec >
double q2mu (double QBxMuA, const Tvec &muA, double QAxMuB, const Tvec &muB, const Tvec &r)
 Returns ion-dipole interaction. More...
 
template<class Tvec >
double mu2mu (const Tvec &muA, const Tvec &muB, double muAxmuB, const Tvec &r, double a=1.0, double b=0.0)
 Returns dipole-dipole interaction. More...
 
template<class Tvec , class Tmat >
double q2quad (double qA, const Tmat &quadB, double qB, const Tmat &quadA, const Tvec &r)
 Returns ion-quadrupole interaction. More...
 
template<std::forward_iterator Titer>
double monopoleMoment (Titer begin, Titer end)
 Returns the total charge for a set of particles. More...
 
template<std::forward_iterator Titer, class BoundaryFunction = std::function<void(Point&)>>
Point dipoleMoment (Titer begin, Titer end, BoundaryFunction boundary=[](Point &) {}, const Point origin={0, 0, 0}, double cutoff=pc::infty)
 Returns the total dipole-moment for a set of particles. More...
 
 TEST_CASE ("[Faunus] dipoleMoment")
 
template<std::forward_iterator Titer, class BoundaryFunction >
Tensor quadrupoleMoment (Titer begin, Titer end, BoundaryFunction boundary=[](const Point &) {}, Point origin={0, 0, 0}, double cutoff=pc::infty)
 Returns the total quadrupole-moment for a set of particles, note with trace! More...
 
 TEST_CASE ("[Faunus] quadrupoleMoment")
 
template<class Tgroup , class BoundaryFunction >
auto toMultipole (const Tgroup &g, BoundaryFunction boundary=[](const Point &) {}, double cutoff=pc::infty)
 Converts a group to a multipole-particle. More...
 
void from_json (const json &j, Particle &particle)
 
void to_json (json &j, const Particle &particle)
 
 TEST_SUITE_BEGIN ("Particle")
 
 TEST_CASE ("[Faunus] Particle")
 
template<typename... Ts>
auto to_json (json &) -> typename std::enable_if< sizeof...(Ts)==0 >
 Particle to JSON.
 
template<typename... Ts>
auto from_json (const json &) -> typename std::enable_if< sizeof...(Ts)==0 >
 
template<typename... Properties>
void to_json (json &j, const ParticleTemplate< Properties... > &a)
 
template<typename... Properties>
void from_json (const json &j, ParticleTemplate< Properties... > &a)
 
template<RequireParticleIterator Iterator>
void applyAtomDataCharges (Iterator first, Iterator last, const double max_difference=1e-9)
 Reset all charges in particle range to those found in Faunus::atoms. More...
 
void from_json (const nlohmann::json &, Random &)
 json to Random conversion
 
void to_json (nlohmann::json &, const Random &)
 Random to json conversion.
 
Point randomUnitVector (Random &rand, const Point &directions=Point::Ones())
 Random unit vector using Neuman's method ("sphere picking")
 
Point randomUnitVectorPolar (Random &rand)
 Random unit vector using polar coordinates ("sphere picking")
 
 TEST_CASE ("[Faunus] SASA_CellList")
 
void to_json (json &j, const Change::GroupChange &group_change)
 Serialize Change data to json.
 
void to_json (json &j, const Change &change)
 Serialise Change object to json.
 
 TEST_CASE ("[Faunus] Change")
 
 TEST_CASE ("Space::numParticles")
 
void to_json (json &j, const Space &spc)
 Serialize Space to json object.
 
void from_json (const json &j, Space &spc)
 Deserialize json object to Space.
 
 TEST_SUITE_BEGIN ("Space")
 
 TEST_CASE ("[Faunus] Space")
 
 TEST_CASE ("[Faunus] Space::toIndices")
 
 TEST_CASE ("[Faunus] Space::updateParticles")
 
 TEST_CASE ("SpaceFactory")
 
struct Faunus::Change __attribute__ ((aligned(32)))
 
void to_json (nlohmann::json &, const Tensor &)
 Tensor -> Json.
 
void from_json (const nlohmann::json &, Tensor &)
 Json -> Tensor.
 
 TEST_SUITE_BEGIN ("Tensor")
 
 TEST_CASE ("[Faunus] Tensor")
 

Variables

std::vector< Faunus::AtomData > atoms
 Global instance of atom list.
 
template<typename T >
concept RequireNamedElements
 Concept for named database such as vector<AtomData>, vector<MoleculeData> etc. More...
 
TipFromTheManual usageTip
 
template<class T >
concept StringStreamable
 
template<class T >
concept Averageable
 Requirements for types used with AverageObj More...
 
template<class T >
concept RequirePoints
 Concept for a range of points. More...
 
template<class T >
concept RequirePointIterator = std::is_convertible_v<std::iter_value_t<T>, Point>
 Concept for an iterator to a Point
 
std::shared_ptr< spdlog::logger > faunus_logger
 
std::shared_ptr< spdlog::logger > mcloop_logger
 
template<typename T >
concept RequireGroups
 Concept for a range of groups. More...
 
std::vector< MoleculeDatamolecules
 List of molecule types.
 
std::vector< ReactionDatareactions
 List of reactions.
 
template<class T >
concept RequireParticles
 Concept for a range of particles. More...
 
template<class T >
concept RequireParticleIterator = std::is_convertible_v<std::iter_value_t<T>, Particle>
 
Random random
 global instance of Random
 
class Faunus::Space __attribute__
 

Detailed Description

Cell list class templates.

Faunus main namespace.

Minimal interface to be used in other header file to avoid number of class templates. Full class templates definitions are provided in "celllistimpl.h" file.

Author
Richard Chudoba
Date
2021-02-01

Function Documentation

◆ applyAtomDataCharges()

template<RequireParticleIterator Iterator>
void Faunus::applyAtomDataCharges ( Iterator  first,
Iterator  last,
const double  max_difference = 1e-9 
)

Reset all charges in particle range to those found in Faunus::atoms.

Parameters
firstIterator to first particle
lastIterator to end
max_differenceApply only if charge mismatch is larger than this, then log

◆ arange()

template<typename T >
constexpr auto Faunus::arange ( const T  start,
const T  stop,
const T  step 
)

Return evenly spaced values within a given interval.

Values are lazily generated within the half-open interval [start, stop) In other words, the interval including start but excluding stop. This function has the same behavior as Numpy's arange()

Examples:

arange(4.0, 10.0, 1.0); // --> 4 5 6 7 8 9
arange(4.0, 20.0, 3.0); // --> 4 7 10 13 16 19
arange(-1.0, 1.0, 0.5); // --> -1 -0.5 0 0.5
Template Parameters
TValue type; must be floating point or integral
Parameters
startStart of interval (included)
stopEnd of interval (excluded)
stepSpacing between values
Returns
Range of lazily generated values

◆ asEigenMatrix()

template<typename dbl = double, class iter , class memberptr >
auto Faunus::asEigenMatrix ( iter  begin,
iter  end,
memberptr  m 
)

Eigen::Map facade to data members in STL container.

No data is copied and modifications of the Eigen object modifies the original container and vice versa.

Example:

std::vector<Tparticle> v(10); auto m1 = asEigenVector(v.begin, v.end(), &Tparticle::pos); –> 10x3 maxtrix view auto m2 = asEigenMatrix(v.begin, v.end(), &Tparticle::charge); –> 10x1 vector view

Warning
Be careful that objects are properly aligned and divisible with sizeof<double>

◆ createStructureFileWriter()

std::unique_ptr< StructureFileWriter > Faunus::createStructureFileWriter ( const std::string &  suffix)

Create structure writer.

Parameters
suffixFilename suffix (pqr, pdb, aam, xyz, gro)
Returns
Shared pointer to write instance; empty if unknown suffix

◆ dipoleMoment()

template<std::forward_iterator Titer, class BoundaryFunction = std::function<void(Point&)>>
Point Faunus::dipoleMoment ( Titer  begin,
Titer  end,
BoundaryFunction  boundary = [](Point&) {},
const Point  origin = {0, 0, 0},
double  cutoff = pc::infty 
)

Returns the total dipole-moment for a set of particles.

Parameters
beginFirst particle
endLast particle
boundaryFunction to use for applying periodic boundaries. Default: do nothing.
originOrigin of dipole moment, default (0,0,0).
cutoffCut-off for included particles with regard to origin, default value is infinite

If the particle has extended properties, point dipole moments will be added as wellCalculates dipole moment vector

◆ displayError()

void Faunus::displayError ( spdlog::logger &  logger,
const std::exception &  e,
int  level = 0 
)

Nicely displays nested exceptions using a logger.

Parameters
loggerlogger to display the exception with
eexception to display (possibly nested)
levelinternal counter for recursion

◆ erf_x()

template<typename T >
T Faunus::erf_x ( T  x)
inline

Approximate 1 - erfc_x.

Parameters
xValue for which erf should be calculated

◆ erfc_x()

template<std::floating_point T>
T Faunus::erfc_x ( T  x)
inline

Approximation of erfc-function.

Parameters
xValue for which erfc should be calculated

Reference for this approximation is found in Abramowitz and Stegun, Handbook of mathematical functions, eq. 7.1.26

\[ \erf(x) = 1 - (a_1t + a_2t^2 + a_3t^3 + a_4t^4 + a_5t^5)e^{-x^2} + \epsilon(x) \]

\[ t = \frac{1}{1 + px} \]

\[ |\epsilon(x)| \le 1.5\times 10^{-7} \]

Warning
Needs modification if x < 0

◆ exp_cawley()

template<class Tint = std::int32_t>
double Faunus::exp_cawley ( double  y)

Approximate exp() function.

Note
see Cawley 2000
Warning
Does not work in big endian systems, nor on gcc

Update 2019: http://www.federicoperini.info/wp-content/uploads/FastExp-Final.pdf

◆ fastaToAtomIds()

std::vector< AtomData::index_type > Faunus::fastaToAtomIds ( std::string_view  fasta_sequence)

Convert FASTA sequence to atom id sequence.

Parameters
fasta_sequenceFASTA sequence, capital letters.
Returns
vector of verified and existing atom id's

◆ fastaToParticles()

ParticleVector Faunus::fastaToParticles ( std::string_view  fasta_sequence,
double  bond_length = 7.0,
const Point origin = {0, 0, 0} 
)

Create particle vector from FASTA sequence with equally spaced atoms.

Particle positions are generated as a random walk, starting at origin, propagating in bond_length steps.

◆ findAtomByName()

AtomData & Faunus::findAtomByName ( std::string_view  name)

Finds an atom by its name in the global Faunus atoms lexicon.

The first matching atom is returned, or an UnknownAtomError is thrown when not found.

Parameters
namean atom name to look for
Returns
an atom found
Exceptions
UnknownAtomErrorwhen no atom found

◆ findMoleculeByName()

MoleculeData & Faunus::findMoleculeByName ( std::string_view  name)

Finds a molecule by its name in the global Faunus molecules lexicon.

Exceptions
ifmolecule not found

The first matching molecule is returned, or an UnknownMoleculeError is thrown when not found.

Parameters
namea molecule name to look for
Returns
a molecule found
Exceptions
UnknownMoleculeErrorwhen no molecule found

◆ findName()

auto Faunus::findName ( RequireNamedElements auto &  range,
std::string_view  name 
)

Finds the first element with a member attribute name matching the input.

Parameters
rangea range of elements
namea name to look for
Returns
an iterator to the first element, or last if not found
See also
findAtomByName(), findMoleculeByName()

◆ for_each_unique_pair()

template<std::forward_iterator Titer, typename Tfunction , typename T = double, typename Taggregate_function >
T Faunus::for_each_unique_pair ( Titer  begin,
Titer  end,
Tfunction  f,
Taggregate_function  aggregator = std::plus<T>() 
)

Iterate over pairs in container, call a function on the elements, and sum results.

Template Parameters
TFloating point type. Default: double)
Parameters
beginBegin iterator
endEnd iterator
fFunction to apply to the pair
aggregatorFunction to aggregate the result from each pair. Default: std::plus<T>

◆ from_json()

void Faunus::from_json ( const json j,
std::vector< AtomData > &  atom_vector 
)

Construct vector of atoms from json array.

Items are added to existing items while if an item already exists, it will be overwritten.

◆ get_optional()

template<typename T >
std::optional<T> Faunus::get_optional ( const json j,
std::string_view  key 
)

Extract JSON value associated with key into std::optional

If the value does not exist, return std::nullopt

Exceptions
Ifvalue exists but cannot be extracted as T.

◆ inv_sqrt()

template<typename float_t = double, char iterations = 1>
float_t Faunus::inv_sqrt ( float_t  x)
inline

Fast inverse square-root approximation.

This is Carmack et al's "magic" inverse square root routine, modified to work with both double and float and with one (less precise) or two (more precise) iterations. Conditionals and sanity checks are evaluated at compile time.

Template Parameters
float_tFloating point type (float or double)
iterationsNumber of iterations (1 or 2)
Parameters
xvalue to operate on
Returns
Approximate inverse square root of x
Remarks
Code comments supposedly from the original Quake III Arena code
See also
https://en.wikipedia.org/wiki/Fast_inverse_square_root

◆ joinToString()

template<std::ranges::range Range>
std::string Faunus::joinToString ( const Range &  values)

Convert range of values into space separated string.

Parameters
valuesRange (vector, set, ...) of values to convert
Returns
String with space sepatated values

◆ jsonSingleItem()

std::tuple<const std::string&, const json&> Faunus::jsonSingleItem ( const json j)

Returns a key-value pair from a JSON object which contains a single key.

JSON objects having a single key-value pair are a common pattern in JSON configuration used in Faunus. This function provides a convenient way to handle it.

Parameters
jJSON object
Returns
tuple [key as a string, value as a JSON]
Exceptions
std::runtime_errorwhen not a JSON object or the object is empty or the object contains more than a single value

◆ loadStructure()

ParticleVector Faunus::loadStructure ( std::string_view  filename,
bool  prefer_charges_from_file = true 
)

Load structure file into particle vector.

Parameters
filenamefilename to load (aam, pqr, xyz, gro)
prefer_charges_from_fileif true, ignore AtomData charges
Exceptions
Throwsexception if nothing was loaded or if unknown suffix
Returns
particles destination particle vector (will be overwritten)

◆ monopoleMoment()

template<std::forward_iterator Titer>
double Faunus::monopoleMoment ( Titer  begin,
Titer  end 
)

Returns the total charge for a set of particles.

Parameters
beginFirst particle
endLast particleCalculates dipole moment vector for a set of particles

◆ mu2mu()

template<class Tvec >
double Faunus::mu2mu ( const Tvec &  muA,
const Tvec &  muB,
double  muAxmuB,
const Tvec &  r,
double  a = 1.0,
double  b = 0.0 
)

Returns dipole-dipole interaction.

Parameters
muAUnit dipole moment vector of particle A
muBUnit dipole moment vector of particle B
muAxmuBProduct of dipole scalars
rDirection \( r_A - r_B \)

◆ names2ids()

template<RequireNamedElements T>
auto Faunus::names2ids ( const T database,
const std::vector< std::string > &  names 
)

Search for name in database and return id()

Template Parameters
TContainer of object having .name and .id() data members
Parameters
databaseIterable range having .name and .id() members
namesContainer with names to convert to id
Exceptions
ifnames not found
Returns
Vector of ids matching names

This is typically used with Faunus::atoms or Faunus::molecules to lookup atom or molecule names and return them as id numbers. If the string * occurs in names, the returned vector will be a sequence containing all id's of the database, i.e. 0, ..., database.size()-1.

◆ NLOHMANN_JSON_SERIALIZE_ENUM()

Faunus::NLOHMANN_JSON_SERIALIZE_ENUM ( SpheroCylinderData::PatchType  ,
{{SpheroCylinderData::PatchType::Invalid, nullptr}, {SpheroCylinderData::PatchType::Full, "full"}, {SpheroCylinderData::PatchType::Capped, "capped"}, {SpheroCylinderData::PatchType::None, "none"}}   
)

General properties for atoms.

< Unsigned int used for atom id and atom indexing

< Name

< Particle charge [e]

< Weight

< Diameter for e.g Lennard-Jones etc. [angstrom] Do not set! Only a temporal class member during the refactorization

< Chemical activity [mol/l]

< Excess polarisability (unit-less)

< Translational displacement parameter [angstrom]

< Rotational displacement parameter [degrees]

< Surface tension [kT/Å^2]

< Transfer free energy [J/mol/angstrom^2/M]

< Dipole moment unit vector

< Dipole moment length

< Is the particle hydrophobic?

< Is the particle implicit (e.g. proton)?

< Atomic scattering form factor (q-independent)

< Arbitrary interaction parameters, e.g., epsilons in various potentials

< Data for patchy sphero cylinders (PSCs)

< Type id

< Type id

◆ numeric_cast()

template<std::integral TOut, std::floating_point TIn>
TOut Faunus::numeric_cast ( const TIn  number)
inline

Convert floating point number to integral number.

Perform range check and rounding.

Template Parameters
TOutintegral type
TInfloating point type
Parameters
number(floating point type)
Returns
number (integral type)
Exceptions
std::overflow_error

◆ parseMolecules()

std::vector< MoleculeData::index_type > Faunus::parseMolecules ( const json j)
Parameters
jJson object with a molecules list of strings
Returns
vector of corresponding molecule ids (sorted)
Exceptions
ifunknown molecule name or not a list of strings

◆ parseReactionString()

std::pair< std::vector< std::string >, std::vector< std::string > > Faunus::parseReactionString ( const std::string &  process_string)

This parses a string containing a reaction, e.g.

Parameters
process_stringReaction such as "A + B = C"
Returns
Pair with reactants (first) and products (second) as atomic or molecule names
Exceptions
std::runtime_errorif unknown atom or molecule, or syntax error

"A = B + B" and returns a pair with (1) a vector of reactant names and (2) a vector of product names. Reactants and products are split by a = sign. All elements in the string must be separated by a white-space.

◆ powi()

template<class T >
constexpr T Faunus::powi ( T  x,
unsigned int  n 
)
inline

◆ q2mu()

template<class Tvec >
double Faunus::q2mu ( double  QBxMuA,
const Tvec &  muA,
double  QAxMuB,
const Tvec &  muB,
const Tvec &  r 
)

Returns ion-dipole interaction.

Parameters
QBxMuAProduct of ion B:s charge and dipole A:s scalar
muAUnit dipole moment vector of particel A
QAxMuBProduct of ion A:s charge and dipole B:s scalar
muBUnit dipole moment vector of particel B
rDirection \( r_A - r_B \)

◆ q2quad()

template<class Tvec , class Tmat >
double Faunus::q2quad ( double  qA,
const Tmat &  quadB,
double  qB,
const Tmat &  quadA,
const Tvec &  r 
)

Returns ion-quadrupole interaction.

Parameters
qACharge of particle A
quadBQuadrupole moment of particle B
qBCharge of particle B
quadAQuadrupole moment of particle A
rDirection \( r_A - r_B \)

◆ quadrupoleMoment()

template<std::forward_iterator Titer, class BoundaryFunction >
Tensor Faunus::quadrupoleMoment ( Titer  begin,
Titer  end,
BoundaryFunction  boundary = [](const Point&) {},
Point  origin = {0, 0, 0},
double  cutoff = pc::infty 
)

Returns the total quadrupole-moment for a set of particles, note with trace!

Parameters
beginFirst particle
endLast particle
boundaryFunction to use for boundary
originOrigin for quadrupole-moment, default (0,0,0)
cutoffCut-off for included particles with regard to origin, default value is infiniteCalculates quadrupole moment tensor (with trace)

◆ rtp2xyz()

Point Faunus::rtp2xyz ( const Point rtp,
const Point origin = {0, 0, 0} 
)

Convert spherical- to cartesian-coordinates.

Parameters
originThe origin to be added (optional)
Note
Input \( (r,\theta,\phi) \) where \( r\in [0,\infty) \), \( \theta\in [0,2\pi) \), and \( \phi\in [0,\pi] \), and output (x,y,z).

◆ splitConvert()

template<StringStreamable T>
auto Faunus::splitConvert ( const std::string &  words)

Convert space separated words into vector of type T.

Example:

textio::splitConvert<double>("0.2 1 100"); // -> {0.2, 1.0, 100.0}
Returns
std::vector of type T

◆ streamMarket()

template<typename SparseMatrixType >
bool Faunus::streamMarket ( const SparseMatrixType &  mat,
std::ostream &  out,
bool  symmetric = false 
)

Save Matrix Market sparse matrix.

Note
File format description: https://math.nist.gov/MatrixMarket/formats.html
Parameters
matSparse matrix
outOutput stream
symmetricSet to true if symmetric matrix (half storage)

Mainly copied from Eigen's unsupported SparseExtra/MarketIO.h

Warning
Untested for symmetric matrices with non-zero diagonal

◆ to_bin()

template<std::floating_point T, std::integral Tint = int>
Tint Faunus::to_bin ( T  x,
T  dx = 1 
)

Round a floating point to integer for use with histogram binning.

This will round to nearest integer, assuming a certain resolution (default 1). This can be useful for binning floating point data into a histogram or table of resolution dx (second argument).

Example:

double x=21.3;
to_bin(x); // -> 21
to_bin(x,2); // -> 11
to_bin(x,0.5); // -> 43

◆ to_json()

void Faunus::to_json ( json j,
const Group group 
)
Parameters
maskBitmask based on enum Group::Selectors
Returns
Lambda function that returns true if group matches mask
auto filter = Group::getSelectionFilter(Select::ACTIVE | Select::NEUTRAL);
bool b = filter(mygroup); // true if mygroup is active and uncharged

◆ toMultipole()

template<class Tgroup , class BoundaryFunction >
auto Faunus::toMultipole ( const Tgroup &  g,
BoundaryFunction  boundary = [](const Point&) {},
double  cutoff = pc::infty 
)

Converts a group to a multipole-particle.

Parameters
gGroup
boundaryFunction to use for boundary
cutoffCut-off for included particles with regard to origin, default value is infinite

◆ xyz2rth()

Point Faunus::xyz2rth ( const Point ,
const Point origin = {0, 0, 0},
const Point dir = {0, 0, 1},
const Point dir2 = {1, 0, 0} 
)

Convert cartesian- to cylindrical-coordinates.

Note
Input (x,y,z), output \( (r,\theta, h) \) where \( r\in [0,\infty) \), \( \theta\in [-\pi,\pi) \), and \( h\in (-\infty,\infty] \).

◆ xyz2rtp()

Point Faunus::xyz2rtp ( const Point ,
const Point origin = {0, 0, 0} 
)

Convert cartesian- to spherical-coordinates.

Note
Input (x,y,z), output \( (r,\theta,\phi) \) where \( r\in [0,\infty) \), \( \theta\in [-\pi,\pi) \), and \( \phi\in [0,\pi] \).

Variable Documentation

◆ Averageable

template<class T >
concept Faunus::Averageable
Initial value:
= requires(T a) {
a * 1.0;
a += a;
}

Requirements for types used with AverageObj

◆ RequireGroups

template<typename T >
concept Faunus::RequireGroups
Initial value:
=
std::ranges::range<T> && std::is_convertible_v<std::ranges::range_value_t<T>, Group>

Concept for a range of groups.

◆ RequireNamedElements

template<typename T >
concept Faunus::RequireNamedElements
Initial value:
= requires(T db) {
{ db.begin() };
{ db.begin()->name } -> std::convertible_to<std::string>;
{ std::is_integral_v<typename std::ranges::range_value_t<T>::index_type> };
}

Concept for named database such as vector<AtomData>, vector<MoleculeData> etc.

◆ RequireParticles

template<class T >
concept Faunus::RequireParticles
Initial value:
=
std::ranges::range<T> && std::is_convertible_v<std::ranges::range_value_t<T>, Particle>

Concept for a range of particles.

◆ RequirePoints

template<class T >
concept Faunus::RequirePoints
Initial value:
=
std::ranges::range<T> && std::is_same_v<std::ranges::range_value_t<T>, Point>
Eigen::Vector3d Point
3D vector used for positions, velocities, forces etc.
Definition: coordinates.h:7

Concept for a range of points.

◆ StringStreamable

template<class T >
concept Faunus::StringStreamable
Initial value:
= requires(T a) {
{ std::istringstream() >> a };
{ std::ostringstream() << a };
}