Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #625 from votca/csg_boltzmann_excl_test
Browse files Browse the repository at this point in the history
Fix exclusions in csg_boltzmann
  • Loading branch information
junghans authored Jan 5, 2021
2 parents efaa34c + f77a39b commit 64fa551
Show file tree
Hide file tree
Showing 16 changed files with 1,956 additions and 110 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
For more detailed information about the changes see the history of the
[repository](https://github.com/votca/csg/commits/master).

## Version 1.6.4 (released XX.12.20)
* fix exclusion creation in csg_boltzmann (#624, #625)

## Version 1.6.3 (released 09.12.20)
* fix test dependencies for parallel ctest (#585)
* fix trigger for gmx-2020 warning in run_gromacs.sh (#591)
Expand Down
90 changes: 17 additions & 73 deletions include/votca/csg/exclusionlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class ExclusionList {

void Clear(void);

template <typename iteratable>
void Remove(iteratable &l);
template <typename iterable>
void Remove(iterable &l);

template <typename iteratable>
void ExcludeList(iteratable &l);
template <typename iterable>
void ExcludeList(iterable &l);

struct exclusion_t {
Bead *_atom;
Expand All @@ -60,8 +60,8 @@ class ExclusionList {

bool IsExcluded(Bead *bead1, Bead *bead2);

template <typename iteratable>
void InsertExclusion(Bead *bead, iteratable &excluded);
template <typename iterable>
void InsertExclusion(Bead *bead, iterable &excluded);

void InsertExclusion(Bead *bead1, Bead *bead2);

Expand All @@ -83,9 +83,9 @@ inline ExclusionList::exclusion_t *ExclusionList::GetExclusions(Bead *bead) {
return (*iter).second;
}

template <typename iteratable>
inline void ExclusionList::Remove(iteratable &l) {
typename iteratable::iterator i, j;
template <typename iterable>
inline void ExclusionList::Remove(iterable &l) {
typename iterable::iterator i, j;

for (i = l.begin(); i != l.end(); ++i) {
for (j = i; j != l.end(); ++j) {
Expand All @@ -94,9 +94,9 @@ inline void ExclusionList::Remove(iteratable &l) {
}
}

template <typename iteratable>
inline void ExclusionList::ExcludeList(iteratable &l) {
typename iteratable::iterator i, j;
template <typename iterable>
inline void ExclusionList::ExcludeList(iterable &l) {
typename iterable::iterator i, j;

for (i = l.begin(); i != l.end(); ++i) {
for (j = i; j != l.end(); ++j) {
Expand All @@ -105,11 +105,11 @@ inline void ExclusionList::ExcludeList(iteratable &l) {
}
}

template <typename iteratable>
inline void ExclusionList::InsertExclusion(Bead *bead1_, iteratable &l) {
for (typename iteratable::iterator i = l.begin(); i != l.end(); ++i) {
Bead *bead1 = bead1_;
Bead *bead2 = *i;
template <typename iterable>
inline void ExclusionList::InsertExclusion(Bead *beadA, iterable &l) {
for (Bead *beadB : l) {
Bead *bead1 = beadA;
Bead *bead2 = beadB;
if (bead2->getId() < bead1->getId()) {
std::swap(bead1, bead2);
}
Expand All @@ -131,62 +131,6 @@ inline void ExclusionList::InsertExclusion(Bead *bead1_, iteratable &l) {
}
}

// template<>
inline void ExclusionList::InsertExclusion(Bead *bead1, Bead *bead2) {
if (bead2->getId() < bead1->getId()) {
std::swap(bead1, bead2);
}

if (bead1 == bead2) {
return;
}

if (IsExcluded(bead1, bead2)) {
return;
}

exclusion_t *e;
if ((e = GetExclusions(bead1)) == nullptr) {
e = new exclusion_t;
e->_atom = bead1;
_exclusions.push_back(e);
_excl_by_bead[bead1] = e;
}
e->_exclude.push_back(bead2);
}

inline void ExclusionList::RemoveExclusion(Bead *bead1, Bead *bead2) {
if (bead2->getId() < bead1->getId()) {
std::swap(bead1, bead2);
}

if (bead1 == bead2) {
return;
}

if (!IsExcluded(bead1, bead2)) {
return;
}

std::list<exclusion_t *>::iterator ex;
for (ex = _exclusions.begin(); ex != _exclusions.end(); ++ex) {
if ((*ex)->_atom == bead1) {
break;
}

if (ex == _exclusions.end()) {
return;
}

(*ex)->_exclude.remove(bead2);
if ((*ex)->_exclude.empty()) {
(*ex) = nullptr;
_exclusions.erase(ex);
}
_exclusions.remove(nullptr);
}
}

std::ostream &operator<<(std::ostream &out, ExclusionList &ex);

} // namespace csg
Expand Down
49 changes: 17 additions & 32 deletions src/csg_boltzmann/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CsgBoltzmann : public CsgApplication {
bool EvaluateTopology(Topology *top, Topology *top_ref) override;

protected:
ExclusionList *CreateExclusionList(Molecule &atomistic, Molecule &cg);
ExclusionList CreateExclusionList(Molecule &atomistic, Molecule &cg);
BondedStatistics _bs;
};
void CsgBoltzmann::Initialize() {
Expand All @@ -76,7 +76,6 @@ bool CsgBoltzmann::EvaluateOptions() {

bool CsgBoltzmann::EvaluateTopology(Topology *top, Topology *top_ref) {
if (OptionsMap().count("excl")) {
ExclusionList *ex;
if (top_ref->MoleculeCount() > 1) {
cout << "WARNING: cannot create exclusion list for topology with"
"multiple molecules, using only first molecule\n";
Expand All @@ -87,60 +86,46 @@ bool CsgBoltzmann::EvaluateTopology(Topology *top, Topology *top_ref) {
<< " in coarse grained representation "
<< top_ref->MoleculeByIndex(0)->getName() << endl;

ex = CreateExclusionList(*top_ref->MoleculeByIndex(0),
*top->MoleculeByIndex(0));
ExclusionList ex = CreateExclusionList(*top_ref->MoleculeByIndex(0),
*top->MoleculeByIndex(0));
std::ofstream fl;
fl.open(OptionsMap()["excl"].as<string>());
fl << "# atomistic: " << top_ref->MoleculeByIndex(0)->getName()
<< " cg: " << top_ref->MoleculeByIndex(0)->getName()
<< " cgmap: " << OptionsMap()["cg"].as<string>() << endl;
fl << *ex;
fl << ex;
fl.close();
delete ex;

return false;
}
return true;
}

ExclusionList *CsgBoltzmann::CreateExclusionList(Molecule &atomistic,
Molecule &cg) {
ExclusionList *ex = new ExclusionList();
ExclusionList CsgBoltzmann::CreateExclusionList(Molecule &atomistic,
Molecule &cg) {
ExclusionList ex;
// exclude all with all
{
list<Bead *> excl_list;
for (votca::Index i = 0; i < atomistic.BeadCount(); ++i) {
excl_list.push_back(atomistic.getBead(i));
}
ex->ExcludeList(excl_list);
}

ex.ExcludeList(atomistic.Beads());
// remove exclusions from inside a mapped bead
Topology *at_top = atomistic.getParent();
for (votca::Index i = 0; i < cg.BeadCount(); ++i) {
const vector<votca::Index> &parent_beads = cg.getBead(i)->ParentBeads();
list<Bead *> excl_list;

for (const votca::Index &parent_bead_id : parent_beads) {
std::vector<Bead *> excl_list;
for (votca::Index parent_bead_id : cg.getBead(i)->ParentBeads()) {
excl_list.push_back(at_top->getBead(parent_bead_id));
}
ex->Remove(excl_list);
ex.Remove(excl_list);
}

// remove exclusion which come from atomistic topology and hence bonds and
// angles
Topology *cg_top = cg.getParent();
for (votca::Index i = 0; i < cg.BeadCount() - 1; ++i) {
for (votca::Index j = i + 1; j < cg.BeadCount(); ++j) {
if (cg_top->getExclusions().IsExcluded(cg.getBead(i), cg.getBead(j))) {
const vector<votca::Index> &parent_beads_w =
cg.getBead(i)->ParentBeads();
const vector<votca::Index> &parent_beads_v =
cg.getBead(j)->ParentBeads();

for (const votca::Index parent_bead_id_w : parent_beads_w) {
for (const votca::Index parent_bead_id_v : parent_beads_v) {
ex->RemoveExclusion(at_top->getBead(parent_bead_id_w),
at_top->getBead(parent_bead_id_v));

for (votca::Index parent_bead_id_i : cg.getBead(i)->ParentBeads()) {
for (votca::Index parent_bead_id_j : cg.getBead(j)->ParentBeads()) {
ex.RemoveExclusion(at_top->getBead(parent_bead_id_i),
at_top->getBead(parent_bead_id_j));
}
}
}
Expand Down
62 changes: 57 additions & 5 deletions src/libcsg/exclusionlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void ExclusionList::CreateExclusions(Topology *top) {

for (auto &ia : ic) {
Index beads_in_int = ia->BeadCount();
list<Bead *> l;
std::vector<Bead *> l;

for (Index ibead = 0; ibead < beads_in_int; ibead++) {
Index ii = ia->getBeadId(ibead);
Expand All @@ -48,13 +48,14 @@ void ExclusionList::CreateExclusions(Topology *top) {
}

bool ExclusionList::IsExcluded(Bead *bead1, Bead *bead2) {
exclusion_t *excl;

if (bead1->getMolecule() != bead2->getMolecule()) {
return false;
}
if (bead2->getId() < bead1->getId()) {
swap(bead1, bead2);
}
exclusion_t *excl;
if ((excl = GetExclusions(bead1))) {
if (find(excl->_exclude.begin(), excl->_exclude.end(), bead2) !=
excl->_exclude.end()) {
Expand All @@ -64,6 +65,58 @@ bool ExclusionList::IsExcluded(Bead *bead1, Bead *bead2) {
return false;
}

void ExclusionList::InsertExclusion(Bead *bead1, Bead *bead2) {
if (bead2->getId() < bead1->getId()) {
std::swap(bead1, bead2);
}

if (bead1 == bead2) {
return;
}

if (IsExcluded(bead1, bead2)) {
return;
}

exclusion_t *e;
if ((e = GetExclusions(bead1)) == nullptr) {
e = new exclusion_t;
e->_atom = bead1;
_exclusions.push_back(e);
_excl_by_bead[bead1] = e;
}
e->_exclude.push_back(bead2);
}

void ExclusionList::RemoveExclusion(Bead *bead1, Bead *bead2) {
if (bead2->getId() < bead1->getId()) {
std::swap(bead1, bead2);
}

if (bead1 == bead2) {
return;
}

if (!IsExcluded(bead1, bead2)) {
return;
}

std::list<exclusion_t *>::iterator ex =
std::find_if(_exclusions.begin(), _exclusions.end(),
[&bead1](exclusion_t *e) { return e->_atom == bead1; });

if (ex == _exclusions.end()) {
return;
}

(*ex)->_exclude.remove(bead2);
if ((*ex)->_exclude.empty()) {
(*ex) = nullptr;
_exclusions.erase(ex);
}
_exclusions.remove(nullptr);
}

bool compareAtomIdiExclusionList(const ExclusionList::exclusion_t *a,
const ExclusionList::exclusion_t *b) {
return a->_atom->getId() < b->_atom->getId();
Expand All @@ -79,9 +132,8 @@ std::ostream &operator<<(std::ostream &out, ExclusionList &exl) {
for (auto &_exclusion : exl._exclusions) {
_exclusion->_exclude.sort(compareAtomIdBeadList);
out << (Index)(_exclusion->_atom->getId()) + 1;
for (list<Bead *>::iterator i = _exclusion->_exclude.begin();
i != _exclusion->_exclude.end(); ++i) {
out << " " << ((*i)->getId() + 1);
for (Bead *bead : _exclusion->_exclude) {
out << " " << (bead->getId() + 1);
}
out << endl;
}
Expand Down
36 changes: 36 additions & 0 deletions src/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,40 @@ if(ENABLE_TESTING)
set_tests_properties(integration_Compare_csg_property_output4 PROPERTIES LABELS "csg;tools;votca;integration")

endif(BASH)

if(GMX_FOUND)
set(RUNPATH ${CMAKE_CURRENT_BINARY_DIR}/Run_csg_boltzmann_ppy)
set(REFPATH ${CMAKE_CURRENT_SOURCE_DIR}/references/ppy/)
file(MAKE_DIRECTORY ${RUNPATH})
foreach(_SRC topol.top grompp.mdp conf.gro ffgmx.itp ppy10.xml)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${REFPATH}/${_SRC} ${RUNPATH}/${_SRC})
endforeach()
add_test(NAME integration_Run_gmx_grompp_ppy COMMAND ${GMX_EXECUTABLE} grompp WORKING_DIRECTORY ${RUNPATH})
set_tests_properties(integration_Run_gmx_grompp_ppy PROPERTIES LABELS "csg;tools;votca")
add_test(NAME integration_Run_csg_boltzmann_ppy
COMMAND $<TARGET_FILE:csg_boltzmann> --top topol.tpr --cg ppy10.xml --excl excl.txt
WORKING_DIRECTORY ${RUNPATH})
set_tests_properties(integration_Run_csg_boltzmann_ppy PROPERTIES DEPENDS integration_Run_gmx_grompp_ppy)
set_tests_properties(integration_Run_csg_boltzmann_ppy PROPERTIES LABELS "csg;tools;votca")
add_test(NAME Compare_csg_boltzmann_output_ppy COMMAND ${CMAKE_COMMAND} -E compare_files excl.txt ${REFPATH}/excl.txt WORKING_DIRECTORY ${RUNPATH})
set_tests_properties(Compare_csg_boltzmann_output_ppy PROPERTIES DEPENDS integration_Run_csg_boltzmann_ppy)
set_tests_properties(Compare_csg_boltzmann_output_ppy PROPERTIES LABELS "csg;tools;votca")

set(RUNPATH ${CMAKE_CURRENT_BINARY_DIR}/Run_csg_boltzmann_mma)
set(REFPATH ${CMAKE_CURRENT_SOURCE_DIR}/references/mma/)
file(MAKE_DIRECTORY ${RUNPATH})
foreach(_SRC topol.top grompp.mdp conf.gro ffgmx.itp mapping.xml)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${REFPATH}/${_SRC} ${RUNPATH}/${_SRC})
endforeach()
add_test(NAME integration_Run_gmx_grompp_mma COMMAND ${GMX_EXECUTABLE} grompp WORKING_DIRECTORY ${RUNPATH})
set_tests_properties(integration_Run_gmx_grompp_mma PROPERTIES LABELS "csg;tools;votca")
add_test(NAME integration_Run_csg_boltzmann_mma
COMMAND $<TARGET_FILE:csg_boltzmann> --top topol.tpr --cg mapping.xml --excl excl.txt
WORKING_DIRECTORY ${RUNPATH})
set_tests_properties(integration_Run_csg_boltzmann_mma PROPERTIES DEPENDS integration_Run_gmx_grompp_mma)
set_tests_properties(integration_Run_csg_boltzmann_mma PROPERTIES LABELS "csg;tools;votca")
add_test(NAME Compare_csg_boltzmann_output_mma COMMAND ${CMAKE_COMMAND} -E compare_files excl.txt ${REFPATH}/excl.txt WORKING_DIRECTORY ${RUNPATH})
set_tests_properties(Compare_csg_boltzmann_output_mma PROPERTIES DEPENDS integration_Run_csg_boltzmann_mma)
set_tests_properties(Compare_csg_boltzmann_output_mma PROPERTIES LABELS "csg;tools;votca")
endif(GMX_FOUND)
endif()
Loading

0 comments on commit 64fa551

Please sign in to comment.