Skip to content

Commit

Permalink
Assorted fixes
Browse files Browse the repository at this point in the history
Changed how energy-scale and orientations work
  • Loading branch information
meister committed Nov 27, 2024
1 parent 373f034 commit fe876bc
Show file tree
Hide file tree
Showing 62 changed files with 1,007 additions and 676 deletions.
1 change: 1 addition & 0 deletions include/cando/chem/energyAnchorRestraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class EnergyAnchorRestraint_O : public EnergyComponent_O
core::T_sp activeAtomMask );
virtual double evaluateAllComponent( ScoringFunction_sp scorer,
NVector_sp pos,
core::T_sp energyScale,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
Expand Down
1 change: 1 addition & 0 deletions include/cando/chem/energyAngle.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class EnergyAngle_O : public EnergyComponent_O
core::T_sp activeAtomMask );
virtual double evaluateAllComponent( ScoringFunction_sp scorer,
NVector_sp pos,
core::T_sp energyScale,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
Expand Down
1 change: 1 addition & 0 deletions include/cando/chem/energyChiralRestraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class EnergyChiralRestraint_O : public EnergyComponent_O
core::T_sp activeAtomMask );
virtual double evaluateAllComponent( ScoringFunction_sp scorer,
NVector_sp pos,
core::T_sp energyScale,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
Expand Down
28 changes: 28 additions & 0 deletions include/cando/chem/energyComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ This is an open source license for the CANDO software from Temple University, bu
#endif
#include <cando/adapt/quickDom.fwd.h>// energyComponent.h wants QDomNode needs quickDom.fwd.h

namespace chem {
class KahanSummation {
private:
double sum;
double c; // A running compensation for lost low-order bits.

public:
// Constructor initializes sum and compensation to zero.
KahanSummation() : sum(0.0), c(0.0) {}

// Adds a new value to the running total using Kahan summation algorithm.
void add(double input) {
double y = input - c;
double t = sum + y;
c = (t - sum) - y;
sum = t;
}

// Returns the current value of the sum.
double getSum() const {
return sum;
}
};
};
namespace chem {


Expand Down Expand Up @@ -280,6 +304,9 @@ class EnergyComponent_O : public core::CxxObject_O
//protected: // Define these in subclasses
// vector<TermClass> _Terms;
// vector<TermClass> _BeyondThresholdTerms;
public:
bool fieldsp() const { return true; };
void fields(core::Record_sp node);
public:
CL_DEFMETHOD virtual size_t numberOfTerms() {_OF(); SUBCLASS_MUST_IMPLEMENT();};
void setScale(double s) {this->_Scale = s; };
Expand Down Expand Up @@ -322,6 +349,7 @@ class EnergyComponent_O : public core::CxxObject_O

CL_DEFMETHOD virtual double evaluateAllComponent( ScoringFunction_sp scorer,
NVector_sp pos,
core::T_sp energyScale,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
Expand Down
1 change: 1 addition & 0 deletions include/cando/chem/energyDihedral.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class EnergyDihedral_O : public EnergyComponent_O
core::T_sp activeAtomMask );
virtual double evaluateAllComponent( ScoringFunction_sp scorer,
NVector_sp pos,
core::T_sp energyScale,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
Expand Down
23 changes: 12 additions & 11 deletions include/cando/chem/energyDihedralRestraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,18 @@ class EnergyDihedralRestraint_O : public EnergyComponent_O
AbstractLargeSquareMatrix_sp m,
core::T_sp activeAtomMask );
virtual double evaluateAllComponent( ScoringFunction_sp scorer,
NVector_sp pos,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
bool calcDiagonalHessian,
bool calcOffDiagonalHessian,
gc::Nilable<AbstractLargeSquareMatrix_sp> hessian,
gc::Nilable<NVector_sp> hdvec,
gc::Nilable<NVector_sp> dvec,
core::T_sp activeAtomMask,
core::T_sp debugInteractions );
NVector_sp pos,
core::T_sp energyScale,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
bool calcDiagonalHessian,
bool calcOffDiagonalHessian,
gc::Nilable<AbstractLargeSquareMatrix_sp> hessian,
gc::Nilable<NVector_sp> hdvec,
gc::Nilable<NVector_sp> dvec,
core::T_sp activeAtomMask,
core::T_sp debugInteractions );

virtual void compareAnalyticalAndNumericalForceAndHessianTermByTerm(
NVector_sp pos );
Expand Down
23 changes: 12 additions & 11 deletions include/cando/chem/energyFixedNonbond.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,18 @@ class EnergyFixedNonbondRestraint_O : public EnergyComponent_O
//virtual void setupHessianPreconditioner(NVector_sp nvPosition,
// AbstractLargeSquareMatrix_sp m );
virtual double evaluateAllComponent( ScoringFunction_sp scorer,
NVector_sp pos,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
bool calcDiagonalHessian,
bool calcOffDiagonalHessian,
gc::Nilable<AbstractLargeSquareMatrix_sp> hessian,
gc::Nilable<NVector_sp> hdvec,
gc::Nilable<NVector_sp> dvec,
core::T_sp activeAtomMask,
core::T_sp debugInteractions ) override;
NVector_sp pos,
core::T_sp energyScale,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
bool calcDiagonalHessian,
bool calcOffDiagonalHessian,
gc::Nilable<AbstractLargeSquareMatrix_sp> hessian,
gc::Nilable<NVector_sp> hdvec,
gc::Nilable<NVector_sp> dvec,
core::T_sp activeAtomMask,
core::T_sp debugInteractions ) override;

virtual void compareAnalyticalAndNumericalForceAndHessianTermByTerm(
NVector_sp pos );
Expand Down
61 changes: 6 additions & 55 deletions include/cando/chem/energyFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ namespace chem
FORWARD(FFPtorDb);
FORWARD(FFItorDb);
FORWARD(FFNonbondDb);
FORWARD(EnergyScale);

class EnergyAtom;

Expand All @@ -96,10 +95,6 @@ namespace chem
FORWARD(BoundingBox);


#define DefaultChiralRestraintOffset 0.2
#define DefaultChiralRestraintWeight 100000.0
#define DefaultAnchorRestraintWeight 10.0

core::T_sp specializeKeepInteractionFactory( core::T_sp keepInteractionFactory, core::T_sp aclass );

bool skipInteraction( core::T_sp keepInteractionFunction,
Expand All @@ -118,47 +113,6 @@ bool skipInteraction( core::T_sp keepInteractionFunction,
FORWARD(EnergyFunction);
};

namespace chem {
FORWARD(EnergyScale);
class EnergyScale_O : public core::CxxObject_O
{
LISP_CLASS(chem,ChemPkg,EnergyScale_O,"EnergyScale",core::CxxObject_O);
public:
double _DielectricConstant;
double _NonbondCutoff;
double _ScaleVdw;
double _ScaleElectrostatic;
double _ChiralRestraintWeight;
double _ChiralRestraintOffset;
double _AnchorRestraintWeight;
double _FixedNonbondRestraintWeight;
EnergyScale_O() : _DielectricConstant(1.0),
_NonbondCutoff(16.0),
_ScaleVdw(1.0),
_ScaleElectrostatic(1.0),
_ChiralRestraintWeight(1.0),
_ChiralRestraintOffset(1.0),
_AnchorRestraintWeight(1.0),
_FixedNonbondRestraintWeight(1.0)
{
this->_ChiralRestraintWeight = DefaultChiralRestraintWeight;
this->_ChiralRestraintOffset = DefaultChiralRestraintOffset;
this->_AnchorRestraintWeight = DefaultAnchorRestraintWeight;
};
static EnergyScale_sp make();
CL_DEFMETHOD void setVdwScale(double d) { this->_ScaleVdw = d; };
CL_DEFMETHOD double getVdwScale() {return this->_ScaleVdw; };
CL_DEFMETHOD void setElectrostaticScale(double d) { this->_ScaleElectrostatic = d; };
CL_DEFMETHOD double getElectrostaticScale() {return this->_ScaleElectrostatic; };
CL_DEFMETHOD void setDielectricConstant(double d) { this->_DielectricConstant = d; };
CL_DEFMETHOD double getDielectricConstant() { return this->_DielectricConstant; };
CL_DEFMETHOD void setNonbondCutoff(double d) { this->_NonbondCutoff = d; };
CL_DEFMETHOD double getNonbondCutoff() { return this->_NonbondCutoff; };

};

};


template <>
struct gctools::GCInfo<chem::EnergyFunction_O> {
Expand All @@ -176,7 +130,6 @@ namespace chem {
static EnergyFunction_sp make(core::T_sp matter,
core::T_sp disableComponents=nil<core::T_O>(),
core::List_sp enableComponents=nil<core::T_O>(),
core::T_sp energyScale=unbound<core::T_O>(),
bool useExcludedAtoms=false,
core::T_sp keepInteractionFactory=nil<core::T_O>(),
bool assign_types=false );
Expand All @@ -187,7 +140,6 @@ namespace chem {
void fields(core::Record_sp node);
public:
Matter_sp _Matter; // Aggregate or Molecule
core::T_sp _EnergyScale;
/*! Stores cross terms for evaluating nonbond interactions
*/
FFNonbondCrossTermTable_sp _NonbondCrossTermTable;
Expand Down Expand Up @@ -227,8 +179,6 @@ namespace chem {

core::List_sp allComponents() const;

EnergyScale_sp energyScale();
void setEnergyScale(core::T_sp energyScale);
string energyTermsEnabled() ;
void loadCoordinatesIntoVector(NVector_sp pos);
void saveCoordinatesFromVector(NVector_sp pos);
Expand All @@ -244,7 +194,7 @@ namespace chem {
void setBoundingBox(BoundingBox_sp bounding_box);
void makUnboundBoundingBox();

ForceMatchReport_sp checkIfAnalyticalForceMatchesNumericalForce( NVector_sp pos, NVector_sp force, core::T_sp activeAtomMask );
ForceMatchReport_sp checkIfAnalyticalForceMatchesNumericalForce( NVector_sp pos, core::T_sp energyScale, NVector_sp force, core::T_sp activeAtomMask );

CL_LISPIFY_NAME("getMatter");
CL_DEFMETHOD Matter_sp getMatter() { return this->_Matter;};
Expand Down Expand Up @@ -326,9 +276,10 @@ namespace chem {
void addTermsForListOfRestraints( ForceField_sp forceField, core::List_sp restraintList, core::T_sp keepInteractionFactory, core::HashTable_sp atomTypes );


double calculateNumericalDerivative(NVector_sp pos, double delta, uint i, core::T_sp activeAtomMask );
double calculateNumericalSecondDerivative(NVector_sp pos, double delta, uint i, uint j, core::T_sp activeAtomMask );
double calculateNumericalDerivative(NVector_sp pos, core::T_sp energyScale, double delta, uint i, core::T_sp activeAtomMask );
double calculateNumericalSecondDerivative(NVector_sp pos, core::T_sp energyScale, double delta, uint i, uint j, core::T_sp activeAtomMask );
double evaluateAll(NVector_sp pos,
core::T_sp energyScale,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
Expand All @@ -348,8 +299,8 @@ namespace chem {
// adapt::QDomNode_sp accumulateTermsBeyondThresholdAsXml();
uint countTermsBeyondThreshold();

void evaluateNumericalForce(NVector_sp pos, NVector_sp numForce, double delta, core::T_sp activeAtomMask );
void evaluateNumericalHessian(NVector_sp pos, AbstractLargeSquareMatrix_sp numHessian, bool calcOffDiagonalElements, double delta, core::T_sp activeAtomMask);
void evaluateNumericalForce(NVector_sp pos, core::T_sp energyScale, NVector_sp numForce, double delta, core::T_sp activeAtomMask );
void evaluateNumericalHessian(NVector_sp pos, core::T_sp energyScale, AbstractLargeSquareMatrix_sp numHessian, bool calcOffDiagonalElements, double delta, core::T_sp activeAtomMask);

core::List_sp checkForBeyondThresholdInteractions(double threshold);

Expand Down
57 changes: 32 additions & 25 deletions include/cando/chem/energyNonbond.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct to_object<chem::EnergyNonbond>

namespace chem {

double _evaluateEnergyOnly_Nonbond(ScoringFunction_sp score,
double _evaluateEnergyOnly_Nonbond(ScoringFunction_sp score, core::T_sp energyScale,
int I1, int I2, core::T_sp activeAtomMask,
num_real x1, num_real y1, num_real z1,
num_real x2, num_real y2, num_real z2,
Expand Down Expand Up @@ -219,35 +219,38 @@ class EnergyNonbond_O : public EnergyComponent_O
void verifyExcludedAtoms(Matter_sp matter, ScoringFunction_sp score);

virtual double evaluateAllComponent( ScoringFunction_sp scorer,
NVector_sp pos,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
bool calcDiagonalHessian,
bool calcOffDiagonalHessian,
gc::Nilable<AbstractLargeSquareMatrix_sp> hessian,
gc::Nilable<NVector_sp> hdvec,
gc::Nilable<NVector_sp> dvec,
core::T_sp activeAtomMask,
core::T_sp debugInteractions );
NVector_sp pos,
core::T_sp energyScale,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
bool calcDiagonalHessian,
bool calcOffDiagonalHessian,
gc::Nilable<AbstractLargeSquareMatrix_sp> hessian,
gc::Nilable<NVector_sp> hdvec,
gc::Nilable<NVector_sp> dvec,
core::T_sp activeAtomMask,
core::T_sp debugInteractions );

double debugAllComponent( ScoringFunction_sp scorer,
NVector_sp pos,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
bool calcDiagonalHessian,
bool calcOffDiagonalHessian,
gc::Nilable<AbstractLargeSquareMatrix_sp> hessian,
gc::Nilable<NVector_sp> hdvec,
gc::Nilable<NVector_sp> dvec,
core::T_sp activeAtomMask,
core::T_sp debugInteractions );
NVector_sp pos,
core::T_sp energyScale,
core::T_sp componentEnergy,
bool calcForce,
gc::Nilable<NVector_sp> force,
bool calcDiagonalHessian,
bool calcOffDiagonalHessian,
gc::Nilable<AbstractLargeSquareMatrix_sp> hessian,
gc::Nilable<NVector_sp> hdvec,
gc::Nilable<NVector_sp> dvec,
core::T_sp activeAtomMask,
core::T_sp debugInteractions );
virtual void compareAnalyticalAndNumericalForceAndHessianTermByTerm( ScoringFunction_sp score,
NVector_sp pos,
core::T_sp energyScale,
core::T_sp activeAtomMask );

void expandExcludedAtomsToTerms(ScoringFunction_sp score);
void expandExcludedAtomsToTerms(ScoringFunction_sp score, core::T_sp energyScale );

virtual string beyondThresholdInteractionsAsString();

Expand Down Expand Up @@ -280,7 +283,11 @@ class EnergyNonbond_O : public EnergyComponent_O
{};
};

EnergyFunction_sp energyFunctionNonbondParameters(ScoringFunction_sp score, double& dielectricConstant, double& dQ1Q2Scale, double& cutoff );
EnergyFunction_sp energyFunctionNonbondParameters(ScoringFunction_sp score,
core::T_sp energyScale,
double& dielectricConstant,
double& dQ1Q2Scale,
double& cutoff );

};

Expand Down
Loading

0 comments on commit fe876bc

Please sign in to comment.