d8ea95dacb0302dee5f67bae1e4832b9ef6024bd
[django_unres.git] / django_simple / todo / forms.py
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 import json
7
8 class MultiWidgetBasic(forms.MultiWidget):
9     def __init__(self, count, attrs=None):
10         self.count=count
11         widgets = []
12         for i in range(self.count):
13            widgets.append(forms.TextInput())
14         super(MultiWidgetBasic, self).__init__(widgets, attrs)
15
16     template_name = 'multi.html'
17
18     def decompress(self, value):
19         if value:
20             return json.loads(value)
21         else:
22             return ['', '']
23
24
25 class MultiExampleField(forms.fields.MultiValueField):
26     def __init__(self, count, *args, **kwargs):
27         self.count=count
28         self.widget = MultiWidgetBasic(self.count)
29         list_fields = []
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)
33
34     def compress(self, values):
35         ## compress list to single object                                               
36         return json.dumps(values)
37
38
39 class TaskForm(forms.Form):
40     name = forms.CharField(max_length=20)
41
42
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')
47                         
48             
49 class TaskForm_min_a(forms.Form):
50      name = forms.CharField(max_length=20)
51
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')
61
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')
65
66
67 class TaskForm_md(forms.Form):
68      name = forms.CharField(max_length=20)
69
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',
75                      required=False,
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')
86                   
87      def clean(self):
88              cleaned_data = super(TaskForm_md, self).clean()
89
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")
94               
95              if md_start == 'pdbstart' and not file1:
96                 msg = 'pdbstart with no PDB file'
97                 self.add_error('file1', msg)
98
99              if md_pdbref and not file1:
100                 msg = 'pdbref with no PDB file'
101                 self.add_error('file1', msg)
102
103
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)
107
108                         
109 class TaskForm_md_a(forms.Form):
110      name = forms.CharField(max_length=20)
111
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',
117                      required=False,
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')
128
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')
141
142      def clean(self):
143              cleaned_data = super(TaskForm_md_a, self).clean()
144
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")
149               
150              if md_start == 'pdbstart' and not file1:
151                 msg = 'pdbstart with no PDB file'
152                 self.add_error('file1', msg)
153
154              if md_pdbref and not file1:
155                 msg = 'pdbref with no PDB file'
156                 self.add_error('file1', msg)
157
158
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)
162
163
164 class TaskForm_remd(forms.Form):
165      name = forms.CharField(max_length=20)
166
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',
172                      required=False,
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')
181                   
182      def clean(self):
183              cleaned_data = super(TaskForm_remd, self).clean()
184
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")
189               
190              if md_start == 'pdbstart' and not file1:
191                 msg = 'pdbstart with no PDB file'
192                 self.add_error('file1', msg)
193
194              if md_pdbref and not file1:
195                 msg = 'pdbref with no PDB file'
196                 self.add_error('file1', msg)
197
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)
201
202                              
203 class TaskForm_remd_a(forms.Form):
204      name = forms.CharField(max_length=20)
205
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',
211                      required=False,
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')
237
238      def clean(self):
239              cleaned_data = super(TaskForm_remd_a, self).clean()
240
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")
245               
246              if md_start == 'pdbstart' and not file1:
247                 msg = 'pdbstart with no PDB file'
248                 self.add_error('file1', msg)
249
250              if md_pdbref and not file1:
251                 msg = 'pdbref with no PDB file'
252                 self.add_error('file1', msg)
253
254
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)
258
259
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')
263
264     def __init__(self, count, *args, **kwargs):
265         super(TaskForm_list, self).__init__(*args, **kwargs)
266         self.count=count
267         self.fields['temperatures'] = MultiExampleField(self.count)
268         self.fields['multiplexing'] = MultiExampleField(self.count)        
269      
270
271