Skip to content

Commit de5ed3b

Browse files
xiangchenjhuXiang Chen
andauthored
add-isomer-option (#92)
* add-isomer-option * format * update test case * format * restore --------- Co-authored-by: Xiang Chen <[email protected]>
1 parent 93ed163 commit de5ed3b

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

bluephos/bluephos_pipeline.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def get_pipeline(
152152
t_nn=1.5, # Threshold for 'z' score.
153153
t_ste=1.9, # Threshold for 'ste'.
154154
t_dft=2.5, # Threshold for 'dft'.
155+
isomer="fac", # default isomer
155156
):
156157
"""
157158
Set up and return the BluePhos discovery pipeline executor
@@ -175,6 +176,7 @@ def get_pipeline(
175176
"t_nn": t_nn,
176177
"t_ste": t_ste,
177178
"t_dft": t_dft,
179+
"isomer": isomer,
178180
}
179181

180182
for key, value in context_dict.items():
@@ -205,6 +207,12 @@ def get_pipeline(
205207
choices=["orca", "ase"],
206208
help="DFT package to use (default: orca)",
207209
)
210+
ap.add_argument(
211+
"--isomer",
212+
required=False,
213+
default="fac",
214+
help="Set the isomer type for the OptimizeGeometriesTask (e.g., mer, fac)",
215+
)
208216
args = ap.parse_args()
209217

210218
# Run the pipeline with the provided arguments
@@ -222,6 +230,7 @@ def get_pipeline(
222230
args.t_nn,
223231
args.t_ste,
224232
args.t_dft,
233+
args.isomer,
225234
),
226235
args,
227236
)

bluephos/tasks/optimizegeometries.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def calculate_ste(mol):
3434
return None
3535

3636

37-
def optimize(row, xtb):
37+
def optimize(row, xtb, isomer):
3838
mol_id = row["ligand_identifier"]
3939
ste = row["ste"]
4040

41-
# Log the values of z and ste for debugging
42-
logger.info(f"Processing molecule {mol_id} ...")
41+
# Log the value of isomer for debugging
42+
logger.info(f"Processing molecule {mol_id} with isomer '{isomer}'...")
4343

4444
# Skip processing if ste already existed (re-run condition)
4545
if ste is not None:
@@ -56,7 +56,6 @@ def optimize(row, xtb):
5656
return row # Return the updated row
5757

5858
mol = AddHs(Chem.MolFromMolBlock(mol))
59-
isomer = "fac" # Example isomer, can be dynamically set if needed
6059
mol_id = mol.GetProp("_Name") + f"_{isomer}"
6160
mol.SetProp("_Name", mol_id)
6261

@@ -105,13 +104,13 @@ def optimize(row, xtb):
105104
return row # Return the updated row
106105

107106

108-
def optimize_geometries(df: pd.DataFrame, xtb: bool) -> pd.DataFrame:
107+
def optimize_geometries(df: pd.DataFrame, xtb: bool, isomer: str) -> pd.DataFrame:
109108
for col in ["xyz", "ste", "xtb_walltime", "xyz_len"]:
110109
if col not in df.columns:
111110
df[col] = None
112111

113112
# Apply the optimize function to each row
114-
df = df.apply(optimize, axis=1, xtb=xtb)
113+
df = df.apply(optimize, axis=1, xtb=xtb, isomer=isomer)
115114

116115
return df
117116

@@ -121,6 +120,7 @@ def optimize_geometries(df: pd.DataFrame, xtb: bool) -> pd.DataFrame:
121120
optimize_geometries,
122121
context_kwargs={
123122
"xtb": "xtb",
123+
"isomer": "isomer",
124124
},
125125
batch_size=1,
126126
num_cpus=1,

tests/test_optimizegeometries_task.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ def test_optimize(mock_optimize_geometry, mock_octahedral_embed, setup_dataframe
3434
# Define a mock xtb argument
3535
mock_xtb = True
3636

37+
# Define a mock isomer argument
38+
mock_isomer = "fac"
39+
3740
# Run optimize
38-
output_dataframe = optimize_geometries(setup_dataframe, mock_xtb)
41+
output_dataframe = optimize_geometries(setup_dataframe, mock_xtb, mock_isomer)
3942

4043
# Check if XYZ data was added or set to failed
4144
assert output_dataframe.loc[0, "xyz"] is not None

0 commit comments

Comments
 (0)