Skip to content

Commit

Permalink
Refactor EnergyBase for increased readability (#296)
Browse files Browse the repository at this point in the history
* Renaming refactor for energybase and external potential

* variable renaming and schema update
  • Loading branch information
mlund authored Jun 28, 2020
1 parent 74fe32a commit 4fb92dd
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 181 deletions.
19 changes: 18 additions & 1 deletion docs/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,24 @@ properties:
- required: [rhoinv]
- required: [phi0]
additionalProperties: false

akesson:
description: "Electric potential correction from outside cuboidal slit"
type: object
properties:
dz: {type: number, default: 0.2, description: "resolution along z (Å)"}
epsr: {type: number, description: "Relative dielectric constant"}
file: {type: string, description: "Input/output file for charge density profile"}
nphi: {type: integer, default: 10, description: "Multiple of `nstep` in between updating charge density profile"}
fixed: {type: boolean, default: false, description: "If true, do not update loaded charge density"}
nstep: {type: integer, description: "Number of energy evalutations between updating charge density"}
molecules:
type: array
items: {type: string}
minItems: 1
description: "Array of molecules to operate on"
required: [epsr, molecules, nstep]
additionalProperties: false

isobaric:
description: "External pressure"
type: object
Expand Down
18 changes: 9 additions & 9 deletions src/energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ double PolicyIonIonEigen::reciprocalEnergy(const EwaldData &d) {
Ewald::Ewald(const json &j, Space &spc) : data(j), spc(spc) {
name = "ewald";
policy = EwaldPolicyBase::makePolicy(data.policy);
cite = policy->cite;
citation_information = policy->cite;
init();
}

Expand All @@ -356,8 +356,8 @@ void Ewald::init() {
double Ewald::energy(Change &change) {
double u = 0;
if (change) {
// If the state is NEW (trial state), then update all k-vectors
if (key == NEW) {
// If the state is NEW_MONTE_CARLO_STATE (trial state), then update all k-vectors
if (key == NEW_MONTE_CARLO_STATE) {
if (change.all or change.dV) { // everything changes
policy->updateBox(data, spc.geo.getLength());
policy->updateComplex(data, spc.groups); // update all (expensive!)
Expand All @@ -381,10 +381,10 @@ double Ewald::energy(Change &change) {
void Ewald::sync(Energybase *energybase_pointer, Change &change) {
auto other = dynamic_cast<decltype(this)>(energybase_pointer);
assert(other);
if (other->key == OLD) {
old_groups =
&(other->spc
.groups); // give NEW access to OLD space for optimized updates
if (other->key == OLD_MONTE_CARLO_STATE) {
old_groups =
&(other->spc
.groups); // give NEW_MONTE_CARLO_STATE access to OLD_MONTE_CARLO_STATE space for optimized updates
}

// hard-coded sync; should be expanded when dipolar ewald is supported
Expand Down Expand Up @@ -449,7 +449,7 @@ double ContainerOverlap::energy(Change &change) {

Isobaric::Isobaric(const json &j, Space &spc) : spc(spc) {
name = "isobaric";
cite = "Frenkel & Smith 2nd Ed (Eq. 5.4.13)";
citation_information = "Frenkel & Smith 2nd Ed (Eq. 5.4.13)";
P = j.value("P/mM", 0.0) * 1.0_mM;
if (P < 1e-10) {
P = j.value("P/Pa", 0.0) * 1.0_Pa;
Expand Down Expand Up @@ -762,7 +762,7 @@ SASAEnergy::SASAEnergy(Space &spc, double cosolute_concentration, double probe_r
: spc(spc), cosolute_concentration(cosolute_concentration)
{
name = "sasa"; // todo predecessor constructor
cite = "doi:10.12688/f1000research.7931.1"; // todo predecessor constructor
citation_information = "doi:10.12688/f1000research.7931.1"; // todo predecessor constructor
parameters = freesasa_default_parameters;
parameters.probe_radius = probe_radius;
init();
Expand Down
2 changes: 1 addition & 1 deletion src/energy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ template <typename Tpairpot> class NonbondedCached : public Nonbonded<PairingPol
if (j < i) {
std::swap(i, j);
}
if (base::key == Energybase::NEW) { // if this is from the trial system,
if (base::key == Energybase::NEW_MONTE_CARLO_STATE) { // if this is from the trial system,
cache(i, j) = base::pairing.group2group(g1, g2); // update the cache
}
return cache(i, j); // return (cached) value
Expand Down
Loading

0 comments on commit 4fb92dd

Please sign in to comment.