Skip to content

Commit

Permalink
g2g cutoff for specific molecules
Browse files Browse the repository at this point in the history
  • Loading branch information
mlund committed Feb 20, 2019
1 parent 2c7582a commit f67849e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Or build from source, see [here](http://mlund.github.io/faunus/docs/install/).
Documentation
=============

http://mlund.github.io/faunus
- manual for latest stable release: https://github.com/mlund/faunus/releases/latest
- manual for development branch: http://mlund.github.io/faunus
- manual for installed verion: `faunus-manual`

Licence
=======
Expand Down
13 changes: 13 additions & 0 deletions docs/_docs/energy.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ Below is a description of possible pair-potentials and their configuration.
`nonbonded_pm` | `coulomb`+`hardsphere` (fixed `type=plain`, `cutoff`$=\infty$)
`nonbonded_pmwca` | `coulomb`+`wca` (fixed `type=plain`, `cutoff`$=\infty$)

### Mass Center Cut-offs

For cut-off based pair-potentials working on large molecules, it can be very efficient to
use mass center cut-offs between molecular groups, thus skipping all pair-interactions.
A single cut-off can be used between all molecules (`default`), or specified for specific
combinations:

~~~ yaml
- nonbonded:
cutoff_g2g:
default: 40
"protein water": 60
~~~

### OpenMP Control

Expand Down
44 changes: 41 additions & 3 deletions src/energy.h
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ namespace Faunus {
class Nonbonded : public Energybase {
private:
double g2gcnt=0, g2gskip=0;
PairMatrix<double> cutoff2; // matrix w. group-to-group cutoff

protected:
typedef typename Tspace::Tpvec Tpvec;
Expand All @@ -835,21 +836,26 @@ namespace Faunus {

void to_json(json &j) const override {
j["pairpot"] = pairpot;
j["cutoff_g2g"] = std::sqrt(Rc2_g2g);
if (omp_enable) {
json _a = json::array();
if (omp_g2g) _a.push_back("g2g");
if (omp_i2all) _a.push_back("i2all");
j["openmp"] = _a;
}
j["cutoff_g2g"] = json::object();
auto &_j = j["cutoff_g2g"];
for (auto &a : Faunus::molecules<typename Tspace::Tpvec>)
for (auto &b : Faunus::molecules<typename Tspace::Tpvec>)
if (a.id()>=b.id())
_j[a.name+" "+b.name] = sqrt( cutoff2(a.id(), b.id()) );
}

template<typename T>
inline bool cut(const T &g1, const T &g2) {
g2gcnt++;
if (g1.atomic || g2.atomic)
return false;
if ( spc.geo.sqdist(g1.cm, g2.cm)<Rc2_g2g )
if ( spc.geo.sqdist(g1.cm, g2.cm) < cutoff2(g1.id, g2.id) )
return false;
g2gskip++;
return true;
Expand Down Expand Up @@ -976,7 +982,39 @@ namespace Faunus {
std::cerr << "warning: nonbonded requests unavailable OpenMP." << endl;
#endif
}
Rc2_g2g = std::pow( j.value("cutoff_g2g", pc::infty), 2);

// disable all group-to-group cutoffs by setting infinity
for (auto &i : Faunus::molecules<typename Tspace::Tpvec>)
for (auto &j : Faunus::molecules<typename Tspace::Tpvec>)
cutoff2.set(i.id(), j.id(), pc::infty);

it = j.find("cutoff_g2g");
if (it != j.end()) {
// old style input w. only a single cutoff
if (it->is_number()) {
Rc2_g2g = std::pow( it->get<double>(), 2 );
for (auto &i : Faunus::molecules<typename Tspace::Tpvec>)
for (auto &j : Faunus::molecules<typename Tspace::Tpvec>)
cutoff2.set(i.id(), j.id(), Rc2_g2g);
}
// new style input w. multiple cutoffs between molecules
else if (it->is_object()) {
// ensure that there is a default, fallback cutoff
Rc2_g2g = std::pow( it->at("default").get<double>(), 2);
for (auto &i : Faunus::molecules<typename Tspace::Tpvec>)
for (auto &j : Faunus::molecules<typename Tspace::Tpvec>)
cutoff2.set(i.id(), j.id(), Rc2_g2g);
// loop for space separated molecule pairs in keys
for (auto& i : it->items()) {
auto v = words2vec<std::string>( i.key() );
if (v.size()==2) {
int id1 = (*findName( Faunus::molecules<typename Tspace::Tpvec>, v[0])).id();
int id2 = (*findName( Faunus::molecules<typename Tspace::Tpvec>, v[1])).id();
cutoff2.set( id1, id2, std::pow(i.value().get<double>(),2) );
}
}
}
}
}

void force(std::vector<Point> &forces) override {
Expand Down

0 comments on commit f67849e

Please sign in to comment.