Skip to content

Instantly share code, notes, and snippets.

@belfhi
Last active April 18, 2018 08:23
Show Gist options
  • Save belfhi/0983e6414a1418eacc9dea5d9f438665 to your computer and use it in GitHub Desktop.
Save belfhi/0983e6414a1418eacc9dea5d9f438665 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from SimEx import *\n",
"from os.path import isfile, isdir\n",
"from os import getcwd, listdir\n",
"import inspect\n",
"from subprocess import Popen, call, PIPE\n",
"from ipywidgets import widgets\n",
"from IPython.display import display"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#sig = inspect.signature(PhotonBeamParameters.__init__)\n",
"#sig.parameters"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"beam = PhotonBeamParameters(\n",
" photon_energy = 4972.0*electronvolt, # photon energy in eV\n",
" beam_diameter_fwhm=1.3e-7*meter, # focus diameter in m\n",
" pulse_energy=0.45e-3*joule, # pulse energy in J\n",
" photon_energy_relative_bandwidth=0.003, # relative bandwidth dE/E\n",
" divergence=0.0*radian, # Beam divergence in rad\n",
" photon_energy_spectrum_type='tophat', # Spectrum type. Acceptable values are \"tophat\", \"SASE\", and \"twocolor\")\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Checking presence of 5udc.pdb. Will query from PDB if not found in $PWD.\n",
"Sample path is set to 5udc.pdb.\n"
]
}
],
"source": [
"parameters = CrystFELPhotonDiffractorParameters(\n",
" sample='5udc.pdb', # Looks up pdb file in cwd, if not found, queries from RCSB pdb mirror.\n",
" uniform_rotation=True, # Apply random rotation\n",
" number_of_diffraction_patterns=1, #\n",
" powder=False, # Set to True to create a virtual powder diffraction pattern (unested) \n",
" intensities_file=None, # File that contains reflection intensities. If set to none, use uniform intensity distribution\n",
" crystal_size_range=[1e-7,1e-7], # Range ([min,max]) in units of metres of crystal size.\n",
" poissonize=False, # Set to True to add Poisson noise.\n",
" number_of_background_photons=0, # Change number to add uniformly distributed background photons.\n",
" suppress_fringes=False, # Set to True to suppress side maxima between reflection peaks.\n",
" beam_parameters=beam, # Beam parameters object from above\n",
" detector_geometry='simple.geom', # External file that contains the detector geometry in CrystFEL notation.\n",
" )\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"parameters.use_gpu"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"if not isfile('simple.geom'):\n",
" xfile = !wget https://raw.githubusercontent.com/eucall-software/simex_platform/develop/Tests/python/unittest/TestFiles/simple.geom"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from SimEx.Utilities.EntityChecks import checkAndSetInstance"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"diffractor = CrystFELPhotonDiffractor(\n",
" parameters=parameters, \n",
" output_path=\"xstal_diffr\") # Output will go to a new dir \"xstal_diffr/\" in the current directory.'"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"dfile = 'diffractor.dill'\n",
"diffractor.dumpToFile(dfile)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'/home/reppinjo/xstal_diffr'"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"diffractor.output_path"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def submitSLURM():\n",
" batch_template = '''#!/bin/sh\n",
" #SBATCH --partition={0} \n",
" #SBATCH --time={1} \n",
" #SBATCH --nodes={2}\n",
" #SBATCH --output={3}/crystfel_%A.out\n",
"\n",
" export MODULEPATH=$MODULEPATH:$HOME/simex_dev_workshop/modulefiles\n",
" module load python3/3.4\n",
" module load simex\n",
"\n",
" mpirun -np {4} python3 $HOME/simex_platform/Sources/python/SimEx/Calculators/CrystFELPhotonDiffractor.py {5}\n",
" '''\n",
"\n",
" partition = 'maxwell'\n",
" time = '00:10:00'\n",
" nnodes = 1\n",
" ntask = 24\n",
" final_script = batch_template.format(partition, time, nnodes, getcwd(), ntask, dfile)\n",
"\n",
" fname = 'batch.sh'\n",
" with open(fname,'w') as ffile:\n",
" ffile.write(final_script)\n",
"\n",
" slurm = Popen(['sbatch',fname], stdout=PIPE)\n",
" print(slurm.stdout.read().strip().decode('utf-8'))"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "96482fde7bdb4e9d9c3cc280c7b7d2d9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(description='Submit to SLURM', style=ButtonStyle())"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Submitted batch job 977270\n"
]
}
],
"source": [
"w = widgets.Button(description='Submit to SLURM')\n",
"w.on_click(lambda b: submitSLURM())\n",
"display(w)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)\r\n",
" 977268 maxwell bash reppinjo R 3:57 1 max-wn060\r\n"
]
}
],
"source": [
"!squeue -u reppinjo"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment