Skip to content

Commit faddcfb

Browse files
committed
Lazy-init EnergyCalculator and LJEnergyCalculator in energy features
1 parent 48cb681 commit faddcfb

7 files changed

Lines changed: 6 additions & 64 deletions

File tree

src/main/groovy/cz/siret/prank/features/implementation/energy/MethylEnergyCloudSF.groovy

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ class MethylEnergyCloudSF extends SasFeatureCalculator implements Parametrized {
2727
// Immutable calculator instance
2828
private LJEnergyCalculator calculator
2929

30-
MethylEnergyCloudSF() {
31-
// TODO re-init with new params before each run
32-
initializeCalculator()
33-
}
34-
35-
/**
36-
* Initialize the feature with the energy calculator
37-
*/
3830
@Override
3931
void preProcessProtein(Protein protein, ProcessedItemContext itemContext) {
4032
initializeCalculator()

src/main/groovy/cz/siret/prank/features/implementation/energy/MethylEnergyCloudX2FullSF.groovy

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ class MethylEnergyCloudX2FullSF extends SasFeatureCalculator implements Parametr
2929
// Immutable calculator instance
3030
private LJEnergyCalculator calculator
3131

32-
MethylEnergyCloudX2FullSF() {
33-
// TODO re-init with new params before each run
34-
initializeCalculator()
35-
}
36-
37-
/**
38-
* Initialize the feature with the energy calculator
39-
*/
4032
@Override
4133
void preProcessProtein(Protein protein, ProcessedItemContext itemContext) {
4234
initializeCalculator()

src/main/groovy/cz/siret/prank/features/implementation/energy/MethylEnergyCloudX2SF.groovy

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ class MethylEnergyCloudX2SF extends SasFeatureCalculator implements Parametrized
2929
// Immutable calculator instance
3030
private LJEnergyCalculator calculator
3131

32-
MethylEnergyCloudX2SF() {
33-
// TODO re-init with new params before each run
34-
initializeCalculator()
35-
}
36-
37-
/**
38-
* Initialize the feature with the energy calculator
39-
*/
4032
@Override
4133
void preProcessProtein(Protein protein, ProcessedItemContext itemContext) {
4234
initializeCalculator()

src/main/groovy/cz/siret/prank/features/implementation/energy/MethylEnergyCloudXFullSF.groovy

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ class MethylEnergyCloudXFullSF extends SasFeatureCalculator implements Parametri
2929
// Immutable calculator instance
3030
private LJEnergyCalculator calculator
3131

32-
MethylEnergyCloudXFullSF() {
33-
// TODO re-init with new params before each run
34-
initializeCalculator()
35-
}
36-
37-
/**
38-
* Initialize the feature with the energy calculator
39-
*/
4032
@Override
4133
void preProcessProtein(Protein protein, ProcessedItemContext itemContext) {
4234
initializeCalculator()

src/main/groovy/cz/siret/prank/features/implementation/energy/MethylEnergyCloudXSF.groovy

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ class MethylEnergyCloudXSF extends SasFeatureCalculator implements Parametrized
2929
// Immutable calculator instance
3030
private LJEnergyCalculator calculator
3131

32-
MethylEnergyCloudXSF() {
33-
// TODO re-init with new params before each run
34-
initializeCalculator()
35-
}
36-
37-
/**
38-
* Initialize the feature with the energy calculator
39-
*/
4032
@Override
4133
void preProcessProtein(Protein protein, ProcessedItemContext itemContext) {
4234
initializeCalculator()

src/main/groovy/cz/siret/prank/features/implementation/energy/MethylEnergyFeature.groovy

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,11 @@ class MethylEnergyFeature extends SasFeatureCalculator implements Parametrized {
2222
// Immutable calculator instance
2323
private LJEnergyCalculator calculator
2424

25-
MethylEnergyFeature() {
26-
// TODO re-init with new params before each run
27-
initializeCalculator()
28-
}
29-
30-
// /**
31-
// * Initialize the feature with the energy calculator
32-
// */
33-
// @Override
34-
// void preProcessProtein(Protein protein, ProcessedItemContext itemContext) {
35-
// initializeCalculator()
36-
// }
37-
38-
39-
4025
/**
41-
* Initialize the energy calculator with current parameters
26+
* Initialize the energy calculator with current parameters (lazy, called on first use per protein).
4227
*/
43-
private void initializeCalculator() {
28+
private void ensureCalculatorInitialized() {
29+
if (calculator != null) return
4430
calculator = new LJEnergyCalculator(
4531
params.energy_probe_sigma,
4632
params.energy_probe_epsilon,
@@ -63,8 +49,8 @@ class MethylEnergyFeature extends SasFeatureCalculator implements Parametrized {
6349
*/
6450
@Override
6551
double[] calculateForSasPoint(Atom sasPoint, SasFeatureCalculationContext context) {
52+
ensureCalculatorInitialized()
6653

67-
// try {
6854
// Get neighbor atoms around the SAS point
6955
//Atoms neighbourAtoms = context.extractor.deepLayer.cutoutSphere(sasPoint, params.energy_rc)
7056
Atoms neighbourAtoms = context.neighbourhoodAtoms

src/main/groovy/cz/siret/prank/features/implementation/energy2/AbstractProbeEnergyFeature.groovy

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,9 @@ import static cz.siret.prank.utils.MathUtils.nanToZero
2727
@CompileStatic
2828
abstract class AbstractProbeEnergyFeature extends SasFeatureCalculator implements Parametrized {
2929

30-
// Immutable calculator instance
3130
protected EnergyCalculator calculator
3231
protected EnergyCalculatorConfig config
3332

34-
AbstractProbeEnergyFeature() {
35-
initializeCalculator()
36-
}
37-
3833
/**
3934
* Get the probe type that this feature calculates
4035
*/
@@ -46,7 +41,8 @@ abstract class AbstractProbeEnergyFeature extends SasFeatureCalculator implement
4641
abstract String getSecondaryDataKey()
4742

4843
/**
49-
* Initialize the energy calculator with current parameters and specific probe selection
44+
* Initialize the energy calculator with current parameters and specific probe selection.
45+
* Called lazily from preProcessProtein before first use.
5046
*/
5147
protected void initializeCalculator() {
5248
// Create config with only the specific probe type selected

0 commit comments

Comments
 (0)