Skip to content

Commit

Permalink
Merge pull request #803 from MolSSI/rxn_fix
Browse files Browse the repository at this point in the history
Fix ordering bug in reactions
  • Loading branch information
bennybp authored Feb 27, 2024
2 parents 345b92c + f256b84 commit d4bb2f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 6 additions & 4 deletions qcfractal/qcfractal/components/reaction/record_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def iterate_service(
# of an optimization)
required_sp_mols = {x.molecule_id for x in rxn_orm.components if has_singlepoint}

complete_tasks = service_orm.dependencies

# What was already completed and/or submitted
sub_opt_mols = {x.molecule_id for x in rxn_orm.components if x.optimization_id is not None}
sub_sp_mols = {x.molecule_id for x in rxn_orm.components if x.singlepoint_id is not None}
Expand All @@ -135,6 +133,10 @@ def iterate_service(
# Singlepoint calculations must wait for optimizations
sp_mols_to_compute -= opt_mols_to_compute

# Convert to well-ordered lists
opt_mols_to_compute = list(opt_mols_to_compute)
sp_mols_to_compute = list(sp_mols_to_compute)

service_orm.dependencies = []
output = ""

Expand Down Expand Up @@ -168,11 +170,11 @@ def iterate_service(
if sp_mols_to_compute:
# If an optimization was specified, we need to get the final molecule from that
if has_optimization:
real_mols_to_compute = {
real_mols_to_compute = [
x.optimization_record.final_molecule_id
for x in rxn_orm.components
if x.molecule_id in sp_mols_to_compute
}
]
else:
real_mols_to_compute = sp_mols_to_compute

Expand Down
16 changes: 13 additions & 3 deletions qcportal/qcportal/reaction/test_record_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@


@pytest.mark.parametrize("includes", [None, all_includes])
def test_reactionrecord_model(snowflake: QCATestingSnowflake, includes: Optional[List[str]]):
@pytest.mark.parametrize("testfile", ["rxn_H2O_psi4_mp2_optsp", "rxn_H2O_psi4_mp2_opt", "rxn_H2O_psi4_b3lyp_sp"])
def test_reactionrecord_model(snowflake: QCATestingSnowflake, includes: Optional[List[str]], testfile: str):
storage_socket = snowflake.get_storage_socket()
snowflake_client = snowflake.client()
activated_manager_name, _ = snowflake.activate_manager()

input_spec, stoichiometry, results = load_test_data("rxn_H2O_psi4_mp2_optsp")
input_spec, stoichiometry, results = load_test_data(testfile)

rec_id = run_test_data(storage_socket, activated_manager_name, "rxn_H2O_psi4_mp2_optsp")
rec_id = run_test_data(storage_socket, activated_manager_name, testfile)
record = snowflake_client.get_reactions(rec_id, include=includes)

if includes is not None:
Expand All @@ -42,6 +43,15 @@ def test_reactionrecord_model(snowflake: QCATestingSnowflake, includes: Optional

for c in com:
if c.singlepoint_id is not None:
# Molecule id may represent the initial molecule for the optimization, not
# necessarily the single point calculation
if c.optimization_id is None:
assert c.singlepoint_record.molecule.id == c.molecule_id
else:
assert c.singlepoint_record.molecule.id == c.optimization_record.final_molecule.id

assert list(c.singlepoint_record.molecule.symbols) == list(c.molecule.symbols)
assert c.singlepoint_record.id == c.singlepoint_id
if c.optimization_id is not None:
assert c.optimization_record.initial_molecule.id == c.molecule_id
assert c.optimization_record.id == c.optimization_id

0 comments on commit d4bb2f0

Please sign in to comment.