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
8 class MultiWidgetBasic(forms.MultiWidget):
9 def __init__(self, count, attrs=None):
12 for i in range(self.count):
13 widgets.append(forms.TextInput())
14 super(MultiWidgetBasic, self).__init__(widgets, attrs)
16 template_name = 'multi.html'
18 def decompress(self, value):
20 return json.loads(value)
25 class MultiExampleField(forms.fields.MultiValueField):
26 def __init__(self, count, *args, **kwargs):
28 self.widget = MultiWidgetBasic(self.count)
30 for i in range(self.count):
31 list_fields.append(forms.fields.CharField(max_length=15))
32 super(MultiExampleField, self).__init__(list_fields, *args, **kwargs)
34 def compress(self, values):
35 ## compress list to single object
36 return json.dumps(values)
39 class TaskForm(forms.Form):
40 name = forms.CharField(max_length=20)
43 class TaskForm_min(forms.Form):
44 name = forms.CharField(max_length=20)
45 file1 = forms.FileField(label='Upload a PDB file',
46 help_text='continuous (without breaks) protein chains,use TER to divide chains')
49 class TaskForm_min_a(forms.Form):
50 name = forms.CharField(max_length=20)
52 min_choice = forms.ChoiceField(choices=MIN_CHOICE,label='minimization algorithm')
53 min_overlap = forms.BooleanField(required=False,label='remove overlap')
54 min_searchsc = forms.BooleanField(required=False,label='MC for sidechain overlap')
55 min_maxmin = forms.IntegerField(label='MAXMIN',initial=10000,
56 help_text='maximum number of iterations')
57 min_maxfun = forms.IntegerField(label='MAXFUN',initial=15000,
58 help_text='maximum number of function evaluations')
59 file1 = forms.FileField(label='Upload a PDB file',
60 help_text='continuous (without breaks) protein chains,use TER to divide chains')
62 min_unres_pdb = forms.BooleanField(required=False,label='uploaded input unres PDB',
63 help_text='(CA and CB atoms only, CB represents SC in UNRES)')
64 min_pdbout = forms.BooleanField(required=False,label='output PDB',initial='true')
67 class TaskForm_md(forms.Form):
68 name = forms.CharField(max_length=20)
70 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
71 label='starting structure',initial='extconf')
72 md_seq = forms.CharField(label='Sequence',
73 help_text='aminoacid sequence using one letter code<br>'+
74 'field is ignored when uploading starting/reference PDB file',
76 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
77 file1 = forms.FileField(label='Upload a PDB file',required=False,
78 help_text='starting structure for pdbstart/reference structure')
79 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
80 md_temp = forms.FloatField(label='temperature',initial=300,
81 help_text='bath temperature')
82 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
83 help_text='total number of steps')
84 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
85 help_text='seed for random number generator')
88 cleaned_data = super(TaskForm_md, self).clean()
90 md_start = cleaned_data.get("md_start")
91 file1 = cleaned_data.get("file1")
92 md_seq = cleaned_data.get("md_seq")
93 md_pdbref = cleaned_data.get("md_pdbref")
95 if md_start == 'pdbstart' and not file1:
96 msg = 'pdbstart with no PDB file'
97 self.add_error('file1', msg)
99 if md_pdbref and not file1:
100 msg = 'pdbref with no PDB file'
101 self.add_error('file1', msg)
104 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
105 msg = 'extended/random chain with no sequence'
106 self.add_error('md_seq', msg)
109 class TaskForm_md_a(forms.Form):
110 name = forms.CharField(max_length=20)
112 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
113 label='starting structure',initial='extconf')
114 md_seq = forms.CharField(label='Sequence',
115 help_text='aminoacid sequence using one letter code<br>'+
116 'field is ignored when uploading starting/reference PDB file',
118 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
119 file1 = forms.FileField(label='Upload a PDB file',required=False,
120 help_text='starting structure for pdbstart/reference structure')
121 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
122 md_temp = forms.FloatField(label='temperature',initial=300,
123 help_text='bath temperature')
124 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
125 help_text='total number of steps')
126 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
127 help_text='seed for random number generator')
129 md_ntwe = forms.IntegerField(label='NTWE',initial=1000,
130 help_text='write statfile every ntwe steps')
131 md_ntwx = forms.IntegerField(label='NTWX',initial=1000,
132 help_text='write trajectory every ntwe steps')
133 md_dt = forms.FloatField(label='DT',initial=0.2,
134 help_text='time step [mtu]')
135 md_lang = forms.ChoiceField(choices=MD_LANG,label='thermostat')
136 md_tau = forms.FloatField(label='tau_bath',initial=1.0,
137 help_text='coupling to the thermal bath (Berendsen)')
138 md_scal_fric = forms.FloatField(label='scal_froc',initial=0.02,
139 help_text='scaling of the friction coefficients (Langevin)')
140 md_mdpdb = forms.BooleanField(required=False,label='trajectory as PDB')
143 cleaned_data = super(TaskForm_md_a, self).clean()
145 md_start = cleaned_data.get("md_start")
146 file1 = cleaned_data.get("file1")
147 md_seq = cleaned_data.get("md_seq")
148 md_pdbref = cleaned_data.get("md_pdbref")
150 if md_start == 'pdbstart' and not file1:
151 msg = 'pdbstart with no PDB file'
152 self.add_error('file1', msg)
154 if md_pdbref and not file1:
155 msg = 'pdbref with no PDB file'
156 self.add_error('file1', msg)
159 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
160 msg = 'extended/random chain with no sequence'
161 self.add_error('md_seq', msg)
164 class TaskForm_remd(forms.Form):
165 name = forms.CharField(max_length=20)
167 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
168 label='starting structure',initial='extconf')
169 md_seq = forms.CharField(label='Sequence',
170 help_text='aminoacid sequence using one letter code<br>'+
171 'field is ignored when uploading starting/reference PDB file',
173 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
174 file1 = forms.FileField(label='Upload a PDB file',required=False,
175 help_text='starting structure for pdbstart/reference structure')
176 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
177 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
178 help_text='total number of steps')
179 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
180 help_text='seed for random number generator')
183 cleaned_data = super(TaskForm_remd, self).clean()
185 md_start = cleaned_data.get("md_start")
186 file1 = cleaned_data.get("file1")
187 md_seq = cleaned_data.get("md_seq")
188 md_pdbref = cleaned_data.get("md_pdbref")
190 if md_start == 'pdbstart' and not file1:
191 msg = 'pdbstart with no PDB file'
192 self.add_error('file1', msg)
194 if md_pdbref and not file1:
195 msg = 'pdbref with no PDB file'
196 self.add_error('file1', msg)
198 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
199 msg = 'extended/random chain with no sequence'
200 self.add_error('md_seq', msg)
203 class TaskForm_remd_a(forms.Form):
204 name = forms.CharField(max_length=20)
206 md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
207 label='starting structure',initial='extconf')
208 md_seq = forms.CharField(label='Sequence',
209 help_text='aminoacid sequence using one letter code<br>'+
210 'field is ignored when uploading starting/reference PDB file',
212 widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
213 file1 = forms.FileField(label='Upload a PDB file',required=False,
214 help_text='starting structure for pdbstart/reference structure')
215 md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
216 md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
217 help_text='total number of steps')
218 md_seed = forms.IntegerField(label='SEED',initial=-39912345,
219 help_text='seed for random number generator')
220 md_ntwe = forms.IntegerField(label='NTWE',initial=1000,
221 help_text='write statfile every ntwe steps')
222 md_dt = forms.FloatField(label='DT',initial=0.2,
223 help_text='time step [mtu]')
224 md_lang = forms.ChoiceField(choices=MD_LANG,label='thermostat')
225 md_tau = forms.FloatField(label='tau_bath',initial=1.0,
226 help_text='coupling to the thermal bath (Berendsen)')
227 md_scal_fric = forms.FloatField(label='scal_froc',initial=0.02,
228 help_text='scaling of the friction coefficients (Langevin)')
229 remd_nrep = forms.IntegerField(label='NREP',initial=8,
230 help_text='number of replicas')
231 remd_nstex = forms.IntegerField(label='NSTEX',initial=1000,
232 help_text='exchange and write trajectory every nstex steps')
233 remd_cluter_temp = forms.FloatField(label='TEMPER',
234 help_text='temperature for cluster analysis',initial=280)
235 # remd_traj1file = forms.BooleanField(required=False,label='single trajectory file',initial='true')
236 # remd_rest1file = forms.BooleanField(required=False,label='single restart file',initial='true')
239 cleaned_data = super(TaskForm_remd_a, self).clean()
241 md_start = cleaned_data.get("md_start")
242 file1 = cleaned_data.get("file1")
243 md_seq = cleaned_data.get("md_seq")
244 md_pdbref = cleaned_data.get("md_pdbref")
246 if md_start == 'pdbstart' and not file1:
247 msg = 'pdbstart with no PDB file'
248 self.add_error('file1', msg)
250 if md_pdbref and not file1:
251 msg = 'pdbref with no PDB file'
252 self.add_error('file1', msg)
255 if md_start != 'pdbstart' and not md_pdbref and not md_seq:
256 msg = 'extended/random chain with no sequence'
257 self.add_error('md_seq', msg)
260 class TaskForm_list(forms.Form):
261 name = forms.CharField(max_length=20,disabled=True,required=False)
262 nrep = forms.IntegerField(disabled=True,required=False,label='NREP')
264 def __init__(self, count, *args, **kwargs):
265 super(TaskForm_list, self).__init__(*args, **kwargs)
267 self.fields['temperatures'] = MultiExampleField(self.count)
268 self.fields['multiplexing'] = MultiExampleField(self.count)