Skip to content

Commit

Permalink
added test_drones and test_files
Browse files Browse the repository at this point in the history
  • Loading branch information
rdguha1995 committed Jan 22, 2024
1 parent d1ca84a commit 88de216
Show file tree
Hide file tree
Showing 39 changed files with 60 additions and 34 deletions.
44 changes: 10 additions & 34 deletions src/atomate2/qchem/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def copy_qchem_outputs(
"""
Copy QChem output files to the current directory.
For folders containing multiple calculations (e.g., suffixed with opt1, opt2,
For folders containing multiple calculations (e.g., suffixed with opt_1, opt_2,
etc), this function will only copy the files with the highest numbered suffix
and the suffix will be removed. Additional qchem files will be also be copied
with the same suffix applied.
Expand Down Expand Up @@ -116,37 +116,13 @@ def get_largest_opt_extension(
opt_files = file_client.glob(Path(directory) / "*.opt*", host=host)
if len(opt_files) == 0:
return ""

numbers = [re.search(r".opt(\d+)", file.name).group(1) for file in opt_files]
numbers = []
for file in opt_files:
match = re.search(r"\.opt_(\d+)", file.name)
if match:
numbers.append(match.group(1))

if not numbers:
return "" # No matches found
max_relax = max(numbers, key=lambda x: int(x))
return f".opt{max_relax}"


# def write_qchem_input_set(
# molecule: Molecule,
# input_set_generator: QChemInputGenerator,
# directory: str | Path = ".",
# # from_prev: bool = False,
# **kwargs,
# ):
# """
# Write QChem input set.

# Parameters
# ----------
# molecule : .Molecule
# A molecule.
# input_set_generator : .QChemInputGenerator
# A QChem input set generator.
# directory : str or Path
# The directory to write the input files to.
# # from_prev : bool
# # Whether to initialize the input set from a previous calculation.
# **kwargs
# Keyword arguments that will be passed to :obj:`.QChemInputSet.write_input`.
# """
# # prev_dir = "." if from_prev else None
# qis = input_set_generator.get_input_set(molecule)

# logger.info("Writing QChem input set.")
# qis.write_input(directory, **kwargs)
return f".opt_{max_relax}"
7 changes: 7 additions & 0 deletions tests/qchem/test_drones.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from atomate2.qchem.drones import QChemDrone


def test_structure_optimization(qchem_test_dir):
drone = QChemDrone()
doc = drone.assimilate(qchem_test_dir / "water_single_point" / "outputs")
assert doc
43 changes: 43 additions & 0 deletions tests/qchem/test_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from pathlib import Path

import pytest

from atomate2.qchem.files import copy_qchem_outputs, get_largest_opt_extension


@pytest.mark.parametrize(
"files",
[
("custodian.json.gz","FW.json.gz"),
],
)
def test_copy_qchem_outputs_sp(qchem_test_dir, tmp_dir, files):
path = qchem_test_dir / "water_single_point" / "outputs"
copy_qchem_outputs(src_dir=path, additional_qchem_files=files)

for file in files:
assert Path(path / file).exists()


@pytest.mark.parametrize(
"files",
[
("custodian.json.gz","FW.json.gz"),
],
)
def test_copy_qchem_outputs_freq(qchem_test_dir, tmp_dir, files):
path = qchem_test_dir / "water_frequency" / "outputs"
copy_qchem_outputs(src_dir=path, additional_qchem_files=files)

for file in files:
assert Path(path / file).exists()


def test_get_largest_opt_extension(qchem_test_dir):
path = qchem_test_dir / "double_opt_test" / "outputs"
extension = get_largest_opt_extension(directory=path)
assert extension == ".opt_2"

path = qchem_test_dir / "water_single_point" / "static" / "outputs"
extension = get_largest_opt_extension(directory=path)
assert extension == ""
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 88de216

Please sign in to comment.