1 from django import forms
2 from .models import Task
3 from .models import MIN_CHOICE
4 from .models import MD_START
5 from .models import MD_LANG
6 from .models import FF_CHOICE
9 class MultiWidgetBasic(forms.MultiWidget):
10 def __init__(self, count, attrs=None):
13 for i in range(self.count):
14 widgets.append(forms.TextInput())
15 super(MultiWidgetBasic, self).__init__(widgets, attrs)
17 template_name = 'multi.html'
19 def decompress(self, value):
21 return json.loads(value)
26 class MultiExampleField(forms.fields.MultiValueField):
27 def __init__(self, count, *args, **kwargs):
29 self.widget = MultiWidgetBasic(self.count)
31 for i in range(self.count):
32 list_fields.append(forms.fields.CharField(max_length=15))
33 super(MultiExampleField, self).__init__(list_fields, *args, **kwargs)
35 def compress(self, values):
36 ## compress list to single object
37 return json.dumps(values)
40 class TaskForm(forms.Form):
41 name = forms.CharField(max_length=20)
44 class TaskForm_min(forms.Form):
45 name = forms.CharField(max_length=20)
46 file1 = forms.FileField(label='Upload a PDB file',
47 help_text='continuous (without breaks) protein chains,use TER to divide chains')
50 class TaskForm_min_a(forms.Form):
51 name = forms.CharField(max_length=20)
53 unres_ff = forms.ChoiceField(choices=FF_CHOICE,widget=forms.RadioSelect,
54 label='Force Field',initial='E0LL2Y')
55 min_choice = forms.ChoiceField(choices=MIN_CHOICE,label='minimization algorithm')
56 min_overlap = forms.BooleanField(required=False,label='remove overlap')
57 min_searchsc = forms.BooleanField(required=False,label='MC for sidechain overlap')
58 min_maxmin = forms.IntegerField(label='MAXMIN',initial=10000,
59 help_text='maximum number of iterations')
60 min_maxfun = forms.IntegerField(label='MAXFUN',initial=15000,
61 help_text='maximum number of function evaluations')
62 file1 = forms.FileField(label='Upload a PDB file',
63 help_text='continuous (without breaks) protein chains,use TER to divide chains')
65 min_unres_pdb = forms.BooleanField(required=False,label='uploaded input unres PDB',
66 help_text='(CA and CB atoms only, CB represents SC in UNRES)')
67 min_pdbout = forms.BooleanField(required=False,label='output PDB',initial='true')
68 boxx = forms.FloatField(label='Box X',initial=1000.0,
69 help_text='box x dimension')
70 boxy = forms.FloatField(label='Box Y',initial=1000.0,
71 help_text='box y dimension')
72 boxz = forms.FloatField(label='Box Z',initial=1000.0,
73 help_text='box z dimension')
76 class TaskForm_md(forms.Form):
77 name = forms.CharField(max_length=20)
79 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
80 label='starting structure',initial='extconf')
81 md_seq = forms.CharField(label='Sequence',
82 help_text='aminoacid sequence using one letter code<br>'+
83 'field is ignored when uploading starting/reference PDB file',
85 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
86 file1 = forms.FileField(label='Upload a PDB file',required=False,
87 help_text='starting structure for pdbstart/reference structure')
88 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
89 md_temp = forms.FloatField(label='temperature',initial=300,
90 help_text='bath temperature')
91 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
92 help_text='total number of steps')
93 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
94 help_text='seed for random number generator')
97 cleaned_data = super(TaskForm_md, self).clean()
99 md_start = cleaned_data.get("md_start")
100 file1 = cleaned_data.get("file1")
101 md_seq = cleaned_data.get("md_seq")
102 md_pdbref = cleaned_data.get("md_pdbref")
104 if md_start == 'pdbstart' and not file1:
105 msg = 'pdbstart with no PDB file'
106 self.add_error('file1', msg)
108 if md_pdbref and not file1:
109 msg = 'pdbref with no PDB file'
110 self.add_error('file1', msg)
113 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
114 msg = 'extended/random chain with no sequence'
115 self.add_error('md_seq', msg)
118 class TaskForm_md_a(forms.Form):
119 name = forms.CharField(max_length=20)
121 unres_ff = forms.ChoiceField(choices=FF_CHOICE,widget=forms.RadioSelect,
122 label='Force Field',initial='E0LL2Y')
123 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
124 label='starting structure',initial='extconf')
125 md_seq = forms.CharField(label='Sequence',
126 help_text='aminoacid sequence using one letter code<br>'+
127 'field is ignored when uploading starting/reference PDB file',
129 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
130 file1 = forms.FileField(label='Upload a PDB file',required=False,
131 help_text='starting structure for pdbstart/reference structure')
132 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
133 md_temp = forms.FloatField(label='temperature',initial=300,
134 help_text='bath temperature')
135 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
136 help_text='total number of steps')
137 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
138 help_text='seed for random number generator')
140 md_ntwe = forms.IntegerField(label='NTWE',initial=1000,
141 help_text='write statfile every ntwe steps')
142 md_ntwx = forms.IntegerField(label='NTWX',initial=1000,
143 help_text='write trajectory every ntwe steps')
144 md_dt = forms.FloatField(label='DT',initial=0.2,
145 help_text='time step [mtu]')
146 md_lang = forms.ChoiceField(choices=MD_LANG,label='thermostat')
147 md_tau = forms.FloatField(label='tau_bath',initial=1.0,
148 help_text='coupling to the thermal bath (Berendsen)')
149 md_scal_fric = forms.FloatField(label='scal_froc',initial=0.02,
150 help_text='scaling of the friction coefficients (Langevin)')
151 md_mdpdb = forms.BooleanField(required=False,label='trajectory as PDB')
153 boxx = forms.FloatField(label='Box X',initial=1000.0,
154 help_text='box x dimension')
155 boxy = forms.FloatField(label='Box Y',initial=1000.0,
156 help_text='box y dimension')
157 boxz = forms.FloatField(label='Box Z',initial=1000.0,
158 help_text='box z dimension')
161 cleaned_data = super(TaskForm_md_a, self).clean()
163 md_start = cleaned_data.get("md_start")
164 file1 = cleaned_data.get("file1")
165 md_seq = cleaned_data.get("md_seq")
166 md_pdbref = cleaned_data.get("md_pdbref")
168 if md_start == 'pdbstart' and not file1:
169 msg = 'pdbstart with no PDB file'
170 self.add_error('file1', msg)
172 if md_pdbref and not file1:
173 msg = 'pdbref with no PDB file'
174 self.add_error('file1', msg)
177 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
178 msg = 'extended/random chain with no sequence'
179 self.add_error('md_seq', msg)
182 class TaskForm_remd(forms.Form):
183 name = forms.CharField(max_length=20)
185 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
186 label='starting structure',initial='extconf')
187 md_seq = forms.CharField(label='Sequence',
188 help_text='aminoacid sequence using one letter code<br>'+
189 'field is ignored when uploading starting/reference PDB file',
191 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
192 file1 = forms.FileField(label='Upload a PDB file',required=False,
193 help_text='starting structure for pdbstart/reference structure')
194 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
195 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
196 help_text='total number of steps')
197 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
198 help_text='seed for random number generator')
201 cleaned_data = super(TaskForm_remd, self).clean()
203 md_start = cleaned_data.get("md_start")
204 file1 = cleaned_data.get("file1")
205 md_seq = cleaned_data.get("md_seq")
206 md_pdbref = cleaned_data.get("md_pdbref")
208 if md_start == 'pdbstart' and not file1:
209 msg = 'pdbstart with no PDB file'
210 self.add_error('file1', msg)
212 if md_pdbref and not file1:
213 msg = 'pdbref with no PDB file'
214 self.add_error('file1', msg)
216 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
217 msg = 'extended/random chain with no sequence'
218 self.add_error('md_seq', msg)
221 class TaskForm_remd_a(forms.Form):
222 name = forms.CharField(max_length=20)
224 unres_ff = forms.ChoiceField(choices=FF_CHOICE,widget=forms.RadioSelect,
225 label='Force Field',initial='E0LL2Y')
226 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
227 label='starting structure',initial='extconf')
228 md_seq = forms.CharField(label='Sequence',
229 help_text='aminoacid sequence using one letter code<br>'+
230 'field is ignored when uploading starting/reference PDB file',
232 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
233 file1 = forms.FileField(label='Upload a PDB file',required=False,
234 help_text='starting structure for pdbstart/reference structure')
235 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
236 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
237 help_text='total number of steps')
238 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
239 help_text='seed for random number generator')
240 md_ntwe = forms.IntegerField(label='NTWE',initial=1000,
241 help_text='write statfile every ntwe steps')
242 md_dt = forms.FloatField(label='DT',initial=0.2,
243 help_text='time step [mtu]')
244 md_lang = forms.ChoiceField(choices=MD_LANG,label='thermostat')
245 md_tau = forms.FloatField(label='tau_bath',initial=1.0,
246 help_text='coupling to the thermal bath (Berendsen)')
247 md_scal_fric = forms.FloatField(label='scal_froc',initial=0.02,
248 help_text='scaling of the friction coefficients (Langevin)')
249 remd_nrep = forms.IntegerField(label='NREP',initial=8,
250 help_text='number of replicas')
251 remd_nstex = forms.IntegerField(label='NSTEX',initial=1000,
252 help_text='exchange and write trajectory every nstex steps')
253 md_ntwx = forms.IntegerField(label='NTWX',initial=1000,
254 help_text='write trajectory every ntwx steps')
255 remd_cluter_temp = forms.FloatField(label='TEMPER',
256 help_text='temperature for cluster analysis',initial=280)
257 # remd_traj1file = forms.BooleanField(required=False,label='single trajectory file',initial='true')
258 # remd_rest1file = forms.BooleanField(required=False,label='single restart file',initial='true')
260 boxx = forms.FloatField(label='Box X',initial=1000.0,
261 help_text='box x dimension')
262 boxy = forms.FloatField(label='Box Y',initial=1000.0,
263 help_text='box y dimension')
264 boxz = forms.FloatField(label='Box Z',initial=1000.0,
265 help_text='box z dimension')
269 cleaned_data = super(TaskForm_remd_a, self).clean()
271 md_start = cleaned_data.get("md_start")
272 file1 = cleaned_data.get("file1")
273 md_seq = cleaned_data.get("md_seq")
274 md_pdbref = cleaned_data.get("md_pdbref")
276 if md_start == 'pdbstart' and not file1:
277 msg = 'pdbstart with no PDB file'
278 self.add_error('file1', msg)
280 if md_pdbref and not file1:
281 msg = 'pdbref with no PDB file'
282 self.add_error('file1', msg)
285 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
286 msg = 'extended/random chain with no sequence'
287 self.add_error('md_seq', msg)
290 class TaskForm_list(forms.Form):
291 name = forms.CharField(max_length=20,disabled=True,required=False)
292 nrep = forms.IntegerField(disabled=True,required=False,label='NREP')
294 def __init__(self, count, *args, **kwargs):
295 super(TaskForm_list, self).__init__(*args, **kwargs)
297 self.fields['temperatures'] = MultiExampleField(self.count)
298 self.fields['multiplexing'] = MultiExampleField(self.count)