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')
70 class TaskForm_md(forms.Form):
71 name = forms.CharField(max_length=20)
73 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
74 label='starting structure',initial='extconf')
75 md_seq = forms.CharField(label='Sequence',
76 help_text='aminoacid sequence using one letter code<br>'+
77 'field is ignored when uploading starting/reference PDB file',
79 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
80 file1 = forms.FileField(label='Upload a PDB file',required=False,
81 help_text='starting structure for pdbstart/reference structure')
82 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
83 md_temp = forms.FloatField(label='temperature',initial=300,
84 help_text='bath temperature')
85 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
86 help_text='total number of steps')
87 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
88 help_text='seed for random number generator')
91 cleaned_data = super(TaskForm_md, self).clean()
93 md_start = cleaned_data.get("md_start")
94 file1 = cleaned_data.get("file1")
95 md_seq = cleaned_data.get("md_seq")
96 md_pdbref = cleaned_data.get("md_pdbref")
98 if md_start == 'pdbstart' and not file1:
99 msg = 'pdbstart with no PDB file'
100 self.add_error('file1', msg)
102 if md_pdbref and not file1:
103 msg = 'pdbref with no PDB file'
104 self.add_error('file1', msg)
107 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
108 msg = 'extended/random chain with no sequence'
109 self.add_error('md_seq', msg)
112 class TaskForm_md_a(forms.Form):
113 name = forms.CharField(max_length=20)
115 unres_ff = forms.ChoiceField(choices=FF_CHOICE,widget=forms.RadioSelect,
116 label='Force Field',initial='E0LL2Y')
117 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
118 label='starting structure',initial='extconf')
119 md_seq = forms.CharField(label='Sequence',
120 help_text='aminoacid sequence using one letter code<br>'+
121 'field is ignored when uploading starting/reference PDB file',
123 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
124 file1 = forms.FileField(label='Upload a PDB file',required=False,
125 help_text='starting structure for pdbstart/reference structure')
126 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
127 md_temp = forms.FloatField(label='temperature',initial=300,
128 help_text='bath temperature')
129 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
130 help_text='total number of steps')
131 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
132 help_text='seed for random number generator')
134 md_ntwe = forms.IntegerField(label='NTWE',initial=1000,
135 help_text='write statfile every ntwe steps')
136 md_ntwx = forms.IntegerField(label='NTWX',initial=1000,
137 help_text='write trajectory every ntwe steps')
138 md_dt = forms.FloatField(label='DT',initial=0.2,
139 help_text='time step [mtu]')
140 md_lang = forms.ChoiceField(choices=MD_LANG,label='thermostat')
141 md_tau = forms.FloatField(label='tau_bath',initial=1.0,
142 help_text='coupling to the thermal bath (Berendsen)')
143 md_scal_fric = forms.FloatField(label='scal_froc',initial=0.02,
144 help_text='scaling of the friction coefficients (Langevin)')
145 md_mdpdb = forms.BooleanField(required=False,label='trajectory as PDB')
148 cleaned_data = super(TaskForm_md_a, self).clean()
150 md_start = cleaned_data.get("md_start")
151 file1 = cleaned_data.get("file1")
152 md_seq = cleaned_data.get("md_seq")
153 md_pdbref = cleaned_data.get("md_pdbref")
155 if md_start == 'pdbstart' and not file1:
156 msg = 'pdbstart with no PDB file'
157 self.add_error('file1', msg)
159 if md_pdbref and not file1:
160 msg = 'pdbref with no PDB file'
161 self.add_error('file1', msg)
164 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
165 msg = 'extended/random chain with no sequence'
166 self.add_error('md_seq', msg)
169 class TaskForm_remd(forms.Form):
170 name = forms.CharField(max_length=20)
172 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
173 label='starting structure',initial='extconf')
174 md_seq = forms.CharField(label='Sequence',
175 help_text='aminoacid sequence using one letter code<br>'+
176 'field is ignored when uploading starting/reference PDB file',
178 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
179 file1 = forms.FileField(label='Upload a PDB file',required=False,
180 help_text='starting structure for pdbstart/reference structure')
181 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
182 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
183 help_text='total number of steps')
184 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
185 help_text='seed for random number generator')
188 cleaned_data = super(TaskForm_remd, self).clean()
190 md_start = cleaned_data.get("md_start")
191 file1 = cleaned_data.get("file1")
192 md_seq = cleaned_data.get("md_seq")
193 md_pdbref = cleaned_data.get("md_pdbref")
195 if md_start == 'pdbstart' and not file1:
196 msg = 'pdbstart with no PDB file'
197 self.add_error('file1', msg)
199 if md_pdbref and not file1:
200 msg = 'pdbref with no PDB file'
201 self.add_error('file1', msg)
203 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
204 msg = 'extended/random chain with no sequence'
205 self.add_error('md_seq', msg)
208 class TaskForm_remd_a(forms.Form):
209 name = forms.CharField(max_length=20)
211 unres_ff = forms.ChoiceField(choices=FF_CHOICE,widget=forms.RadioSelect,
212 label='Force Field',initial='E0LL2Y')
213 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
214 label='starting structure',initial='extconf')
215 md_seq = forms.CharField(label='Sequence',
216 help_text='aminoacid sequence using one letter code<br>'+
217 'field is ignored when uploading starting/reference PDB file',
219 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
220 file1 = forms.FileField(label='Upload a PDB file',required=False,
221 help_text='starting structure for pdbstart/reference structure')
222 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
223 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
224 help_text='total number of steps')
225 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
226 help_text='seed for random number generator')
227 md_ntwe = forms.IntegerField(label='NTWE',initial=1000,
228 help_text='write statfile every ntwe steps')
229 md_dt = forms.FloatField(label='DT',initial=0.2,
230 help_text='time step [mtu]')
231 md_lang = forms.ChoiceField(choices=MD_LANG,label='thermostat')
232 md_tau = forms.FloatField(label='tau_bath',initial=1.0,
233 help_text='coupling to the thermal bath (Berendsen)')
234 md_scal_fric = forms.FloatField(label='scal_froc',initial=0.02,
235 help_text='scaling of the friction coefficients (Langevin)')
236 remd_nrep = forms.IntegerField(label='NREP',initial=8,
237 help_text='number of replicas')
238 remd_nstex = forms.IntegerField(label='NSTEX',initial=1000,
239 help_text='exchange and write trajectory every nstex steps')
240 remd_cluter_temp = forms.FloatField(label='TEMPER',
241 help_text='temperature for cluster analysis',initial=280)
242 # remd_traj1file = forms.BooleanField(required=False,label='single trajectory file',initial='true')
243 # remd_rest1file = forms.BooleanField(required=False,label='single restart file',initial='true')
246 cleaned_data = super(TaskForm_remd_a, self).clean()
248 md_start = cleaned_data.get("md_start")
249 file1 = cleaned_data.get("file1")
250 md_seq = cleaned_data.get("md_seq")
251 md_pdbref = cleaned_data.get("md_pdbref")
253 if md_start == 'pdbstart' and not file1:
254 msg = 'pdbstart with no PDB file'
255 self.add_error('file1', msg)
257 if md_pdbref and not file1:
258 msg = 'pdbref with no PDB file'
259 self.add_error('file1', msg)
262 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
263 msg = 'extended/random chain with no sequence'
264 self.add_error('md_seq', msg)
267 class TaskForm_list(forms.Form):
268 name = forms.CharField(max_length=20,disabled=True,required=False)
269 nrep = forms.IntegerField(disabled=True,required=False,label='NREP')
271 def __init__(self, count, *args, **kwargs):
272 super(TaskForm_list, self).__init__(*args, **kwargs)
274 self.fields['temperatures'] = MultiExampleField(self.count)
275 self.fields['multiplexing'] = MultiExampleField(self.count)