-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTPS2TOPAS.py
152 lines (129 loc) · 7.64 KB
/
TPS2TOPAS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"""
The TPS2TOPAS interface: An interface tool to parametrize treatment plans for the TrueBeam
radiotherapy system into OpenTOPAS parameter control files for Monte Carlo simulation.
Authors:
Ramon Ortiz, Ph.D.
Department of Radiation Oncology
University of California San Francisco.
Jose Ramos-Mendez, Ph.D. *
Department of Radiation Oncology
University of California San Francisco.
* corresponding author
Please cite:
History:
13 June 2024 - released version (v1.0)
"""
from input_handling import *
from plan_data import *
from write_PCF import *
import sys
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
def printHelp():
print('Use: TPS2TOPAS.py --m [mode] [parameterFile]')
print(' Parameters:')
print(' mode: gui or inputfile ')
print(' parameterFile: ONLY IF "inputfile" mode selected: txt file including:')
print(' (1) Project name')
print(' (2) path to DICOM directory')
print(' (3) path to DICOM-structure file')
print(' (4) path to DICOM-dose file')
print(' (5) path to DICOM-RT plan file')
print(' (6) path to phase space file name')
print(' (7) MLC model: "generic", "Varian" or "VarianHD"')
print(' (8) Geometrical particle splitting factor (integer number)')
print(' (9) Scoring quantity: "DoseToWater" or "DoseToMedium')
print(' (10) Output file name')
print(' (11) Output file format: "binary", "DICOM", "csv", "root" or "xml"')
exitProgram()
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
def EvaluateCorrectInitialization():
narg = len(sys.argv)
if narg == 1:
print("###### \n ERROR! incorrect use \n ######")
printHelp()
exitProgram()
for i in range(narg):
option = sys.argv[i].lower()
if '--' in option:
if option == '--help' or option == '--h':
printHelp()
elif option == '--m':
if sys.argv[i+1] == 'gui':
mode = 'gui'
inputFile = ''
elif sys.argv[i+1] == 'inputfile':
mode = 'file'
try:
inputFile = sys.argv[i+2]
except:
print("###### \n ERROR! a parameter file is required in mode 'inputfile' \n ######")
printHelp()
exitProgram()
try:
f = open(inputFile, "r")
except:
print("###### \n ERROR! file not found \n######")
exitProgram()
f.close()
else:
print("###### \n ERROR! Please use a valid mode \n######")
printHelp()
else:
print("###### \n ERROR! %s incorrect use \n######" % sys.argv[i])
printHelp()
exitProgram()
return mode, inputFile
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
def exitProgram():
sys.exit(1)
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
def main():
# Initialization
mode, inputFile = EvaluateCorrectInitialization()
# Read data
if mode == 'gui':
DATA = InputDataInputGUIMode()
if mode == 'file':
DATA = InputDataInputFileMode(inputFile)
# Create the project directory
os.system('mkdir %s' %DATA["project_name"])
os.system('mkdir %s/output' %DATA["project_name"])
os.system('cp HUtoMaterialSchneider.txt %s' %DATA["project_name"])
# Retrieve data from files exported from TPS
CT_DATA = RetrieveCTData(DATA)
PLAN_DATA = RetrievePlanData(DATA)
ROI_DATA = RetrieveROIData(DATA)
# Write PCF
WriteTimeFeaturesPCF(DATA,PLAN_DATA)
WritePlanParameterFile(DATA,CT_DATA,PLAN_DATA)
WriteGeometryFile(DATA,ROI_DATA)
WriteMainWithVisualizationFile(DATA)
WriteMainFile(DATA,PLAN_DATA)
# Print output message
print("\n--- DONE --- ")
print(" - OpenTOPAS parameter files have been created and saved in %s" %(str(pathlib.Path().resolve())+"/"+DATA["project_name"]))
print(" -- See above for possible warnings")
print("-------------")
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
if __name__ == "__main__":
main()