Skip to content

Commit 1106d68

Browse files
committed
consistency with documentation
1 parent 6313541 commit 1106d68

1 file changed

Lines changed: 69 additions & 69 deletions

File tree

api/system_template.py

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,41 @@ def main():
2828

2929
# file writers
3030
parser.add_argument('-e', metavar='<experiment>', action='store', type=str,
31-
help='select the experiment name', default=experiment)
31+
help='select the experiment name', default=experiment)
3232
parser.add_argument('-s', metavar='system', action='store', type=str,
33-
help='write geometry / materials templates for system name', default=NGIVEN)
33+
help='write geometry / materials templates for system name', default=NGIVEN)
3434
parser.add_argument('-v', metavar='variation', action='store', type=str,
35-
help='sets system variation(s). If not provided, \'default\' will be used ', nargs='*',
36-
default=['default'])
35+
help='sets system variation(s). If not provided, \'default\' will be used ',
36+
nargs='*',
37+
default=['default'])
3738
# code snippets loggers: volume
38-
parser.add_argument('-silent', action='store_true', help='do not output the commented lines of code',
39-
default=False)
40-
parser.add_argument('-sl', action='store_true', help='show available geant4 solids constructors')
39+
parser.add_argument('-silent', action='store_true',
40+
help='do not output the commented lines of code',
41+
default=False)
42+
parser.add_argument('-sl', action='store_true',
43+
help='show available geant4 solids constructors')
4144
parser.add_argument('-gv', metavar='volume', action='store', type=str,
42-
help="show or write template python code to create selected geant4 volume "
43-
"Use ' -sl ' to list the available types.", default=NGIVEN)
45+
help="show or write template python code to create selected geant4 volume "
46+
"Use ' -sl ' to list the available types.", default=NGIVEN)
4447
parser.add_argument('-gvp', metavar='parameters', action='store', type=str,
45-
help="assign parameters to the geant4 volume type selected with the gv option", default=NGIVENS)
48+
help="assign parameters to the geant4 volume type selected with the gv option",
49+
default=NGIVENS)
4650
# code snippets loggers: material
4751
parser.add_argument('-gmatFM', metavar='material', action='store', type=str,
48-
help='show or write template python code for a material defined using fractional masses', default=NGIVEN)
52+
help='show or write template python code for a material defined using fractional masses',
53+
default=NGIVEN)
4954
parser.add_argument('-gmatNA', metavar='material', action='store', type=str,
50-
help='show or write template python code for a material defined using number of atoms', default=NGIVEN)
55+
help='show or write template python code for a material defined using number of atoms',
56+
default=NGIVEN)
5157
parser.add_argument('-write_to', metavar='filename', action='store', type=str,
52-
help='write code to filename instead of showing it to screen', default=NGIVEN)
58+
help='write code to filename instead of showing it to screen',
59+
default=NGIVEN)
5360
parser.add_argument('-geo_sub', metavar='method', action='store', type=str,
54-
help='to use with write_to option: defines name of geo subroutine', default="build_test")
61+
help='to use with write_to option: defines name of geo subroutine',
62+
default="build_test")
5563
# add option to select the database type
5664
parser.add_argument('-f', metavar='factory', action='store', type=str,
57-
help='select the factory type', default='ascii')
65+
help='select the factory type', default='ascii')
5866

5967
args = parser.parse_args()
6068

@@ -113,7 +121,8 @@ def ask_to_overwrite_file(path):
113121

114122
def write_templates(system, variations):
115123
print()
116-
print(f' Writing files for experiment >{experiment}<, system template >{system}< using variations >{variations}<:')
124+
print(
125+
f' Writing files for experiment >{experiment}<, system template >{system}< using variations >{variations}<:')
117126
print()
118127
print(f' - {system}.py')
119128
print(f' - geometry.py')
@@ -137,29 +146,23 @@ def write_templates(system, variations):
137146

138147
# ask_to_overwrite_file(system_script)
139148
with open(f'{system_script}', 'w') as ps:
140-
ps.write('#!/usr/bin/env python3\n\n')
141-
ps.write('# python:\n')
142-
ps.write('# api:\n')
143-
ps.write('from gconfiguration import GConfiguration\n\n')
144-
ps.write(f'# {system}:\n')
149+
ps.write('#!/usr/bin/env python3\n')
150+
ps.write('from gconfiguration import autogeometry\n\n')
151+
ps.write(f'# {system}\n')
145152
ps.write('from materials import define_materials\n')
146153
ps.write(f'from geometry import build_{system}\n\n')
147-
ps.write('def main():\n')
148-
ps.write(' # Define GConfiguration name, factory and description.\n')
149-
ps.write(f' configuration = GConfiguration(\'{experiment}\', \'{system}\')\n\n')
150-
ps.write(' define_materials(configuration)\n')
151-
ps.write(f' build_{system}(configuration)\n')
152-
ps.write(' configuration.show()\n\n\n')
153-
ps.write('if __name__ == "__main__":\n')
154-
ps.write(' main()\n\n\n')
154+
ps.write(f'cfg = autogeometry(\'{experiment}\', \'{system}\')\n\n')
155+
ps.write('define_materials(cfg)\n')
156+
ps.write(f'build_{system}(cfg)\n')
157+
155158
# change permission
156159
os.chmod(system_script, 0o755)
157160

158161
# ask_to_overwrite_file(mat_script)
159162
with open(f'{mat_script}', 'w') as pm:
160163
pm.write('from gmaterial import GMaterial\n\n')
161164
pm.write('def define_materials(configuration):\n\n')
162-
pm.write('# example of material: epoxy glue, defined with number of atoms\n')
165+
pm.write(' # example of material: epoxy glue, defined with number of atoms\n')
163166
pm.write(' gmaterial = GMaterial("epoxy")\n')
164167
pm.write(' gmaterial.description = "epoxy glue 1.16 g/cm3"\n')
165168
pm.write(' gmaterial.density = 1.16\n')
@@ -168,7 +171,7 @@ def write_templates(system, variations):
168171
pm.write(' gmaterial.addNAtoms("O", 4)\n')
169172
pm.write(' gmaterial.addNAtoms("C", 15)\n')
170173
pm.write(' gmaterial.publish(configuration)\n\n')
171-
pm.write('# example of material: carbon fiber, defined using the fractional mass\n')
174+
pm.write(' # example of material: carbon fiber, defined using the fractional mass\n')
172175
pm.write(' gmaterial = GMaterial("carbonFiber")\n')
173176
pm.write(' gmaterial.description = "carbon fiber - 1.75g/cm3"\n')
174177
pm.write(' gmaterial.density = 1.75\n')
@@ -178,21 +181,20 @@ def write_templates(system, variations):
178181

179182
# ask_to_overwrite_file(geo_script)
180183
with open(f'{geo_script}', 'w') as pg:
181-
pg.write('from gvolume import GVolume\n')
182-
pg.write('import math\n\n')
183-
pg.write('# These are example of methods to build a mother and daughter volume.\n\n')
184+
pg.write('from gvolume import GVolume\n\n')
185+
pg.write('# These are example of methods to organize volumes creation\n\n')
184186
pg.write(f'def build_{system}(configuration):\n')
185187
pg.write(' build_flux_box(configuration)\n')
186188
pg.write(' build_target(configuration)\n\n')
187189
pg.write('def build_flux_box(configuration):\n')
188190
pg.write(' gvolume = GVolume(\'flux_box\')\n')
189191
pg.write(' gvolume.description = \'carbon fiber box\'\n')
190192
pg.write(' gvolume.make_box(40.0, 40.0, 2.0)\n')
193+
pg.write(' gvolume.set_position(0, 0, 100)\n')
191194
pg.write(' gvolume.material = \'carbonFiber\'\n')
192195
pg.write(' gvolume.color = \'3399FF\'\n')
193196
pg.write(' gvolume.style = 1\n')
194197
pg.write(' gvolume.digitization = \'flux\'\n')
195-
pg.write(' gvolume.set_position(0, 0, 100)\n')
196198
pg.write(' gvolume.set_identifier(\'box\', 2) # identifier for this box\n')
197199
pg.write(' gvolume.publish(configuration)\n\n')
198200

@@ -203,7 +205,6 @@ def write_templates(system, variations):
203205
pg.write(' gvolume.material = \'epoxy\'\n')
204206
pg.write(' gvolume.publish(configuration)\n\n\n\n')
205207

206-
207208
# ask_to_overwrite_file(yaml)
208209
with open(f'{yaml}', 'w') as pj:
209210
pj.write('runno: 1\n')
@@ -212,12 +213,9 @@ def write_templates(system, variations):
212213
pj.write('gparticle:\n')
213214
pj.write(' - name: proton\n')
214215
pj.write(' p: 1500\n')
215-
pj.write(' vz: -5.0\n')
216+
pj.write(' vz: -5.0\n\n')
216217
pj.write('verbosity:\n')
217-
pj.write(' - ghits: 0\n')
218-
pj.write(' - gsystem: 1\n')
219-
pj.write(' - gstreamer: 0\n')
220-
pj.write(' - general: 1\n\n')
218+
pj.write(' - gsystem: 1\n\n')
221219
pj.write('gsystem:\n')
222220
pj.write(f' - name: {system}\n')
223221
pj.write(' factory: sqlite\n\n')
@@ -228,29 +226,23 @@ def write_templates(system, variations):
228226

229227
# ask_to_overwrite_file(readme)
230228
with open(f'{readme}', 'w') as rm:
231-
gemc = '[GEMC: Monte Carlo Particles and Hardware Simulator](https://gemc.github.io/home)'
232-
rm.write('\n')
233-
"""write 20 spaces then system name then 20 spaces"""
234-
rm.write(f'|{" " * 20}{gemc}{" " * 20}|\n')
235-
"""write as many dashes as the length of the system name plus 40"""
236-
rm.write('|:' + '-' * (len(gemc) + 38) + ':|\n')
237-
"""center system and description"""
238-
left_right_space = int((40 - len(gemc) - 12) / 2)
239-
rm.write(f'|{" " * left_right_space}Name and Summary Description{" " * left_right_space}|\n\n\n')
240-
rm.write('### Description\n\n')
241-
rm.write('### Usage\n\n')
242-
rm.write('- #### Building the detector\n\n')
243-
rm.write('- #### Running gemc\n\n')
244-
rm.write('- #### Examples\n\n')
245-
rm.write('### Output\n\n')
246-
rm.write('### Notes\n\n')
247-
rm.write('### Author(s)\n\n')
248-
rm.write('### References\n\n')
229+
rm.write('## Geometry\n\n')
230+
rm.write('## Physics List\n\n')
231+
rm.write('## Generator\n\n')
232+
rm.write('## Digitization\n\n')
233+
rm.write('## Usage\n\n')
234+
rm.write('- ### Building the detector\n\n')
235+
rm.write('- ### Running gemc\n\n')
236+
rm.write('## Output Format\n\n')
237+
rm.write('## Additional Notes\n\n')
238+
rm.write('## Author(s)\n\n')
239+
rm.write('## References\n\n')
249240

250241

251242
def check_units(unit_string) -> str:
252243
"""check if units are valid and return the unit string"""
253-
if unit_string in ['mm', 'cm', 'm', 'rad', 'deg', 'mrad', 'urad', 'ns', 's', 'MeV', 'GeV', 'keV', 'eV']:
244+
if unit_string in ['mm', 'cm', 'm', 'rad', 'deg', 'mrad', 'urad', 'ns', 's', 'MeV', 'GeV',
245+
'keV', 'eV']:
254246
return unit_string
255247

256248

@@ -367,18 +359,26 @@ def log_gvolume(subroutine_name, silent, write_to, volume_type, parameters: [str
367359
if not silent:
368360
volume_definitions.append(
369361
'# Uncomment any of the lines below to set parameters different than these defaults:\n')
370-
volume_definitions.append('# gvolume.mother = \'motherVolumeName\' # default: \'root\' ')
371-
volume_definitions.append('# gvolume.description = \'describe your volume here\' # default: \'na\'')
372-
volume_definitions.append('# gvolume.set_position(myX, myY, myZ) # default: (0, 0, 0)')
373-
volume_definitions.append('# gvolume.set_rotation(myX, myY, myZ) # default: (0, 0, 0)')
374-
volume_definitions.append('# gvolume.mfield = \'solenoid\' # default: \'na\'')
375-
volume_definitions.append('# gvolume.color = \'838EDE\' # default: \'778899\'')
362+
volume_definitions.append(
363+
'# gvolume.mother = \'motherVolumeName\' # default: \'root\' ')
364+
volume_definitions.append(
365+
'# gvolume.description = \'describe your volume here\' # default: \'na\'')
366+
volume_definitions.append(
367+
'# gvolume.set_position(myX, myY, myZ) # default: (0, 0, 0)')
368+
volume_definitions.append(
369+
'# gvolume.set_rotation(myX, myY, myZ) # default: (0, 0, 0)')
370+
volume_definitions.append(
371+
'# gvolume.mfield = \'solenoid\' # default: \'na\'')
372+
volume_definitions.append(
373+
'# gvolume.color = \'838EDE\' # default: \'778899\'')
376374
volume_definitions.append(
377375
'# gvolume.style = \'0\' # (1 = surface, 0 = wireframe) default is 1')
378376
volume_definitions.append(
379377
'# gvolume.visible = \'0\' # (1 = visible, 0 = invisible) default is 1')
380-
volume_definitions.append('# gvolume.digitization = \'flux\' # default: \'na\'')
381-
volume_definitions.append('# gvolume.set_identifier(\'paddleid\', 1) # default: \'na\'')
378+
volume_definitions.append(
379+
'# gvolume.digitization = \'flux\' # default: \'na\'')
380+
volume_definitions.append(
381+
'# gvolume.set_identifier(\'paddleid\', 1) # default: \'na\'')
382382

383383
volume_definitions.append('gvolume.publish(configuration)')
384384

@@ -411,7 +411,7 @@ def print_all_g4solids():
411411
print(' The corresponding solids and their \033[92mconstructors\033[0m in gemc are:\n')
412412
for g4solid, description in AVAILABLE_SOLIDS_MAP.items():
413413
print(f' - \033[91m{g4solid:20}\033[0m {description[0]:30}\n'
414-
f' \033[92m{description[1]} \033[0m\n')
414+
f' \033[92m{description[1]} \033[0m\n')
415415
print('\n\n')
416416

417417

0 commit comments

Comments
 (0)