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

Fix EPSR Toml parsing #1694

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/classes/atomType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ SerialisedValue AtomType::serialise() const
{
SerialisedValue atomType;

atomType["name"] = name_;
atomType["z"] = Z_;
atomType["charge"] = charge_;
atomType["form"] = ShortRangeFunctions::forms().keyword(interactionPotential_.form());
Expand Down
10 changes: 5 additions & 5 deletions src/classes/serializablePairPotential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ SerialisedValue SerializablePairPotential::serialise() const
pairPotentials["forceChargeSource"] = true;
if (atomTypeChargeSource_)
pairPotentials["includeCoulomb"] = true;
for (auto &atomType : atomTypes_)
pairPotentials["atomTypes"][atomType->name().data()] = atomType->serialise();
Serialisable::fromVector(atomTypes_, "atomTypes", pairPotentials);
return pairPotentials;
}

Expand All @@ -71,7 +70,8 @@ void SerializablePairPotential::deserialise(const SerialisedValue &node)
shortRangeTruncationScheme_ = PairPotential::shortRangeTruncationSchemes().deserialise(
toml::find_or<std::string>(node, "shortRangeTruncation", "Shifted"));

toMap(node, "atomTypes",
[this](const auto &name, const auto &data)
{ atomTypes_.emplace_back(std::make_unique<AtomType>(name))->deserialise(data); });
toVector(node, "atomTypes",
[this](const auto &data) {
atomTypes_.emplace_back(std::make_unique<AtomType>(toml::find<std::string>(data, "name")))->deserialise(data);
});
}
10 changes: 5 additions & 5 deletions tests/modules/epsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class EPSRModuleTest : public ::testing::Test

TEST_F(EPSRModuleTest, Water3NInpA)
{
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/epsr-water-inpa.txt"));
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/epsr-water-inpa.txt"));
ASSERT_TRUE(systemTest.dissolve().iterate(1));

// Estimated Partials
Expand Down Expand Up @@ -107,7 +107,7 @@ TEST_F(EPSRModuleTest, Water3NInpA)

TEST_F(EPSRModuleTest, Water3NX)
{
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/epsr-water-3n-x.txt"));
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/epsr-water-3n-x.txt"));
ASSERT_TRUE(systemTest.dissolve().iterate(1));

// Test total neutron-weighted F(r)
Expand Down Expand Up @@ -138,7 +138,7 @@ TEST_F(EPSRModuleTest, Water3NX)

TEST_F(EPSRModuleTest, Benzene)
{
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/epsr-benzene-3n.txt"));
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/epsr-benzene-3n.txt"));
ASSERT_TRUE(systemTest.dissolve().iterate(1));

// Test total neutron-weighted F(r)
Expand Down Expand Up @@ -200,7 +200,7 @@ TEST_F(EPSRModuleTest, BenzeneReadPCof) { ASSERT_NO_THROW(systemTest.setUp("diss

TEST_F(EPSRModuleTest, ScatteringMatrix)
{
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/epsr-5datasets.txt"));
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/epsr-5datasets.txt"));
ASSERT_TRUE(systemTest.dissolve().iterate(1));

// Find EPSR module
Expand All @@ -221,7 +221,7 @@ TEST_F(EPSRModuleTest, ScatteringMatrix)

TEST_F(EPSRModuleTest, DataWeighting)
{
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/epsr-5datasets-weighted.txt"));
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/epsr-5datasets-weighted.txt"));
ASSERT_TRUE(systemTest.dissolve().iterate(1));

// Find EPSR module
Expand Down
Loading