Skip to content

Commit

Permalink
fix: Remove atom type and master term from forcefield tab (#1889)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobBuchananCompPhys committed May 13, 2024
1 parent 7d0de7e commit 420d363
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 8 deletions.
86 changes: 84 additions & 2 deletions src/classes/coreData.cpp
Expand Up @@ -53,9 +53,11 @@ std::shared_ptr<AtomType> CoreData::addAtomType(Elements::Element Z)
}

// Remove specified AtomType
void CoreData::removeAtomType(const std::shared_ptr<AtomType> &at)
void CoreData::removeAtomType(std::shared_ptr<AtomType> &at)
{
atomTypes_.erase(std::remove(atomTypes_.begin(), atomTypes_.end(), at));
removeReferencesTo(at);

atomTypes_.erase(std::remove(atomTypes_.begin(), atomTypes_.end(), at), atomTypes_.end());
}

// Return number of AtomTypes in list
Expand Down Expand Up @@ -156,6 +158,20 @@ MasterBond &CoreData::addMasterBond(std::string_view name)
return *masters_.bonds.emplace_back(std::make_shared<MasterBond>(name));
}

// Remove specified master Bond
void CoreData::removeMasterBond(const std::shared_ptr<MasterBond> &bond)
{
// Detach from master term
for (auto &species : species_)
{
for (auto &b : species->bonds())
if (b.masterTerm() == bond.get())
b.detachFromMasterTerm();
}

masters_.bonds.erase(std::remove(masters_.bonds.begin(), masters_.bonds.end(), bond), masters_.bonds.end());
}

// Return number of master Bond parameters in list
int CoreData::nMasterBonds() const { return masters_.bonds.size(); }

Expand Down Expand Up @@ -198,6 +214,20 @@ MasterAngle &CoreData::addMasterAngle(std::string_view name)
return *masters_.angles.emplace_back(std::make_shared<MasterAngle>(name));
}

// Remove specified master Angle
void CoreData::removeMasterAngle(const std::shared_ptr<MasterAngle> &angle)
{
// Detach from master term
for (auto &species : species_)
{
for (auto &a : species->angles())
if (a.masterTerm() == angle.get())
a.detachFromMasterTerm();
}

masters_.angles.erase(std::remove(masters_.angles.begin(), masters_.angles.end(), angle), masters_.angles.end());
}

// Return number of master Angle parameters in list
int CoreData::nMasterAngles() const { return masters_.angles.size(); }

Expand Down Expand Up @@ -240,6 +270,20 @@ MasterTorsion &CoreData::addMasterTorsion(std::string_view name)
return *masters_.torsions.emplace_back(std::make_shared<MasterTorsion>(name));
}

// Remove specified MasterTorsion
void CoreData::removeMasterTorsion(const std::shared_ptr<MasterTorsion> &torsion)
{
// Detach from master term
for (auto &species : species_)
{
for (auto &t : species->torsions())
if (t.masterTerm() == torsion.get())
t.detachFromMasterTerm();
}

masters_.torsions.erase(std::remove(masters_.torsions.begin(), masters_.torsions.end(), torsion), masters_.torsions.end());
}

// Return number of master Torsion parameters in list
int CoreData::nMasterTorsions() const { return masters_.torsions.size(); }

Expand Down Expand Up @@ -282,6 +326,21 @@ MasterImproper &CoreData::addMasterImproper(std::string_view name)
return *masters_.impropers.emplace_back(std::make_shared<MasterImproper>(name));
}

// Remove specified master Improper
void CoreData::removeMasterImproper(const std::shared_ptr<MasterImproper> &improper)
{
// Detach from master term
for (auto &species : species_)
{
for (auto &i : species->impropers())
if (i.masterTerm() == improper.get())
i.detachFromMasterTerm();
}

masters_.impropers.erase(std::remove(masters_.impropers.begin(), masters_.impropers.end(), improper),
masters_.impropers.end());
}

// Return number of master Improper parameters in list
int CoreData::nMasterImpropers() const { return masters_.impropers.size(); }

Expand Down Expand Up @@ -677,6 +736,14 @@ template <class O> void objectNoLongerValid(CoreData *coreData, O *object)
mod->keywords().objectNoLongerValid(object);
}

template <class P> void objectNoLongerValid(CoreData *coreData, std::shared_ptr<P> object)
{
// Loop over all keyword objects and call their local functions
for (auto &layer : coreData->processingLayers())
for (auto &mod : layer->modules())
mod->keywords().objectNoLongerValid(object);
}

// Remove all references to the specified data
void CoreData::removeReferencesTo(Module *data) { objectNoLongerValid(this, data); }
void CoreData::removeReferencesTo(Isotopologue *data) { objectNoLongerValid(this, data); }
Expand All @@ -691,6 +758,21 @@ void CoreData::removeReferencesTo(Species *data)
cfg->empty();
}
void CoreData::removeReferencesTo(SpeciesSite *data) { objectNoLongerValid(this, data); }
void CoreData::removeReferencesTo(std::shared_ptr<AtomType> data)
{
for (auto &species : species_)
{
for (auto &atom : species->atoms())
{
if (atom.atomType() == data)
{
atom.setAtomType(nullptr);
}
}
}

objectNoLongerValid(this, data);
}

/*
* Modules
Expand Down
11 changes: 10 additions & 1 deletion src/classes/coreData.h
Expand Up @@ -46,7 +46,7 @@ class CoreData
// Add new AtomType
std::shared_ptr<AtomType> addAtomType(Elements::Element Z);
// Remove specified AtomType
void removeAtomType(const std::shared_ptr<AtomType> &at);
void removeAtomType(std::shared_ptr<AtomType> &at);
// Return number of AtomTypes in list
int nAtomTypes() const;
// Return core AtomTypes list
Expand Down Expand Up @@ -114,6 +114,8 @@ class CoreData
void deserialiseMaster(const SerialisedValue &node);
// Add new master Bond parameters
MasterBond &addMasterBond(std::string_view name);
// Remove specified master Bond
void removeMasterBond(const std::shared_ptr<MasterBond> &bond);
// Return number of master Bond parameters in list
int nMasterBonds() const;
// Return list of master Bond parameters
Expand All @@ -124,6 +126,8 @@ class CoreData
OptionalReferenceWrapper<const MasterBond> getMasterBond(std::string_view name) const;
// Add new master Angle parameters
MasterAngle &addMasterAngle(std::string_view name);
// Remove specified master Angle
void removeMasterAngle(const std::shared_ptr<MasterAngle> &angle);
// Return number of master Angles parameters in list
int nMasterAngles() const;
// Return list of master Angle parameters
Expand All @@ -134,6 +138,8 @@ class CoreData
OptionalReferenceWrapper<const MasterAngle> getMasterAngle(std::string_view name) const;
// Add new master Torsion parameters
MasterTorsion &addMasterTorsion(std::string_view name);
// Remove specified master Torsion
void removeMasterTorsion(const std::shared_ptr<MasterTorsion> &torsion);
// Return number of master Torsions parameters in list
int nMasterTorsions() const;
// Return list of master Torsion parameters
Expand All @@ -144,6 +150,8 @@ class CoreData
OptionalReferenceWrapper<const MasterTorsion> getMasterTorsion(std::string_view name) const;
// Add new master Improper parameters
MasterImproper &addMasterImproper(std::string_view name);
// Remove specified master Impropers
void removeMasterImproper(const std::shared_ptr<MasterImproper> &improper);
// Return number of master Impropers parameters in list
int nMasterImpropers() const;
// Return list of master Improper parameters
Expand Down Expand Up @@ -274,4 +282,5 @@ class CoreData
void removeReferencesTo(Module *data);
void removeReferencesTo(Species *data);
void removeReferencesTo(SpeciesSite *data);
void removeReferencesTo(std::shared_ptr<AtomType> data);
};

1 comment on commit 420d363

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 420d363 Previous: 7d0de7e Ratio
BM_Box_MinimumVector<OrthorhombicBox> 9.933113967105058 ns/iter 4.952878119654742 ns/iter 2.01

This comment was automatically generated by workflow using github-action-benchmark.

CC: @disorderedmaterials/dissolve-devs

Please sign in to comment.