Skip to content

Commit 942aae9

Browse files
authored
Fill XDS_template from base instead of writing 4 almost-identical files (#158)
1 parent 40da77a commit 942aae9

8 files changed

Lines changed: 30 additions & 356 deletions

File tree

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ include src/instamatic/config/microscope/*.yaml
2828
include src/instamatic/config/scripts/*.md
2929
include src/instamatic/neural_network/*.p
3030
include src/instamatic/processing/PETS_input_keywords.csv
31+
include src/instamatic/processing/XDS_template.inp

src/instamatic/processing/ImgConversionDM.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(
7272
self.name = 'DigitalMicrograph'
7373
self.method = method
7474

75-
from .XDS_templateDM import XDS_template
75+
from .XDS_template import XDS_template_DM as XDS_template
7676

7777
self.XDS_template = XDS_template
7878

src/instamatic/processing/ImgConversionTPX.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(
8484
self.name = 'TimePix_SU'
8585
self.method = method
8686

87-
from .XDS_templateTPX import XDS_template
87+
from .XDS_template import XDS_template_TPX as XDS_template
8888

8989
self.XDS_template = XDS_template
9090

src/instamatic/processing/ImgConversionTVIPS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(
7474
self.name = 'TVIPS F416'
7575
self.method = method
7676

77-
from .XDS_templateTVIPS import XDS_template
77+
from .XDS_template import XDS_template_TVIPS as XDS_template
7878

7979
self.XDS_template = XDS_template
8080

src/instamatic/processing/XDS_templateDM.py renamed to src/instamatic/processing/XDS_template.inp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from __future__ import annotations
2-
3-
XDS_template = """! XDS.INP file for Rotation Electron Diffraction generated by `instamatic`
1+
! XDS.INP file for Rotation Electron Diffraction generated by `instamatic`
42
! {date}
53
! For definitions of input parameters, see:
64
! http://xds.mpimf-heidelberg.mpg.de/html_doc/xds_parameters.html
@@ -37,8 +35,8 @@
3735
STARTING_ANGLE= {starting_angle:0.4f}
3836
STARTING_FRAME= 1
3937

40-
MAX_CELL_AXIS_ERROR= 0.03 !0.03 is default
41-
MAX_CELL_ANGLE_ERROR= 2.0 !2.0 is default
38+
MAX_CELL_AXIS_ERROR= {max_cell_axis_error} !0.03 is default
39+
MAX_CELL_ANGLE_ERROR= {max_cell_angle_error} !2.0 is default
4240

4341
TEST_RESOLUTION_RANGE=10. 1.0 !for calculation of Rmeas when analysing the intensity data for space group symmetry in the CORRECT step.
4442
!MIN_RFL_Rmeas=50 !50 is default - used in the CORRECT step for identification of possible space groups.
@@ -49,7 +47,7 @@
4947
NX={NX} NY={NY} !Number of pixels
5048
QX={QX:.4f} QY={QY:.4f} !Physical size of pixels (mm)
5149
OVERLOAD= 130000 !default value dependent on the detector used
52-
TRUSTED_REGION= 0.0 1.05 !default \"0.0 1.05\". Corners for square detector max \"0.0 1.4142\"
50+
TRUSTED_REGION= 0.0 1.05 !default "0.0 1.05". Corners for square detector max "0.0 1.4142"
5351
{untrusted_areas}
5452
{stretch_correction}
5553
SENSOR_THICKNESS=0.30
@@ -95,7 +93,7 @@
9593

9694
!NBX=7 NBY=7 ! 3 is default, used to estimate the expected variation in a data image, see GAIN.cbf
9795
!BACKGROUND_PIXEL= 6.0 ! Background pixel belongs to background if variation less than given esds
98-
!STRONG_PIXEL= 3.0 ! Strong pixel must exceed background by more than number of given esds
96+
{strong_pixel_line} ! Strong pixel must exceed background by more than number of given esds
9997
!MAXIMUM_NUMBER_OF_STRONG_PIXELS= 1500000 ! Approximate upper limit for the total number of 'strong' pixels
10098
!MINIMUM_NUMBER_OF_PIXELS_IN_A_SPOT= 6 ! Used to suppress spurious, isolated 'strong' pixels from entering the spot list
10199
!SPOT_MAXIMUM-CENTROID= 3.0 ! Maximum deviation of spot maximum from spot centroid
@@ -109,10 +107,9 @@
109107

110108
! ********** Indexing **********
111109

112-
MINIMUM_FRACTION_OF_INDEXED_SPOTS= 0.25 ! 0.50 is default.
110+
{min_fraction_line} !0.50 is default.
113111
!MAXIMUM_ERROR_OF_SPOT_POSITION=6.0 ! 3.0 is default
114112
!REFLECTING_RANGE=
115113
!REFLECTING_RANGE_E.S.D.=
116114
!BEAM_DIVERGENCE=
117115
!BEAM_DIVERGENCE_E.S.D.=
118-
"""
Lines changed: 20 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,30 @@
11
from __future__ import annotations
22

3-
XDS_template = """! XDS.INP file for Rotation Electron Diffraction generated by `instamatic`
4-
! {date}
5-
! For definitions of input parameters, see:
6-
! http://xds.mpimf-heidelberg.mpg.de/html_doc/xds_parameters.html
7-
!
8-
! cRED implementation reference paper:
9-
! J. Appl. Cryst. (2018). 51, 1652–1661. http://dx.doi.org/10.1107/S1600576718015145
3+
from dataclasses import asdict, dataclass
4+
from importlib.resources import files
105

11-
! ********** Job control **********
6+
from instamatic._collections import PartialFormatter
127

13-
!JOB= XYCORR INIT COLSPOT IDXREF
14-
!JOB= DEFPIX INTEGRATE CORRECT
15-
!JOB= CORRECT
8+
XDS_template_path = files('instamatic.processing').joinpath('XDS_template.inp')
9+
XDS_template_base = XDS_template_path.read_text(encoding='utf-8')
1610

17-
MAXIMUM_NUMBER_OF_JOBS=4
18-
MAXIMUM_NUMBER_OF_PROCESSORS=4
1911

20-
! ********** Data images **********
12+
@dataclass
13+
class XDSPreset:
14+
max_cell_axis_error: str = '0.05'
15+
max_cell_angle_error: str = '3.0'
16+
strong_pixel_line: str = '!STRONG_PIXEL= 3.0'
17+
min_fraction_line: str = '!MINIMUM_FRACTION_OF_INDEXED_SPOTS= 0.25'
2118

22-
NAME_TEMPLATE_OF_DATA_FRAMES= {data_drc}/0????.img SMV
23-
DATA_RANGE= {data_begin:d} {data_end:d}
24-
SPOT_RANGE= {data_begin:d} {data_end:d}
25-
BACKGROUND_RANGE= {data_begin:d} {data_end:d}
26-
{exclude:s}
2719

28-
! ********** Crystal **********
20+
mce = {'max_cell_axis_error': '0.03', 'max_cell_angle_error': '2.0'}
2921

30-
!SPACE_GROUP_NUMBER= 0
31-
!UNIT_CELL_CONSTANTS= 10 20 30 90 90 90
22+
xds_preset_base = XDSPreset()
23+
xds_preset_dm = XDSPreset(min_fraction_line='MINIMUM_FRACTION_OF_INDEXED_SPOTS= 0.25 ', **mce)
24+
xds_preset_tvips = XDSPreset(strong_pixel_line='STRONG_PIXEL= 6.0 ', **mce)
3225

33-
!REIDX= !Optional reindexing transformation to apply on reflection indices
34-
FRIEDEL'S_LAW=TRUE !TRUE is default
35-
36-
!phi(i) = STARTING_ANGLE + OSCILLATION_RANGE * (i - STARTING_FRAME)
37-
STARTING_ANGLE= {starting_angle:0.4f}
38-
STARTING_FRAME= 1
39-
40-
MAX_CELL_AXIS_ERROR= 0.05 !0.03 is default
41-
MAX_CELL_ANGLE_ERROR= 3.0 !2.0 is default
42-
43-
TEST_RESOLUTION_RANGE=10. 1.0 !for calculation of Rmeas when analysing the intensity data for space group symmetry in the CORRECT step.
44-
!MIN_RFL_Rmeas=50 !50 is default - used in the CORRECT step for identification of possible space groups.
45-
!MAX_FAC_Rmeas=2.0 !2.0 is default - used in the CORRECT step for identification of possible space groups.
46-
47-
! ********** Detector hardware **********
48-
49-
NX={NX} NY={NY} !Number of pixels
50-
QX={QX:.4f} QY={QY:.4f} !Physical size of pixels (mm)
51-
OVERLOAD= 130000 !default value dependent on the detector used
52-
TRUSTED_REGION= 0.0 1.05 !default \"0.0 1.05\". Corners for square detector max \"0.0 1.4142\"
53-
{untrusted_areas}
54-
{stretch_correction}
55-
SENSOR_THICKNESS=0.30
56-
AIR=0.0
57-
58-
! ********** Trusted detector region **********
59-
60-
VALUE_RANGE_FOR_TRUSTED_DETECTOR_PIXELS= 10 30000 !Values are defined in `ABS.CBF`, check mask in `BKGPIX.CBF`, used in DEFPIX
61-
!MINIMUM_ZETA= !0.05 is default
62-
63-
INCLUDE_RESOLUTION_RANGE= 20 0.8
64-
65-
!Ice Ring exclusion, important for data collected using cryo holders
66-
!EXCLUDE_RESOLUTION_RANGE= 3.93 3.87 !ice-ring at 3.897 Angstrom
67-
!EXCLUDE_RESOLUTION_RANGE= 3.70 3.64 !ice-ring at 3.669 Angstrom
68-
!EXCLUDE_RESOLUTION_RANGE= 3.47 3.41 !ice-ring at 3.441 Angstrom (Main)
69-
!EXCLUDE_RESOLUTION_RANGE= 2.70 2.64 !ice-ring at 2.671 Angstrom
70-
!EXCLUDE_RESOLUTION_RANGE= 2.28 2.22 !ice-ring at 2.249 Angstrom (Main)
71-
!EXCLUDE_RESOLUTION_RANGE= 2.102 2.042 !ice-ring at 2.072 Angstrom - strong
72-
!EXCLUDE_RESOLUTION_RANGE= 1.978 1.918 !ice-ring at 1.948 Angstrom - weak
73-
!EXCLUDE_RESOLUTION_RANGE= 1.948 1.888 !ice-ring at 1.918 Angstrom - strong
74-
!EXCLUDE_RESOLUTION_RANGE= 1.913 1.853 !ice-ring at 1.883 Angstrom - weak
75-
!EXCLUDE_RESOLUTION_RANGE= 1.751 1.691 !ice-ring at 1.721 Angstrom - weak
76-
77-
! ********** Detector geometry & Rotation axis **********
78-
79-
DIRECTION_OF_DETECTOR_X-AXIS= 1 0 0
80-
DIRECTION_OF_DETECTOR_Y-AXIS= 0 1 0
81-
82-
ORGX= {origin_x:.2f} ORGY= {origin_y:.2f} !Detector origin (pixels). Often close to the image center, i.e. ORGX=NX/2; ORGY=NY/2
83-
DETECTOR_DISTANCE= {sign}{detector_distance:.2f} !Can be negative. Positive because the detector normal points away from the crystal.
84-
85-
OSCILLATION_RANGE= {osc_angle:.4f}
86-
87-
ROTATION_AXIS= {rot_x:.4f} {rot_y:.4f} {rot_z:.4f}
88-
89-
! ********** Incident beam **********
90-
91-
X-RAY_WAVELENGTH= {wavelength:.4f} !used by IDXREF
92-
INCIDENT_BEAM_DIRECTION= 0 0 1 !The vector points from the source towards the crystal
93-
94-
! ********** Background and peak pixels **********
95-
96-
!NBX=7 NBY=7 ! 3 is default, used to estimate the expected variation in a data image, see GAIN.cbf
97-
!BACKGROUND_PIXEL= 6.0 ! Background pixel belongs to background if variation less than given esds
98-
!STRONG_PIXEL= 3.0 ! Strong pixel must exceed background by more than number of given esds
99-
!MAXIMUM_NUMBER_OF_STRONG_PIXELS= 1500000 ! Approximate upper limit for the total number of 'strong' pixels
100-
!MINIMUM_NUMBER_OF_PIXELS_IN_A_SPOT= 6 ! Used to suppress spurious, isolated 'strong' pixels from entering the spot list
101-
!SPOT_MAXIMUM-CENTROID= 3.0 ! Maximum deviation of spot maximum from spot centroid
102-
!SIGNAL_PIXEL= 3.0 ! Signal pixels must exceed background by more than given esds
103-
104-
! ********** Refinement **********
105-
106-
REFINE(IDXREF)= BEAM AXIS ORIENTATION CELL !POSITION
107-
REFINE(INTEGRATE)= !POSITION BEAM AXIS !ORIENTATION CELL
108-
REFINE(CORRECT)= BEAM AXIS ORIENTATION CELL !POSITION
109-
110-
! ********** Indexing **********
111-
112-
!MINIMUM_FRACTION_OF_INDEXED_SPOTS= 0.25 !0.50 is default.
113-
!MAXIMUM_ERROR_OF_SPOT_POSITION=6.0 ! 3.0 is default
114-
!REFLECTING_RANGE=
115-
!REFLECTING_RANGE_E.S.D.=
116-
!BEAM_DIVERGENCE=
117-
!BEAM_DIVERGENCE_E.S.D.=
118-
"""
26+
pf = PartialFormatter()
27+
XDS_template = pf.format(XDS_template_base, **asdict(xds_preset_base))
28+
XDS_template_DM = pf.format(XDS_template_base, **asdict(xds_preset_dm))
29+
XDS_template_TPX = XDS_template
30+
XDS_template_TVIPS = pf.format(XDS_template_base, **asdict(xds_preset_tvips))

src/instamatic/processing/XDS_templateTPX.py

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)