Skip to content

Commit

Permalink
Use openff-forcebalance for optimizations
Browse files Browse the repository at this point in the history
Use shell trick

Update test environment

Update `forcebalance` imports

Update more imports

Test against qdata patch

Tidy conda environments

Tidy environments
  • Loading branch information
mattwthompson committed Jan 26, 2023
1 parent 40e470a commit 3ee15cd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 47 deletions.
17 changes: 8 additions & 9 deletions devtools/conda-envs/no_openeye.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ dependencies:
- click-option-group
- rdkit >=22
- ambertools >=22
- openff-utilities
- openff-toolkit-base >=0.11.3
- openff-utilities
- openff-units
- openff-forcefields
- openff-qcsubmit
- openmm >=7.6.0

# Shim
- importlib-metadata >=4
- importlib_metadata >=4

# Optional
- forcebalance
- openff-fragmenter-base

### Bespoke dependencies
Expand All @@ -43,7 +39,6 @@ dependencies:
- chemper
- geometric <1
- torsiondrive
- pymbar

# Executor
- uvicorn
Expand All @@ -60,8 +55,12 @@ dependencies:
- pytest-cov
- pytest-asyncio
- pytest-celery
- pytest-xdist
- codecov
- requests-mock

- importlib-metadata >=4

# `openff-forcebalance` and dependencies
- pymbar =3
- lxml
- pip:
- git+https://github.com/openforcefield/openff-forcebalance.git@qc-io
20 changes: 9 additions & 11 deletions devtools/conda-envs/test-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,17 @@ dependencies:
- click
- click-option-group
- rdkit
- openff-utilities
- openff-toolkit-base >=0.11.3
- openff-forcefields
- openff-utilities
- openff-units
- openff-forcefields
- openff-qcsubmit
- openmm >=7.6.0

# Shim
- importlib-metadata >=4
- importlib_metadata >=4

# Optional
- forcebalance
- openff-fragmenter-base

- openeye-toolkits
- openff-fragmenter-base

### Bespoke dependencies

Expand All @@ -46,7 +41,6 @@ dependencies:
- chemper
- geometric <1
- torsiondrive
- pymbar

# Executor
- uvicorn
Expand All @@ -63,8 +57,12 @@ dependencies:
- pytest-cov
- pytest-asyncio
- pytest-celery
- pytest-xdist
- codecov
- requests-mock

- importlib-metadata >=4
- importlib_metadata >=4
# `openff-forcebalance` and dependencies
- pymbar =3
- lxml
- pip:
- git+https://github.com/openforcefield/openff-forcebalance.git@qc-io
6 changes: 3 additions & 3 deletions openff/bespokefit/optimizers/forcebalance/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _generate_target(
],
):

from forcebalance.molecule import Molecule as FBMolecule
from openff.forcebalance.molecule import Molecule as FBMolecule

if isinstance(target, AbInitioTargetSchema) and target.fit_force is True:
raise NotImplementedError()
Expand Down Expand Up @@ -528,7 +528,7 @@ def _generate_target(
qc_records: List[Tuple[Union[ResultRecord, "AtomicResult"], Molecule]],
):

from forcebalance.molecule import Molecule as FBMolecule
from openff.forcebalance.molecule import Molecule as FBMolecule

assert len(qc_records) == 1
qc_record, off_molecule = qc_records[0]
Expand Down Expand Up @@ -590,7 +590,7 @@ def _generate_target(
],
):

from forcebalance.molecule import Molecule as FBMolecule
from openff.forcebalance.molecule import Molecule as FBMolecule

record_names = []

Expand Down
10 changes: 5 additions & 5 deletions openff/bespokefit/optimizers/forcebalance/forcebalance.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def provenance(cls) -> Dict:
"""
Collect the provenance information for forcebalance.
"""
import forcebalance
import openff.forcebalance
import openff.toolkit

versions = {
"forcebalance": forcebalance.__version__,
"forcebalance": openff.forcebalance.__version__,
"openff.toolkit": openff.toolkit.__version__,
}

Expand All @@ -70,7 +70,7 @@ def provenance(cls) -> Dict:
@classmethod
def is_available(cls) -> bool:
try:
importlib.import_module("forcebalance")
importlib.import_module("openff.forcebalance")
return True
except ImportError:
return False
Expand Down Expand Up @@ -101,10 +101,10 @@ def _optimize(

with open("log.txt", "w") as log:

_logger.debug("Launching Forcebalance")
_logger.debug("Launching openff-forcebalance")

subprocess.run(
"ForceBalance optimize.in",
"openff-forcebalance optimize -i optimize.in",
shell=True,
stdout=log,
stderr=log,
Expand Down
19 changes: 2 additions & 17 deletions openff/bespokefit/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,9 @@ def bace() -> Molecule:
def clear_force_balance_caches():
"""A fixture which will clean the incredibly bug prone ``smirnoff_hack`` caches prior
to each test running."""
from openff.forcebalance.smirnoff_hack import use_caches

from forcebalance.smirnoff_hack import (
AT_TOOLKIT_CACHE_assign_partial_charges,
OE_TOOLKIT_CACHE_assign_partial_charges,
OE_TOOLKIT_CACHE_find_smarts_matches,
OE_TOOLKIT_CACHE_molecule_conformers,
RDK_TOOLKIT_CACHE_find_smarts_matches,
RDK_TOOLKIT_CACHE_molecule_conformers,
TOOLKIT_CACHE_ChemicalEnvironment_validate,
)

OE_TOOLKIT_CACHE_find_smarts_matches.clear()
RDK_TOOLKIT_CACHE_find_smarts_matches.clear()
TOOLKIT_CACHE_ChemicalEnvironment_validate.clear()
OE_TOOLKIT_CACHE_assign_partial_charges.clear()
AT_TOOLKIT_CACHE_assign_partial_charges.clear()
OE_TOOLKIT_CACHE_molecule_conformers.clear()
RDK_TOOLKIT_CACHE_molecule_conformers.clear()
use_caches()


@pytest.fixture(scope="module")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def test_forcebalance_provenance():
"""
Make sure the correct forcebalance version is returned.
"""
import forcebalance
import openff.forcebalance
import openff.toolkit

provenance = ForceBalanceOptimizer.provenance()

assert provenance["forcebalance"] == forcebalance.__version__
assert provenance["forcebalance"] == openff.forcebalance.__version__
assert provenance["openff.toolkit"] == openff.toolkit.__version__


Expand Down

0 comments on commit 3ee15cd

Please sign in to comment.