6 #include "reactioncoordinate.h" 7 #include "aux/timers.h" 8 #include "aux/table_2d.h" 9 #include "aux/equidistant_table.h" 10 #include "aux/sparsehistogram.h" 11 #include <Eigen/SparseCore> 15 #include <string_view> 54 virtual void _to_json(
json&)
const;
55 virtual void _from_json(
const json&);
56 virtual void _sample() = 0;
57 virtual void _to_disk();
58 int number_of_steps = 0;
59 int number_of_skipped_steps = 0;
64 int sample_interval = 0;
65 int number_of_samples = 0;
70 void to_json(
json& j)
const;
71 void from_json(
const json& j);
74 [[nodiscard]]
int getNumberOfSteps()
const;
76 Analysis(
const Space& spc, std::string_view name,
int sample_interval,
77 int number_of_skipped_steps);
124 void _to_disk()
override;
130 std::unique_ptr<std::ostream> stream =
nullptr;
133 bool collectWidomAverage(
double energy_change);
135 const std::string& filename =
""s);
137 meanFreeEnergy()
const;
147 const std::string filename;
148 std::unique_ptr<std::ostream> stream =
nullptr;
149 const std::unique_ptr<ReactionCoordinate::ReactionCoordinateBase> reaction_coordinate;
151 void _to_json(
json& j)
const override;
152 void _sample()
override;
153 void _to_disk()
override;
155 const Space& spc,
const std::string& filename,
156 std::unique_ptr<ReactionCoordinate::ReactionCoordinateBase> reaction_coordinate);
175 MoleculeData::index_type molid;
179 std::unique_ptr<std::ostream>
180 single_position_stream;
181 std::vector<Point> reference_positions;
182 std::vector<Point> previous_positions;
183 std::vector<Eigen::Vector3i> cell_indices;
184 std::vector<average_type>
185 mean_squared_displacement;
186 double max_possible_displacement;
190 std::string displacement_histogram_filename;
191 int reference_reset_interval =
192 std::numeric_limits<int>::max();
195 getPositions()
const;
196 void resetReferencePosition(
const Point& position,
198 Point getOffset(
const Point& diff, Eigen::Vector3i& cell)
const;
199 void sampleDisplacementFromReference(
const Point& position,
int index);
200 void _sample()
override;
201 void _to_json(
json& j)
const override;
202 void _to_disk()
override;
217 getPositions()
const override;
220 std::string_view name =
"displacement_com");
230 std::shared_ptr<MoleculeInserter> inserter;
231 int number_of_insertions;
232 MoleculeData::index_type molid;
233 bool absolute_z_coords =
false;
235 void selectGhostGroup();
237 void _sample()
override;
238 void _to_json(
json& j)
const override;
239 void _from_json(
const json& j)
override;
251 std::unique_ptr<pairpotential::NewCoulombGalore>
254 std::string filename;
255 std::pair<double, double> range;
257 unsigned int calculations_per_sample_event = 1;
258 void _to_json(
json& j)
const override;
259 void _sample()
override;
260 void _to_disk()
override;
276 RANDOM_WALK_NO_OVERLAP,
281 unsigned int max_overlap_trials = 100;
282 double histogram_resolution = 0.01;
283 unsigned int calculations_per_sample_event = 1;
284 std::string file_prefix;
290 std::unique_ptr<SparseHistogram<double>>
294 std::vector<Target> targets;
296 std::unique_ptr<pairpotential::NewCoulombGalore>
299 mean_potential_correlation;
301 potential_correlation_histogram;
302 void getTargets(
const json& j);
303 void setPolicy(
const json& j);
305 calcPotentialOnTarget(
const Target& target);
306 [[nodiscard]]
bool overlapWithParticles(
307 const Point& position)
const;
308 std::function<void()> applyPolicy;
309 json output_information;
310 void _to_json(
json& j)
const override;
311 void _sample()
override;
312 void _to_disk()
override;
320 {ElectricPotential::Policies::INVALID,
nullptr},
321 {ElectricPotential::Policies::FIXED,
"fixed"},
322 {ElectricPotential::Policies::RANDOM_WALK_NO_OVERLAP,
324 {ElectricPotential::Policies::RANDOM_WALK,
"random_walk"},
337 std::vector<std::string> names;
338 std::set<AtomData::index_type> atom_id_selection;
340 Point origin = {0.0, 0.0, 0.0};
341 Eigen::Vector3i dir = {1, 1, 1};
342 bool count_charge =
false;
343 int center_of_mass_atom_id = -1;
345 [[nodiscard]]
double distanceToOrigin(
const Point& position)
const;
346 void _from_json(
const json& j)
override;
347 void _to_json(
json& j)
const override;
348 void _to_disk()
override;
349 void _sample()
override;
352 AtomProfile(
const json& j,
const Space& spc);
362 std::vector<std::string> atom_names;
363 std::vector<AtomData::index_type> atom_ids;
365 int center_of_mass_atom_id = -1;
367 void _from_json(
const json& j)
override;
368 void _to_json(
json& j)
const override;
369 void _sample()
override;
370 void _to_disk()
override;
383 using id_type = size_t;
384 std::map<id_type, Average<double>> mean_density;
385 std::map<id_type, std::string_view> names;
386 void _to_disk()
override;
387 void _sample()
override;
388 void _to_json(
json& j)
const override;
389 static void writeTable(std::string_view name,
Table&
table);
392 [[nodiscard]]
virtual std::map<id_type, int> count()
const = 0;
393 std::map<MoleculeData::index_type, Table> probability_density;
397 double updateVolumeStatistics();
400 template <RequireNamedElements Range>
401 Density(
const Space& spc,
const Range& atoms_or_molecules,
const std::string_view name)
404 for (
const auto& data : atoms_or_molecules) {
405 names[data.id()] = data.name;
406 probability_density[data.id()].setResolution(1, 0);
417 [[nodiscard]] std::map<id_type, int> count()
const override;
429 std::map<id_type, Table> atomswap_probability_density;
430 void _sample()
override;
431 void _to_disk()
override;
432 [[nodiscard]] std::map<id_type, int> count()
const override;
444 std::function<double(const Group&, const Group&)>
448 bool throw_on_error);
462 std::unique_ptr<std::ostream> matrix_stream;
463 std::string filename;
464 virtual void setPairMatrix() = 0;
465 void _to_json(
json& j)
const override;
466 void _from_json(
const json& j)
override;
467 void _sample()
override;
468 void _to_disk()
override;
488 std::function<double(const Group&, const Group&)>
490 std::vector<int> group_indices;
491 void setPairMatrix()
override;
503 using AtomHistogram = std::map<AtomData::index_type, int>;
504 std::vector<AtomHistogram> atom_histograms;
505 std::vector<AverageStdev<double>> atom_mean_charges;
506 std::string filename;
510 [[nodiscard]] std::vector<double> getMeanCharges()
const;
511 [[nodiscard]] std::vector<double> getChargeStandardDeviation()
const;
512 [[nodiscard]] std::vector<std::string> getPredominantParticleNames()
const;
514 void _sample()
override;
515 void _to_json(
json& j)
const override;
516 void _to_disk()
override;
535 std::map<MoleculeData::index_type, Data>
537 void _sample()
override;
538 void _to_json(
json& j)
const override;
551 std::string file_name;
552 std::string separator;
553 std::unique_ptr<std::ostream> output_stream;
554 [[nodiscard]] std::vector<double> calculateEnergies()
const;
558 double initial_energy = 0.0;
559 double minimum_energy = std::numeric_limits<double>::infinity();
560 bool dump_minimum_energy_configuration =
false;
562 bool updateMinimumEnergy(
double current_energy);
563 void createOutputStream();
564 [[maybe_unused]]
void normalize();
565 void _sample()
override;
566 void _to_json(
json& j)
const override;
567 void _from_json(
const json& j)
override;
568 void _to_disk()
override;
580 const double mass_center_tolerance = 1.0e-3;
581 void _sample()
override;
582 void checkGroupsCoverParticles();
585 void checkWithinContainer(
607 std::function<void(const std::string&)> writeFunc =
nullptr;
608 bool save_random_number_generator_state =
false;
609 bool use_numbered_files =
true;
610 bool convert_hexagonal_prism_to_cuboid =
false;
611 std::string filename;
613 void _to_json(
json& j)
const override;
614 void _sample()
override;
615 static void saveAsCuboid(
const std::string& filename,
const Space& spc,
617 void saveJsonStateFile(
const std::string& filename,
const Space& spc)
const;
618 void saveBinaryJsonStateFile(
const std::string& filename,
const Space& spc)
const;
623 void setWriteFunction(
const Space& spc);
632 using index_type = size_t;
642 Eigen::Vector3i slicedir = {0, 0, 0};
643 double thickness = 0;
646 void _from_json(
const json& j)
override;
647 void _to_json(
json& j)
const override;
648 void _to_disk()
override;
649 [[nodiscard]]
double volumeElement(
double r)
const;
661 void _sample()
override;
663 void sampleDifferent();
664 void sampleIdentical();
676 void _sample()
override;
677 void sampleDistance(
const Group& group_i,
const Group& group_j);
678 void sampleDifferent();
679 void sampleIdentical();
691 std::string correlation_filename;
697 void _from_json(
const json& j)
override;
698 void _to_disk()
override;
707 void _sample()
override;
723 using index_type = MoleculeData::index_type;
724 std::vector<index_type> group_ids;
725 std::vector<std::size_t> group_indices;
726 std::unique_ptr<XTCWriter> writer;
727 void _to_json(
json& j)
const override;
728 void _sample()
override;
730 const std::vector<std::string>& molecule_names);
742 double volume_displacement = 0.0;
743 void _sample()
override;
744 void _from_json(
const json& j)
override;
745 void _to_json(
json& j)
const override;
746 void sanityCheck(
double old_energy);
747 void writeToFileStream(
const Point& scale,
double energy_change)
const;
758 MoleculeData::index_type molid;
759 std::map<int, unsigned int> histogram;
760 void _sample()
override;
761 void _to_json(
json& j)
const override;
778 MoleculeData::index_type molid;
779 Point perturbation_direction = {0.0, 0.0, 1.0};
780 double perturbation_distance = 0.0;
782 void _sample()
override;
783 void _from_json(
const json& j)
override;
784 void _to_json(
json& j)
const override;
786 void writeToFileStream(
double energy_change)
const;
803 average_type ion_ion;
804 average_type ion_dipole;
805 average_type ion_quadrupole;
806 average_type dipole_dipole;
807 average_type dipole_dipole_correlation;
810 std::map<MoleculeData::index_type, Data> mean_energy;
811 std::vector<std::string> names;
812 std::vector<MoleculeData::index_type> ids;
813 std::string filename;
816 void _sample()
override;
817 void _to_json(
json& j)
const override;
818 void _to_disk()
override;
820 [[nodiscard]]
double groupGroupExactEnergy(
840 Schemes scheme = Schemes::DEBYE;
841 bool mass_center_scattering;
842 bool save_after_sample =
false;
843 std::string filename;
844 std::vector<Scatter::Scatterer> scatter_positions;
845 std::vector<MoleculeData::index_type> molecule_ids;
846 std::vector<std::string> molecule_names;
849 std::unique_ptr<Scatter::DebyeFormula<Tformfactor>> debye;
850 std::unique_ptr<Scatter::StructureFactorPBC<Tformfactor>> explicit_average_pbc;
851 std::unique_ptr<Scatter::StructureFactorIPBC<Tformfactor, float>> explicit_average_ipbc;
852 void _sample()
override;
853 void _to_disk()
override;
854 void _to_json(
json& j)
const override;
866 std::string filename;
867 AtomData::index_type atom_id;
868 std::ofstream output_stream;
871 void _to_json(
json& j)
const override;
872 void _sample()
override;
873 void _to_disk()
override;
886 std::string filename;
887 std::unique_ptr<std::ostream> stream;
888 MoleculeData::index_type group_index;
889 std::vector<size_t> particle_range;
890 [[nodiscard]] std::pair<Point, Point>
892 void _to_json(
json& j)
const override;
893 void _sample()
override;
894 void _to_disk()
override;
907 std::string filename;
908 std::vector<AtomData::index_type> particle_range;
909 MoleculeData::index_type group_index;
910 bool use_molecular_mass_center =
912 std::ofstream output_stream;
917 Point dipole_moment{0.0, 0.0, 0.0};
918 Point eivals, eivec, center;
919 } __attribute__((aligned(128)));
921 Data calculateMultipoleMoment()
const;
922 void _to_json(
json& j)
const override;
923 void _sample()
override;
924 void _to_disk()
override;
945 average_type gyration_radius_squared;
946 average_type gyration_radius;
947 average_type end_to_end_squared;
948 average_type shape_factor_squared;
949 average_type aspherity;
950 average_type acylindricity;
951 average_type relative_shape_anisotropy;
955 MoleculeData::index_type molid;
956 std::unique_ptr<std::ostream> tensor_output_stream =
nullptr;
959 void _to_json(
json& j)
const override;
960 void _sample()
override;
961 void _to_disk()
override;
978 std::unique_ptr<std::ostream> stream =
nullptr;
981 std::string filename;
982 void _sample()
override;
983 void _to_json(
json& j)
const override;
984 void _to_disk()
override;
987 QRtraj(
const json& j,
const Space& spc,
const std::string& name =
"qrtraj");
1006 class AreaSamplingPolicy;
1016 using index_type = Faunus::AtomData::index_type;
1017 using count_type = size_t;
1034 average_type area_squared;
1037 Averages average_data;
1039 std::unique_ptr<std::ostream> output_stream;
1041 double probe_radius;
1042 int slices_per_atom;
1044 std::string filename;
1046 std::unique_ptr<Faunus::SASA::SASABase> sasa;
1047 std::unique_ptr<AreaSamplingPolicy> policy;
1049 void _to_json(
json& j)
const override;
1050 void _from_json(
const json& input)
override;
1051 void _to_disk()
override;
1052 void _sample()
override;
1054 void setPolicy(Policies);
1055 void takeSample(
double area);
1057 friend class AreaSamplingPolicy;
1061 SASAAnalysis(
double probe_radius,
int slices_per_atom,
double resolution, Policies policy,
1066 {{SASAAnalysis::Policies::ATOMIC,
"atomic"},
1067 {SASAAnalysis::Policies::MOLECULAR,
"molecular"},
1068 {SASAAnalysis::Policies::ATOMS_IN_MOLECULE,
"atoms_in_molecule"},
1069 {SASAAnalysis::Policies::INVALID,
nullptr}})
1072 class AreaSamplingPolicy
1075 template <
typename TBegin,
typename TEnd>
1076 void sampleIndividualSASA(TBegin first, TEnd last,
SASAAnalysis& analysis);
1077 template <
typename TBegin,
typename TEnd>
1078 void sampleTotalSASA(TBegin first, TEnd last,
SASAAnalysis& analysis);
1082 virtual void to_json(
json& input)
const = 0;
1083 virtual void from_json(
const json& input) = 0;
1085 inline AreaSamplingPolicy() =
default;
1086 inline virtual ~AreaSamplingPolicy() =
default;
1093 AtomData::index_type atom_id;
1094 std::string atom_name;
1097 void to_json(
json& input)
const override;
1098 void from_json(
const json& input)
override;
1108 MoleculeData::index_type molecule_id;
1109 std::string molecule_name;
1112 void to_json(
json& input)
const override;
1113 void from_json(
const json& input)
override;
1127 MoleculeData::index_type molecule_id;
1128 std::set<size_t> selected_indices;
1129 std::string molecule_name;
1130 std::set<std::string> atom_names;
1133 void to_json(
json& input)
const override;
1134 void from_json(
const json& input)
override;
1141 template <
class T,
class Enable =
void>
struct [[maybe_unused]]
_analyse 1143 void sample(
T&) { std::cout <<
"not a dipole!" << std::endl; }
1149 typename std::enable_if<std::is_base_of<Dipole, T>::value>::type>
1151 void sample(
T&) { std::cout <<
"dipole!" << std::endl; }
1157 const std::string filename;
1159 std::shared_ptr<Energy::Penalty> penalty_energy;
1160 void _sample()
override;
1193 Modes mode = Modes::FULL;
1194 double probe_radius;
1195 bool use_pbc =
false;
1196 Averages average_data;
1197 std::unique_ptr<std::ostream> output_stream;
1198 std::string filename;
1201 std::unique_ptr<Impl> pimpl;
1203 void _to_json(
json& json_output)
const override;
1204 void _from_json(
const json& input)
override;
1205 void _to_disk()
override;
1206 void _sample()
override;
1210 Voronota(Modes mode,
double probe_radius,
const Space& spc);
Virtual translation move to calculate force.
Definition: analysis.h:776
SASA sampling policy which samples as a whole atom in a selected molecule if multiple atoms are selec...
Definition: analysis.h:1124
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
Base class for distribution functions etc.
Definition: analysis.h:629
Average< double > mean_exponentiated_energy_change
< exp(-du/kT) >
Definition: analysis.h:132
void sample(T &)
Sample.
Definition: analysis.h:1151
std::unique_ptr< Analysis > createAnalysis(const std::string &name, const json &j, Space &spc, Energy::Hamiltonian &pot)
Factory function for generating analysis based on name.
Definition: analysis.cpp:153
Definition: voronota.cpp:46
std::function< bool(double)> createValueFilter(const std::string &name, const json &j, bool throw_on_error)
Generate lambda to filter values.
Definition: analysis.cpp:476
Eigen::SparseMatrix< double > pair_matrix
Matrix of pair properties.
Definition: analysis.h:473
std::vector< Point > PointVector
Vector of 3D vectors.
Definition: core.h:24
Save system energy to disk.
Definition: analysis.h:547
double T
floating point size
Definition: units.h:73
Equidistant2DTable< double, double > histogram
distance histogram
Definition: analysis.h:640
Base class for all analysis functions.
Definition: analysis.h:51
Base class to writeKeyValuePairs simple structure files such as XYZ, AAM, PQR etc.
Definition: io.h:208
Same as AtomRDF but for molecules.
Definition: analysis.h:673
Example analysis.
Definition: analysis.h:1141
Space & mutable_space
This reference to space can be changed.
Definition: analysis.h:127
Analysis of single atom densities.
Definition: analysis.h:426
std::string file
output filename
Definition: analysis.h:639
Abstract base class for analysing atomic and molecular densities.
Definition: analysis.h:379
Samples the electric potential at arbitrary positions in the simulation box.
Definition: analysis.h:269
std::string filename
output filename (optional)
Definition: analysis.h:129
std::function< void()> write_to_file
Write a single frame to stream.
Definition: analysis.h:977
Definition: analysis.h:499
Analysis of molecular group densities.
Definition: analysis.h:414
Tracks displacements of molecular group mass centers.
Definition: analysis.h:213
Excess pressure using virtual volume move.
Definition: analysis.h:739
Atomic radial distribution function, g(r)
Definition: analysis.h:658
Definition: equidistant_table.h:25
std::vector< Particle > ParticleVector
Storage type for collections of particles.
Definition: particle.h:253
Write XTC trajectory file.
Definition: analysis.h:720
Definition: analysis.h:904
Sample scattering intensity.
Definition: analysis.h:831
Definition: analysis.h:1154
std::string name2
atom or molecule name
Definition: analysis.h:638
Particle class for storing positions, id, and other properties.
Definition: particle.h:220
Excess chemical potential of molecules.
Definition: analysis.h:228
Samples the electric potential correlation as a function of distance, < Φ₁Φ₂>="">(r) ...
Definition: analysis.h:248
Trajectory with charge and radius, only, for all (active, inactive) particles.
Definition: analysis.h:974
Base class for streaming pair properties to a sparse matrix.
Definition: analysis.h:459
Adding a new analysis requires the following steps:
Definition: analysis.cpp:36
End of Group class.
Definition: group.h:177
Change change
Change object to describe perturbation.
Definition: analysis.h:131
Namespace for particle pair-potentials.
Definition: analysis.h:18
Dipole-dipole correlation function, <{}(0){}(r)>
Definition: analysis.h:705
Aggregate and sum energy terms.
Definition: energy.h:1954
Definition: analysis.h:863
std::function< bool(double)> value_filter
Used to filter values generated by property
Definition: analysis.h:472
Definition: analysis.h:28
All energies inherit from this class.
Definition: externalpotential.h:21
Definition: analysis.h:688
const std::string name
descriptive name
Definition: analysis.h:68
Molecular multipole moments and their fluctuations.
Definition: analysis.h:525
SASA sampling policy which samples individually atoms selected by atom type name. ...
Definition: analysis.h:1090
Analysis of Vorononoi tessellation using the Voronota-LT library.
Definition: analysis.h:1173
SASA sampling policy which samples individually molecules selected by molecules name.
Definition: analysis.h:1105
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.
Definition: atomdata.h:61
Aggregator class for storing and selecting multiple analysis instances.
Definition: analysis.h:104
std::vector< MoleculeData > molecules
List of molecule types.
Definition: molecule.cpp:22
Specify changes made to a system.
Definition: space.h:29
Sample and save the eigenvalues of the inertia tensor for a range of indexes within a molecule...
Definition: analysis.h:883
std::function< double(const Group &, const Group &)> createGroupGroupProperty(const json &j, const Space &spc, Energy::Hamiltonian &hamiltonian)
Generates lambda to calculate properties between groups.
Definition: analysis.h:445
std::string cite
url, doi etc. describing the analysis
Definition: analysis.h:69
Checks if system is sane.
Definition: analysis.h:577
std::string name1
atom or molecule
Definition: analysis.h:637
Samples a matrix of group properties.
Definition: analysis.h:485
Placeholder for atoms and molecules.
Definition: space.h:92
Density of atom along axis.
Definition: analysis.h:358
Wrapper for external CoulombGalore library.
Definition: potentials.h:581
Helper class for storing vectors of base pointers.
Definition: auxiliary.h:237
Average< double > mean_volume
average volume (angstrom^3)
Definition: analysis.h:641
Save simulation state and particle coordinates to disk.
Definition: analysis.h:604
Tracks displacements of particle positions.
Definition: analysis.h:172
Analysis of polymer shape - radius of gyration, shape etc.
Definition: analysis.h:940
void sample(T &)
Sample.
Definition: analysis.h:1143
Multipolar decomposition between groups as a function of separation.
Definition: analysis.h:797
Generate PSCs text trajectory containing.
Definition: analysis.h:1000
const Space & spc
Instance of Space to analyse.
Definition: analysis.h:63
Sample and save reaction coordinates to a file.
Definition: analysis.h:143
Analysis class for sasa calculations.
Definition: analysis.h:1014
VolumeMethod
Various methods of volume scaling,.
Definition: geometry.h:52
Base class for perturbation analysis.
Definition: analysis.h:121