Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang tidy fixes #447

Merged
merged 38 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
be8c967
Clang tidy geometry
mlund Jun 16, 2024
170ddab
Clang tidy rotate.cpp
mlund Jun 16, 2024
d3a5ba7
Clang tidy group
mlund Jun 16, 2024
ff14bc3
Update clang tidy config
mlund Jun 16, 2024
f827dde
Clang tidy
mlund Jun 16, 2024
d733916
Clang tidy on move
mlund Jun 16, 2024
318c5ad
clang typy atomdata
mlund Jun 16, 2024
7586f7f
tidy analysis
mlund Jun 16, 2024
49a62d5
Tidy space
mlund Jun 16, 2024
ce78a2d
Tidy speciation
mlund Jun 16, 2024
8221b42
Tidy externalpotential
mlund Jun 16, 2024
13f4332
Tidy geometry
mlund Jun 16, 2024
4a0df35
Tidy bonds
mlund Jun 16, 2024
da5ef92
Tidy units
mlund Jun 16, 2024
e81e218
Tidy SASA
mlund Jun 16, 2024
c047955
Tidy energy
mlund Jun 16, 2024
be5042c
Tidy moleculedata
mlund Jun 16, 2024
9d034cb
Tidy potentials
mlund Jun 16, 2024
c506c08
Tidy regions
mlund Jun 16, 2024
faeadc1
Tidy aux/ partial
mlund Jun 16, 2024
679b46a
Tidy auxiliary
mlund Jun 16, 2024
75344f4
Tidy cellist
mlund Jun 16, 2024
3a3d010
Tidy core
mlund Jun 16, 2024
dc5f383
Tidy particle (test only)
mlund Jun 16, 2024
6c2dca1
Tidy io (test only)
mlund Jun 16, 2024
1501171
Tidy random
mlund Jun 16, 2024
98b027a
Clang tidy update
mlund Jun 16, 2024
4212e7d
Tidy average
mlund Jun 16, 2024
1bc2445
Tidy scatter
mlund Jun 16, 2024
5d9a143
Tidy penalty
mlund Jun 16, 2024
56975d4
Fix openmp in scatter after tidying
mlund Jun 16, 2024
ac8bbb4
Tidy reactioncoordinate
mlund Jun 16, 2024
0a893b6
Tidy smart mc
mlund Jun 16, 2024
2759956
Tidy SPC
mlund Jun 16, 2024
1fadcb1
Tidy tensor
mlund Jun 16, 2024
e82cc88
Tidy force move
mlund Jun 16, 2024
4f08d2a
Tidy main faunus
mlund Jun 16, 2024
a578325
Tidy chainmove
mlund Jun 16, 2024
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
3 changes: 2 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Checks: '*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm-*,-modernize-use-nodiscard,-llvmlibc-callee-namespace,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers'
WarningsAsErrors: '*'
HeaderFilterRegex: ''
FormatStyle: none
FormatStyle: file
MinimumVariableNameLength: 1

CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: CamelCase }
Expand Down
10 changes: 10 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <zstr.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/archives/binary.hpp>
#include <range/v3/numeric/accumulate.hpp>
#include <range/v3/view/zip.hpp>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -236,7 +235,7 @@ CombinedAnalysis::CombinedAnalysis(const json& json_array, Space& spc, Energy::H
}
}

void SystemEnergy::normalize() {
[[maybe_unused]] void SystemEnergy::normalize() {
const auto sum = energy_histogram.sumy();
for (auto& i : energy_histogram.getMap()) {
i.second = i.second / sum;
Expand Down Expand Up @@ -1557,7 +1556,7 @@ void MultipoleDistribution::_to_disk() {
if (number_of_samples == 0) {
return;
}
if (std::ofstream stream(MPI::prefix + filename.c_str()); stream) {
if (std::ofstream stream(MPI::prefix + filename); stream) {
stream << "# Multipolar energies (kT/lB)\n"
<< fmt::format("# {:>8}{:>10}{:>10}{:>10}{:>10}{:>10}{:>10}{:>10}\n", "R", "exact", "tot", "ii", "id",
"dd", "iq", "mucorr");
Expand Down Expand Up @@ -2014,7 +2013,7 @@ void AtomsInMoleculePolicy::to_json(json& output) const {
}

void AtomsInMoleculePolicy::from_json(const json& input) {
if (const auto atomlist = input.at("atomlist"); !atomlist.empty()) {
if (const auto& atomlist = input.at("atomlist"); !atomlist.empty()) {
for (const auto& atom_specifier : atomlist) {
if (atom_specifier.is_string()) {
atom_names.insert(static_cast<const std::string>(atom_specifier));
Expand Down
64 changes: 32 additions & 32 deletions src/analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Faunus::SASA {
class SASABase;
}

namespace Faunus {

/**
* Adding a new analysis requires the following steps:
*
Expand All @@ -45,7 +45,7 @@ namespace Faunus {
* 3. Recommended: add the required json input format to `docs/schema.yml`
* 4. Recommended: add documentation to `docs/_docs/analysis.md`
*/
namespace analysis {
namespace Faunus::analysis {

/**
* @brief Base class for all analysis functions
Expand Down Expand Up @@ -78,7 +78,7 @@ class Analysis {
void from_json(const json& j); //!< configure from json object
void to_disk(); //!< Save data to disk (if defined)
void sample(); //!< Increase step count and sample
int getNumberOfSteps() const; //!< Number of steps
[[nodiscard]] int getNumberOfSteps() const; //!< Number of steps
Analysis(const Space& spc, std::string_view name);
Analysis(const Space& spc, std::string_view name, int sample_interval, int number_of_skipped_steps);
virtual ~Analysis() = default;
Expand Down Expand Up @@ -135,7 +135,7 @@ class PerturbationAnalysis : public Analysis {
bool collectWidomAverage(double energy_change); //!< add to exp(-du/kT) incl. safety checks
PerturbationAnalysis(const std::string& name, Energy::EnergyTerm& pot, Space& spc,
const std::string& filename = ""s);
double meanFreeEnergy() const; //!< Average perturbation free energy, `-ln(<exp(-du/kT)>)`
[[nodiscard]] double meanFreeEnergy() const; //!< Average perturbation free energy, `-ln(<exp(-du/kT)>)`
};

/**
Expand Down Expand Up @@ -185,7 +185,7 @@ class AtomicDisplacement : public Analysis {
std::string displacement_histogram_filename; //!< Name of P(r) histogram file
int reference_reset_interval = std::numeric_limits<int>::max(); //!< Renew reference at given interval

virtual PointVector getPositions() const; //!< Extract current positions from `molid`
[[nodiscard]] virtual PointVector getPositions() const; //!< Extract current positions from `molid`
void resetReferencePosition(const Point& position, int index); //!< Store current positions as reference
Point getOffset(const Point& diff, Eigen::Vector3i& cell) const; //!< Offset to other cells
void sampleDisplacementFromReference(const Point& position, int index);
Expand All @@ -204,7 +204,7 @@ class AtomicDisplacement : public Analysis {
*/
class MassCenterDisplacement : public AtomicDisplacement {
private:
PointVector getPositions() const override; //!< Extracts mass centers from all active `molid` groups
[[nodiscard]] PointVector getPositions() const override; //!< Extracts mass centers from all active `molid` groups
public:
MassCenterDisplacement(const json& j, const Space& spc, std::string_view name = "displacement_com");
};
Expand Down Expand Up @@ -233,7 +233,7 @@ class WidomInsertion : public PerturbationAnalysis {
/**
* @brief Samples the electric potential correlation as a function of distance, <Φ₁Φ₂>(r)
*/
class PotentialCorrelation : public Analysis {
class [[maybe_unused]] PotentialCorrelation : public Analysis {
private:
std::unique_ptr<pairpotential::NewCoulombGalore> coulomb; //!< Class for calculating the potential
Equidistant2DTable<double, Average<double>> mean_correlation; //!< <Φ₁Φ₂>(r)
Expand Down Expand Up @@ -274,7 +274,7 @@ class ElectricPotential : public Analysis {
void getTargets(const json& j); //!< Get user defined target positions
void setPolicy(const json& j); //!< Set user defined position setting policy
double calcPotentialOnTarget(const Target& target); //!< Evaluate net potential of target position
bool overlapWithParticles(const Point& position) const; //!< Check if position is within the radius of any particle
[[nodiscard]] bool overlapWithParticles(const Point& position) const; //!< Check if position is within the radius of any particle
std::function<void()> applyPolicy; //!< Lambda for position setting policy
json output_information; //!< json output generated during construction
void _to_json(json& j) const override;
Expand Down Expand Up @@ -310,7 +310,7 @@ class AtomProfile : public Analysis {
bool count_charge = false;
int center_of_mass_atom_id = -1; // center at COM of id_com atoms?

double distanceToOrigin(const Point& position) const;
[[nodiscard]] double distanceToOrigin(const Point& position) const;
void _from_json(const json& j) override;
void _to_json(json& j) const override;
void _to_disk() override;
Expand Down Expand Up @@ -352,10 +352,10 @@ class Density : public Analysis {
void _to_disk() override;
void _sample() override;
void _to_json(json& j) const override;
void writeTable(std::string_view name, Table& table);
static void writeTable(std::string_view name, Table& table);

private:
virtual std::map<id_type, int> count() const = 0;
[[nodiscard]] virtual std::map<id_type, int> count() const = 0;
std::map<MoleculeData::index_type, Table> probability_density;
Average<double> mean_cubic_root_of_volume;
Average<double> mean_volume;
Expand All @@ -378,7 +378,7 @@ class Density : public Analysis {
*/
class MoleculeDensity final : public Density {
private:
std::map<id_type, int> count() const override;
[[nodiscard]] std::map<id_type, int> count() const override;

public:
MoleculeDensity(const json& j, const Space& spc);
Expand All @@ -392,7 +392,7 @@ class AtomDensity final : public Density {
std::map<id_type, Table> atomswap_probability_density;
void _sample() override;
void _to_disk() override;
std::map<id_type, int> count() const override;
[[nodiscard]] std::map<id_type, int> count() const override;

public:
AtomDensity(const json& j, const Space& spc);
Expand Down Expand Up @@ -465,9 +465,9 @@ class ChargeFluctuations : public Analysis {
bool verbose = true; //!< set to true for more output

ParticleVector averageChargeParticles(const Space::GroupType& group);
std::vector<double> getMeanCharges() const;
std::vector<double> getChargeStandardDeviation() const;
std::vector<std::string> getPredominantParticleNames() const;
[[nodiscard]] std::vector<double> getMeanCharges() const;
[[nodiscard]] std::vector<double> getChargeStandardDeviation() const;
[[nodiscard]] std::vector<std::string> getPredominantParticleNames() const;

void _sample() override;
void _to_json(json& j) const override;
Expand Down Expand Up @@ -505,7 +505,7 @@ class SystemEnergy : public Analysis {
std::string file_name;
std::string separator;
std::unique_ptr<std::ostream> output_stream;
std::vector<double> calculateEnergies() const;
[[nodiscard]] std::vector<double> calculateEnergies() const;
Average<double> mean_energy;
Average<double> mean_squared_energy;
Table2D<double, double> energy_histogram; // Density histograms
Expand All @@ -515,7 +515,7 @@ class SystemEnergy : public Analysis {

bool updateMinimumEnergy(double current_energy);
void createOutputStream();
void normalize();
[[maybe_unused]] void normalize();
void _sample() override;
void _to_json(json& j) const override;
void _from_json(const json& j) override;
Expand Down Expand Up @@ -594,10 +594,10 @@ class PairFunction : public Analysis {
void _from_json(const json& j) override;
void _to_json(json& j) const override;
void _to_disk() override;
double volumeElement(double r) const;
[[nodiscard]] double volumeElement(double r) const;

public:
PairFunction(const Space& spc, const json& j, const std::string_view name);
PairFunction(const Space& spc, const json& j, std::string_view name);
};

/**
Expand Down Expand Up @@ -753,7 +753,7 @@ class MultipoleDistribution : public Analysis {
void _to_json(json& j) const override;
void _to_disk() override;
void sampleGroupGroup(const Space::GroupType& group1, const Space::GroupType& group2);
double groupGroupExactEnergy(const Space::GroupType& group1,
[[nodiscard]] double groupGroupExactEnergy(const Space::GroupType& group1,
const Space::GroupType& group2) const; //<! exact ion-ion energy between particles

public:
Expand Down Expand Up @@ -813,7 +813,7 @@ class InertiaTensor : public Analysis {
std::unique_ptr<std::ostream> stream; //!< file output stream
MoleculeData::index_type group_index; //!< Group to analyse
std::vector<size_t> particle_range; //!< range of indexes within the group
std::pair<Point, Point> compute() const; //!< Compute eigen values and principal axis
[[nodiscard]] std::pair<Point, Point> compute() const; //!< Compute eigen values and principal axis
void _to_json(json& j) const override;
void _sample() override;
void _to_disk() override;
Expand Down Expand Up @@ -942,7 +942,7 @@ class SpaceTrajectory : public Analysis {
void _sample() override;
void _to_json(json& j) const override;
void _to_disk() override;
bool useCompression() const; //!< decide from filename if zlib should be used
[[nodiscard]] bool useCompression() const; //!< decide from filename if zlib should be used

public:
SpaceTrajectory(const json& j, const Space& spc);
Expand Down Expand Up @@ -981,10 +981,10 @@ class SASAAnalysis : public Analysis {
std::unique_ptr<Faunus::SASA::SASABase> sasa; //!< sasa object for calculating solute areas
std::unique_ptr<AreaSamplingPolicy> policy; //!< policy specyfing how sampling will be performed

virtual void _to_json(json& j) const override;
virtual void _from_json(const json& input) override;
virtual void _to_disk() override;
virtual void _sample() override;
void _to_json(json& j) const override;
void _from_json(const json& input) override;
void _to_disk() override;
void _sample() override;

void setPolicy(Policies);
void takeSample(double area);
Expand Down Expand Up @@ -1066,12 +1066,12 @@ class AtomsInMoleculePolicy final : public AreaSamplingPolicy {
};

/** @brief Example analysis */
template <class T, class Enable = void> struct _analyse {
template <class T, class Enable = void> struct [[maybe_unused]] _analyse {
void sample(T&) { std::cout << "not a dipole!" << std::endl; } //!< Sample
}; // primary template

/** @brief Example analysis */
template <class T> struct _analyse<T, typename std::enable_if<std::is_base_of<Dipole, T>::value>::type> {
template <class T> struct [[maybe_unused]] _analyse<T, typename std::enable_if<std::is_base_of<Dipole, T>::value>::type> {
void sample(T&) { std::cout << "dipole!" << std::endl; } //!< Sample
}; // specialized template

Expand Down Expand Up @@ -1106,7 +1106,7 @@ class Voronota : public Analysis {
std::string filename; //!< output file name
bool use_pbc = false; //!< Is the cell periodic?

void _to_json(json& j) const override;
void _to_json(json& json_output) const override;
void _from_json(const json& input) override;
void _to_disk() override;
void _sample() override;
Expand All @@ -1116,6 +1116,6 @@ class Voronota : public Analysis {
Voronota(double probe_radius, const Space& spc);
};

} // namespace analysis
} // namespace Faunus::analysis


} // namespace Faunus
40 changes: 22 additions & 18 deletions src/atomdata.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma clang diagnostic push
#pragma ide diagnostic ignored "altera-unroll-loops"
#include <doctest/doctest.h>
#include <stdexcept>
#include "atomdata.h"
Expand Down Expand Up @@ -96,9 +98,9 @@ void from_json(const json& j, AtomData& a) {
if (!j.is_object() || j.size() != 1) {
throw std::runtime_error("Invalid JSON data for AtomData");
}
for (auto atom_iter : j.items()) {
for (const auto& atom_iter : j.items()) {
a.name = atom_iter.key();
SingleUseJSON val = atom_iter.value();
auto val = SingleUseJSON(atom_iter.value());
a.alphax = val.value("alphax", a.alphax);
a.charge = val.value("q", a.charge);
a.dp = val.value("dp", a.dp) * 1.0_angstrom;
Expand Down Expand Up @@ -211,27 +213,27 @@ TEST_CASE("[Faunus] AtomData") {
CHECK_EQ(v.size(), 2);
CHECK_EQ(v.front().id(), 0);
CHECK_EQ(v.front().name, "A"); // alphabetic order in std::map
CHECK(v.front().interaction.at("sigma") == Approx(2.5)); // raw number, no units
CHECK(v.front().interaction.at("eps_custom") == Approx(0.1)); // raw number, no units
CHECK_EQ(v.front().interaction.at("sigma"), Approx(2.5)); // raw number, no units
CHECK_EQ(v.front().interaction.at("eps_custom"), Approx(0.1)); // raw number, no units

CHECK_EQ(std::isnan(v.front().interaction.at("eps_unknown")), true);
// CHECK_THROWS_AS_MESSAGE(v.front().interaction.get("eps_unknown"), std::runtime_error, "unknown atom property");
CHECK(v.front().sigma == Approx(2.5e-10_m));
CHECK(v.front().activity == Approx(0.01_molar));
CHECK(v.back().tfe == Approx(0.98_kJmol / (1.0_angstrom * 1.0_angstrom * 1.0_molar)));
CHECK_EQ(v.front().sigma, Approx(2.5e-10_m));
CHECK_EQ(v.front().activity, Approx(0.01_molar));
CHECK_EQ(v.back().tfe, Approx(0.98_kJmol / (1.0_angstrom * 1.0_angstrom * 1.0_molar)));

AtomData a = json(v.back()); // AtomData -> JSON -> AtomData

CHECK_EQ(a.name, "B");
CHECK_EQ(a.id(), 1);
CHECK(a.activity == Approx(0.2_molar));
CHECK(a.interaction.at("sigma") == Approx(2.2)); // raw number, no units
CHECK(a.interaction.at("eps") == Approx(0.05)); // raw number, no units
CHECK(a.dp == Approx(9.8));
CHECK(a.dprot == Approx(3.14));
CHECK(a.mw == Approx(1.1));
CHECK(a.tfe == Approx(0.98_kJmol / 1.0_angstrom / 1.0_angstrom / 1.0_molar));
CHECK(a.tension == Approx(0.023_kJmol / 1.0_angstrom / 1.0_angstrom));
CHECK_EQ(a.activity, Approx(0.2_molar));
CHECK_EQ(a.interaction.at("sigma"), Approx(2.2)); // raw number, no units
CHECK_EQ(a.interaction.at("eps"), Approx(0.05)); // raw number, no units
CHECK_EQ(a.dp, Approx(9.8));
CHECK_EQ(a.dprot, Approx(3.14));
CHECK_EQ(a.mw, Approx(1.1));
CHECK_EQ(a.tfe, Approx(0.98_kJmol / 1.0_angstrom / 1.0_angstrom / 1.0_molar));
CHECK_EQ(a.tension, Approx(0.023_kJmol / 1.0_angstrom / 1.0_angstrom));

auto it = findName(v, "B");
CHECK_EQ(it->id(), 1);
Expand All @@ -244,11 +246,11 @@ UnknownAtomError::UnknownAtomError(std::string_view atom_name)
: GenericError("unknown atom: '{}'", atom_name) {}

AtomData& findAtomByName(std::string_view name) {
const auto result = findName(Faunus::atoms, name);
if (result == Faunus::atoms.end()) {
const auto iter = findName(Faunus::atoms, name);
if (iter == Faunus::atoms.end()) {
throw UnknownAtomError(name);
}
return *result;
return *iter;
}

void from_json(const json& j, SpheroCylinderData& psc) {
Expand All @@ -268,3 +270,5 @@ void to_json(json& j, const SpheroCylinderData& psc) {
}

} // namespace Faunus

#pragma clang diagnostic pop
Loading
Loading