Skip to content

Commit

Permalink
Merge pull request #66 from pcdshub/60-add-cctbx-class
Browse files Browse the repository at this point in the history
60 add cctbx class
  • Loading branch information
themindatlarge authored Aug 16, 2024
2 parents af7bbcd + 869535b commit 12dd7a6
Show file tree
Hide file tree
Showing 32 changed files with 483 additions and 562 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ logs
# Ignore generated database file
mfx/db.txt

# Ignore changed presets
presets/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
195 changes: 119 additions & 76 deletions mfx/bash_utilities.py
Original file line number Diff line number Diff line change
@@ -1,78 +1,121 @@
def xfel_gui():
import subprocess
import logging
from mfx.macros import get_exp

logging.info("Checking xfel gui phil File")
cctbx_settings = open("/cds/home/opr/mfxopr/.cctbx.xfel/settings_old.phil", "r", encoding="UTF-8")
setting_lines = cctbx_settings.readlines()
change = False

if setting_lines[10] != f'name = "{get_exp()}"':
logging.warning(f"Changing experiment to current: {get_exp()}")
setting_lines[10] = f' name = "{get_exp()}"\n'
change = True

if setting_lines[11] != f'user = "{get_exp()}"':
logging.warning(f"Changing experiment to current: {get_exp()}")
setting_lines[11] = f' user = "{get_exp()}"\n'
change = True

if change:
cctbx_settings = open("/cds/home/opr/mfxopr/.cctbx.xfel/settings.phil", "w", encoding="UTF-8")
cctbx_settings.writelines(setting_lines)
cctbx_settings.close
cctbx_settings = open("/cds/home/opr/mfxopr/.cctbx.xfel/settings_old.phil", "w", encoding="UTF-8")
cctbx_settings.writelines(setting_lines)
cctbx_settings.close

subprocess.Popen(
[". /reg/g/cctbx/brewster/working/build/conda_setpaths.sh;cctbx.xfel &"],
shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
class bs:
def xfel_gui(self):
import subprocess
import logging
from mfx.macros import get_exp

logging.info("Checking xfel gui phil File")
cctbx_settings = open("/cds/home/opr/mfxopr/.cctbx.xfel/settings_old.phil", "r", encoding="UTF-8")
setting_lines = cctbx_settings.readlines()
change = False

if setting_lines[10] != f'name = "{get_exp()}"':
logging.warning(f"Changing experiment to current: {get_exp()}")
setting_lines[10] = f' name = "{get_exp()}"\n'
change = True

if setting_lines[11] != f'user = "{get_exp()}"':
logging.warning(f"Changing experiment to current: {get_exp()}")
setting_lines[11] = f' user = "{get_exp()}"\n'
change = True

if change:
cctbx_settings = open("/cds/home/opr/mfxopr/.cctbx.xfel/settings.phil", "w", encoding="UTF-8")
cctbx_settings.writelines(setting_lines)
cctbx_settings.close
cctbx_settings = open("/cds/home/opr/mfxopr/.cctbx.xfel/settings_old.phil", "w", encoding="UTF-8")
cctbx_settings.writelines(setting_lines)
cctbx_settings.close

subprocess.Popen(
[". /reg/g/cctbx/brewster/working/build/conda_setpaths.sh;cctbx.xfel &"],
shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)


def takepeds(self):
import os
import logging
logging.info("Taking Pedestals")
os.system(f"/reg/g/pcds/engineering_tools/latest-released/scripts/takepeds")


def makepeds(self, username, run_number=None):
import os
import logging
from mfx.db import daq
from mfx.macros import get_exp
logging.info("Making Pedestals")
if run_number is None:
run_number = daq.run_number()
username = str(username)
run_number = str(int(run_number))
os.system(f"ssh -Y {username}@s3dflogin ssh -Y psana /sdf/group/lcls/ds/tools/engineering_tools/engineering_tools/scripts/makepeds_psana --queue milano --run {run_number} --experiment {get_exp()}")


def awr(self, hutch='mfx'):
import os
import logging
logging.info(f"{hutch} Beamline Check")
os.system(f"/cds/home/opr/mfxopr/bin/awr {hutch}")


def restartdaq(self):
import subprocess
import logging
logging.info("Restarting the DAQ")
subprocess.Popen(
["/reg/g/pcds/engineering_tools/latest-released/scripts/restartdaq -w"],
shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)


def cameras(self, time=12):
import subprocess
import logging
logging.info("Opening Cam Viewer")
subprocess.Popen(
[f"/reg/g/pcds/engineering_tools/latest-released/scripts/camViewer -w {time}"],
shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)


def camera_list(self):
import re
import logging
logging.info("Opening Camera List")
camlist = open("/reg/g/pcds/pyps/config/mfx/camviewer.cfg", "r", encoding="UTF-8")
cam_list = camlist.readlines()
avail_cams = [cam for cam in cam_list if cam.startswith('GE')]
self.camera_names = [['camera_name', 'camera_pv']]
print("Available Cameras")
for cam in avail_cams:
cam = re.split(';|,', cam)
self.camera_names.append([cam[4].strip(),cam[2]])
print(f"Camera {cam[4].strip()} .... {cam[2]}")


def focus_scan(self, camera):
import os
import sys
import logging
logging.info(
"Preparing for Focus Scan\n"
"Please check the following\n"
"One of the following cameras is selected\n\n")
self.camera_list()
logging.info(
"\nCamera orientation set to none\n"
"Slits are open\n"
"Blue crosshair in upper left corner\n"
"Red crosshair in bottom right corner\n")

input("Press Enter to continue...")

if camera not in [pv[1] for pv in self.camera_names]:
logging.info("Desired Camera not in List. Software will exit.")
sys.exit()

logging.info("Checking Focus Scan Plot")
os.system(f"/cds/home/opr/mfxopr/bin/focus_scan {camera} -p")
input("Press Enter to continue...")

def takepeds():
import os
import logging
logging.info("Taking Pedestals")
os.system(f"/reg/g/pcds/engineering_tools/latest-released/scripts/takepeds")


def makepeds(username, run_number=None):
import os
import logging
from mfx.db import daq
from mfx.macros import get_exp
logging.info("Making Pedestals")
if run_number is None:
run_number = daq.run_number()
username = str(username)
run_number = str(int(run_number))
os.system(f"ssh -Y {username}@s3dflogin ssh -Y psana /sdf/group/lcls/ds/tools/engineering_tools/engineering_tools/scripts/makepeds_psana --queue milano --run {run_number} --experiment {get_exp()}")


def awr(hutch='mfx'):
import os
import logging
logging.info(f"{hutch} Beamline Check")
os.system(f"/cds/home/opr/mfxopr/bin/awr {hutch}")


def restartdaq():
import subprocess
import logging
logging.info("Restarting the DAQ")
subprocess.Popen(
["/reg/g/pcds/engineering_tools/latest-released/scripts/restartdaq -w"],
shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
#os.system("/reg/g/pcds/engineering_tools/latest-released/scripts/restartdaq -w")


def cameras(time=12):
import subprocess
import logging
logging.info("Opening Cam Viewer")
subprocess.Popen(
[f"/reg/g/pcds/engineering_tools/latest-released/scripts/camViewer -w {time}"],
shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
#os.system(f"/reg/g/pcds/engineering_tools/latest-released/scripts/camViewer -w {time}")
logging.info("Running Focus Scan")
os.system(f"/cds/home/opr/mfxopr/bin/focus_scan {camera} -s")
7 changes: 6 additions & 1 deletion mfx/beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from pcdsdevices.sequencer import EventSequencer
sequencer = EventSequencer('ECS:SYS0:7', name='mfx_sequencer')
mfx_sequencer = sequencer
sequencer2 = EventSequencer('ECS:SYS0:12', name='mfx_sequencer_spare')
mfx_sequencer_spare = sequencer2

with safe_load('rayonix utils'):
from mfx.rayonix import Rayonix
Expand All @@ -37,10 +39,12 @@

with safe_load('macros'):
from mfx.macros import *

with safe_load('MFX_Timing'):
from mfx.mfx_timing import *
mfx_timing = MFX_Timing(sequencer)

with safe_load('Droplet_on_Demand'):
# from mfx.mfxDOD import *
from mfx.mfx_dod import *

with safe_load('delay_scan'):
Expand Down Expand Up @@ -73,6 +77,7 @@

with safe_load('bash_utilities'):
from mfx.bash_utilities import *
bs = bs()

with safe_load('cctbx'):
from mfx.cctbx import *
Expand Down
89 changes: 29 additions & 60 deletions mfx/cctbx.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,50 @@
class cctbx:
def __init__(self):
from mfx.macros import get_exp
self.settings = "~/.cctbx.xfe/settings_old.phil"
self.experiment = str(get_exp())


def check_settings(self, user):
def xfel_gui(self, user):
import logging
import subprocess
exp = self.experiment
logging.info("Checking xfel gui phil File")
cctbx_settings = open("/cds/home/opr/mfxopr/.cctbx.xfel/settings_s3df.phil", "r", encoding="UTF-8")
setting_lines = cctbx_settings.readlines()
change = False
if setting_lines[4] != f'experiment = "{exp}"':
logging.warning(f"Changing experiment to current: {exp}")
change = True
settings = f'''\
facility {{
name = *lcls standalone
lcls {{
experiment = "{exp}"
web {{
location = "S3DF"
}}
}}
}}
output_folder = "/sdf/data/lcls/ds/mfx/{exp}/results/common/results"
mp {{
method = local lsf sge pbs *slurm shifter htcondor custom
nnodes_index = 2
nnodes_scale = 1
nnodes_merge = 1
nproc_per_node = 120
queue = "milano"
extra_options = " --account=lcls:{exp} --reservation=lcls:onshift"
env_script = "/sdf/group/lcls/ds/tools/cctbx/build/conda_setpaths.sh"
phenix_script = "/sdf/group/lcls/ds/tools/cctbx/phenix/phenix-1.20.1-4487/phenix_env.sh"
}}
experiment_tag = "common"
db {{
host = "172.24.5.182"
name = "{exp}"
user = "{exp}"
}}\
'''
if change:
cctbx_settings = open("/cds/home/opr/mfxopr/.cctbx.xfel/settings_s3df.phil", "w", encoding="UTF-8")
cctbx_settings.writelines(settings)
cctbx_settings.close
self.settings = f"/sdf/home/{user[0]}/{user}/.cctbx.xfel/settings.phil"
self.cctbx_dir = f"/sdf/home/{user[0]}/{user}"

subprocess.Popen(
[f"rsync -avze ssh ~/.cctbx.xfel/settings_s3df.phil {user}@s3dflogin:~/.cctbx.xfel/settings_old.phil"],
shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
proc = [
f"ssh -YAC {user}@s3dflogin "
f"/sdf/home/d/djr/scripts/cctbx_step1.sh {user} {self.experiment}"
]

logging.info(proc)

subprocess.Popen(
proc, shell=True,
stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)

def xfel_gui(self, user):

def notch_check(self, user, runs=[]):
import logging
import subprocess
import os

#cctbx_dir =
if not os.path.exists(out_result):
os.makedirs(out_result)
import sys
if len(runs) > 0:
run_list = []
for run in runs:
run_list.append(f'{experiment}:{run}')
logging.info(f'Selected runs: {run_list}')
runlist = ' '
runlist = runlist.join(run_list)
logging.info(f'Selected runs: {runlist}')
else:
logging.warning(f'No selected runs. Program will exit.')
sys.exit()

proc = [
f"ssh -YAC mfxopr@daq-mfx-mon0{str(node)} "
f"/cds/group/pcds/pyps/apps/hutch-python/mfx/scripts/"
f"detector_image.sh {experiment} {str(det)} {str(calibdir)} {str(ave)}"
f'ssh -YAC {user}@s3dflogin '
f'/sdf/home/d/djr/scripts/cctbx_notch_check.sh "{self.runlist}"'
]

logging.info(proc)

subprocess.Popen(
proc, shell=True,
stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)

subprocess.Popen(
[". /reg/g/cctbx/brewster/working/build/conda_setpaths.sh;cctbx.xfel &"],
shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
Loading

0 comments on commit 12dd7a6

Please sign in to comment.