Skip to content

Commit

Permalink
Add pre-commit config, lint with Black 22.1.0 (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson authored Feb 21, 2022
1 parent 5c6f65d commit 89e9043
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 37 deletions.
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ci:
autoupdate_schedule: "monthly"
repos:
- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
files: (^openff|^integration-tests)
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
files: (^openff|^integration-tests)
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
files: (^openff|^integration-tests)
2 changes: 1 addition & 1 deletion openff/evaluator/properties/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class ExcessMolarVolume(EstimableExcessProperty):

@classmethod
def default_unit(cls):
return unit.centimeter ** 3 / unit.mole
return unit.centimeter**3 / unit.mole

@classmethod
def _observable_type(cls) -> ObservableType:
Expand Down
2 changes: 1 addition & 1 deletion openff/evaluator/protocols/reweighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def _compute_effective_samples(
.magnitude
)

effective_samples = 1.0 / np.sum(weights ** 2)
effective_samples = 1.0 / np.sum(weights**2)
return float(effective_samples)

def _execute(self, directory, available_resources):
Expand Down
8 changes: 4 additions & 4 deletions openff/evaluator/tests/test_datasets/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def test_to_pandas():
thermodynamic_state=thermodynamic_state,
phase=PropertyPhase.Liquid,
substance=binary_substance,
value=1 * unit.meter ** 3 / unit.mole,
uncertainty=0.11 * unit.meter ** 3 / unit.mole,
value=1 * unit.meter**3 / unit.mole,
uncertainty=0.11 * unit.meter**3 / unit.mole,
source=source,
)

Expand Down Expand Up @@ -171,8 +171,8 @@ def test_from_pandas():
thermodynamic_state=thermodynamic_state,
phase=PropertyPhase.Liquid,
substance=Substance.from_components("CO", "O"),
value=1.0 * unit.kilogram / unit.meter ** 3,
uncertainty=1.0 * unit.kilogram / unit.meter ** 3,
value=1.0 * unit.kilogram / unit.meter**3,
uncertainty=1.0 * unit.kilogram / unit.meter**3,
source=MeasurementSource(doi="10.5281/zenodo.596537"),
),
EnthalpyOfVaporization(
Expand Down
2 changes: 1 addition & 1 deletion openff/evaluator/tests/test_layers/test_reweighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_storage_retrieval():
thermodynamic_state=state,
),
ExcessMolarVolume(
value=1.0 * unit.meter ** 3, substance=mixture, thermodynamic_state=state
value=1.0 * unit.meter**3, substance=mixture, thermodynamic_state=state
),
]
expected_data_per_property = {
Expand Down
4 changes: 2 additions & 2 deletions openff/evaluator/tests/test_protocols/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_average_dielectric_constant():
np.zeros((1, 3)) * unit.elementary_charge * unit.nanometer
)
average_observable.volumes = ObservableArray(
np.ones((1, 1)) * unit.nanometer ** 3
np.ones((1, 1)) * unit.nanometer**3
)
average_observable.thermodynamic_state = ThermodynamicState(
298.15 * unit.kelvin, 1.0 * unit.atmosphere
Expand Down Expand Up @@ -175,7 +175,7 @@ def test_decorrelate_observables():

protocol = DecorrelateObservables("")
protocol.input_observables = ObservableArray(
np.ones((10, 1)) * unit.nanometer ** 3
np.ones((10, 1)) * unit.nanometer**3
)
protocol.time_series_statistics = TimeSeriesStatistics(10, 4, 2.0, 2)
protocol.execute(temporary_directory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_reweight_dielectric_constant():
value=np.zeros((10, 3)) * unit.elementary_charge * unit.nanometers
)
reweight_protocol.volumes = ObservableArray(
value=np.ones((10, 1)) * unit.nanometer ** 3
value=np.ones((10, 1)) * unit.nanometer**3
)
reweight_protocol.reference_reduced_potentials = [
ObservableArray(value=np.zeros(10) * unit.dimensionless)
Expand Down
8 changes: 4 additions & 4 deletions openff/evaluator/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_same_component_batching():
Density(
thermodynamic_state=thermodynamic_state,
substance=Substance.from_components("O", "C"),
value=0.0 * unit.kilogram / unit.meter ** 3,
value=0.0 * unit.kilogram / unit.meter**3,
),
EnthalpyOfVaporization(
thermodynamic_state=thermodynamic_state,
Expand All @@ -135,7 +135,7 @@ def test_same_component_batching():
Density(
thermodynamic_state=thermodynamic_state,
substance=Substance.from_components("O", "CO"),
value=0.0 * unit.kilogram / unit.meter ** 3,
value=0.0 * unit.kilogram / unit.meter**3,
),
EnthalpyOfVaporization(
thermodynamic_state=thermodynamic_state,
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_shared_component_batching():
Density(
thermodynamic_state=thermodynamic_state,
substance=Substance.from_components("O", "C"),
value=0.0 * unit.kilogram / unit.meter ** 3,
value=0.0 * unit.kilogram / unit.meter**3,
),
EnthalpyOfVaporization(
thermodynamic_state=thermodynamic_state,
Expand All @@ -182,7 +182,7 @@ def test_shared_component_batching():
Density(
thermodynamic_state=thermodynamic_state,
substance=Substance.from_components("O", "CO"),
value=0.0 * unit.kilogram / unit.meter ** 3,
value=0.0 * unit.kilogram / unit.meter**3,
),
EnthalpyOfVaporization(
thermodynamic_state=thermodynamic_state,
Expand Down
20 changes: 10 additions & 10 deletions openff/evaluator/tests/test_utils/test_observables.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,10 @@ def test_subtract_observables(value_a, value_b, expected_value):
object_type,
),
_mock_observable(
8.0 * unit.kelvin ** 2,
8.0 * unit.kelvin**2,
[
("vdW", "[#1:1]", "epsilon", 20.0 * unit.kelvin ** 2),
("vdW", "[#6:1]", "epsilon", 16.0 * unit.kelvin ** 2),
("vdW", "[#1:1]", "epsilon", 20.0 * unit.kelvin**2),
("vdW", "[#6:1]", "epsilon", 16.0 * unit.kelvin**2),
],
object_type,
),
Expand All @@ -722,10 +722,10 @@ def test_subtract_observables(value_a, value_b, expected_value):
object_type,
),
_mock_observable(
8.0 * unit.kelvin ** 2,
8.0 * unit.kelvin**2,
[
("vdW", "[#1:1]", "epsilon", 4.0 * unit.kelvin ** 2),
("vdW", "[#6:1]", "epsilon", 8.0 * unit.kelvin ** 2),
("vdW", "[#1:1]", "epsilon", 4.0 * unit.kelvin**2),
("vdW", "[#6:1]", "epsilon", 8.0 * unit.kelvin**2),
],
object_type,
),
Expand Down Expand Up @@ -954,7 +954,7 @@ def test_frame_magic_functions(key):
{"Temperature": ObservableArray(value=numpy.ones(2) * unit.kelvin)}
),
"Volume",
numpy.ones(1) * unit.nanometer ** 3,
numpy.ones(1) * unit.nanometer**3,
pytest.raises(ValueError),
"The length of the data (1) must match the length of the data already in "
"the frame (2).",
Expand Down Expand Up @@ -1002,7 +1002,7 @@ def test_frame_from_openmm(pressure):
ObservableType.KineticEnergy: 5939.683117957521 * unit.kilojoule / unit.mole,
ObservableType.TotalEnergy: 13874.51498645249 * unit.kilojoule / unit.mole,
ObservableType.Temperature: 286.38157154881503 * unit.kelvin,
ObservableType.Volume: 26.342326662784938 * unit.nanometer ** 3,
ObservableType.Volume: 26.342326662784938 * unit.nanometer**3,
ObservableType.Density: 0.6139877476363793 * unit.gram / unit.milliliter,
}

Expand All @@ -1014,7 +1014,7 @@ def test_frame_from_openmm(pressure):
13874.51498645249 * unit.kilojoule / unit.mole
+ pressure
* 26.342326662784938
* unit.nanometer ** 3
* unit.nanometer**3
* unit.avogadro_constant
)
assert numpy.isclose(observable_frame["Enthalpy"].value[0], expected_enthalpy)
Expand Down Expand Up @@ -1105,7 +1105,7 @@ def test_frame_join():
ObservableFrame(
{
"Volume": ObservableArray(
value=numpy.ones(2) * unit.nanometer ** 3
value=numpy.ones(2) * unit.nanometer**3
)
}
),
Expand Down
4 changes: 2 additions & 2 deletions openff/evaluator/utils/observables.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ class ObservableFrame(MutableMapping[Union[str, ObservableType], ObservableArray
ObservableType.KineticEnergy: unit.kilojoules / unit.mole,
ObservableType.TotalEnergy: unit.kilojoules / unit.mole,
ObservableType.Temperature: unit.kelvin,
ObservableType.Volume: unit.nanometer ** 3,
ObservableType.Volume: unit.nanometer**3,
ObservableType.Density: unit.gram / unit.milliliter,
ObservableType.Enthalpy: unit.kilojoules / unit.mole,
ObservableType.ReducedPotential: unit.dimensionless,
Expand Down Expand Up @@ -687,7 +687,7 @@ def from_openmm(
"Kinetic Energy (kJ/mole)": unit.kilojoules / unit.mole,
"Total Energy (kJ/mole)": unit.kilojoules / unit.mole,
"Temperature (K)": unit.kelvin,
"Box Volume (nm^3)": unit.nanometer ** 3,
"Box Volume (nm^3)": unit.nanometer**3,
"Density (g/mL)": unit.gram / unit.milliliter,
}

Expand Down
2 changes: 1 addition & 1 deletion openff/evaluator/utils/packmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _approximate_box_size_by_density(
A list of the three box lengths in units compatible with angstroms.
"""

volume = 0.0 * unit.angstrom ** 3
volume = 0.0 * unit.angstrom**3

for (molecule, number) in zip(molecules, n_copies):

Expand Down
17 changes: 7 additions & 10 deletions openff/evaluator/utils/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,14 @@ def _statistical_inefficiency(

while current_timestep < number_of_timesteps - 1:

autocorrelation_function = (
autocorrelation_function = np.sum(
np.sum(
np.sum(
time_series_shifted[0 : (number_of_timesteps - current_timestep)]
* time_series_shifted[current_timestep:number_of_timesteps],
axis=1,
),
axis=0,
)
/ (float(number_of_timesteps - current_timestep) * sigma_squared)
)
time_series_shifted[0 : (number_of_timesteps - current_timestep)]
* time_series_shifted[current_timestep:number_of_timesteps],
axis=1,
),
axis=0,
) / (float(number_of_timesteps - current_timestep) * sigma_squared)

if autocorrelation_function <= 0.0 and current_timestep > minimum_samples:
break
Expand Down

0 comments on commit 89e9043

Please sign in to comment.