Skip to content

Commit f759efa

Browse files
committed
Account for multiple visits per target (trigger_xchem)
1 parent 9a9d4c2 commit f759efa

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

src/dlstbx/services/trigger_xchem.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,13 @@ def trigger_pandda_xchem(
278278
# Find corresponding XChem visit directory and database
279279
xchem_dir = pathlib.Path(f"/dls/labxchem/data/{proposal_string}")
280280
yaml_files = []
281+
match_dirs = []
281282

282283
for subdir in xchem_dir.iterdir():
283284
user_yaml = subdir / ".user.yaml"
284285
if user_yaml.exists():
285286
yaml_files.append(user_yaml)
286287

287-
if not yaml_files:
288-
match = False
289-
290288
for yaml_file in yaml_files:
291289
with open(yaml_file, "r") as file:
292290
expt_yaml = yaml.load(file, Loader=yaml.SafeLoader)
@@ -295,12 +293,40 @@ def trigger_pandda_xchem(
295293
directory = yaml_file.parents[0]
296294
if acr == acronym:
297295
match = True
298-
match_dir = directory
296+
match_dirs.append(directory)
299297
# match_yaml = expt_yaml
300-
self.log.info(f"Found user yaml for dcid {dcid} at {yaml_file}")
301-
break
302-
else:
303-
match = False
298+
self.log.info(f"Found user yaml for dtag {dtag} at {yaml_file}")
299+
300+
if not match_dirs:
301+
match = False
302+
elif len(match_dirs) == 1:
303+
match_dir = match_dirs[0]
304+
elif (
305+
len(match_dirs) > 1
306+
): # account for potentially multiple labxchem visits for a single target
307+
for path in match_dirs:
308+
try:
309+
db_path = str(
310+
path / "processing/database" / "soakDBDataFile.sqlite"
311+
)
312+
conn = sqlite3.connect(
313+
f"file:{db_path}?mode=ro", uri=True, timeout=10
314+
)
315+
df = pd.read_sql_query(
316+
f"SELECT * from mainTable WHERE Puck = '{container_code}' AND PuckPosition = {location} AND CrystalName = '{dtag}'",
317+
conn,
318+
)
319+
conn.close()
320+
321+
if not df.empty:
322+
match_dir = path
323+
self.log.info(f"labxchem visit {path} found for dtag {dtag}")
324+
break
325+
326+
except Exception as e:
327+
self.log.info(
328+
f"Exception whilst reading ligand information from {db_path} for dtag {dtag}, dcid {dcid}: {e}"
329+
)
304330

305331
if not match:
306332
self.log.info(
@@ -335,7 +361,7 @@ def trigger_pandda_xchem(
335361
# match_yaml = expt_yaml
336362

337363
except Exception as e:
338-
print(f"Problem reading .sqlite database for {subdir}: {e}")
364+
self.log.info(f"Problem reading .sqlite database for {subdir}: {e}")
339365

340366
if not match:
341367
self.log.debug(

0 commit comments

Comments
 (0)