X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=qcg%2Futils.py;h=6140e7babbf1b379516a232322827a854394da8b;hb=f2acc5c35cbf21773972b7b7e8d1c49a41774c47;hp=29f631bcfccf7d6d3ed358b6c6b469cefa8bdacd;hpb=c101141ec6a1c32fe158b2f4ed7d8fe68e702cf6;p=qcg-portal.git diff --git a/qcg/utils.py b/qcg/utils.py index 29f631b..6140e7b 100644 --- a/qcg/utils.py +++ b/qcg/utils.py @@ -1,12 +1,19 @@ +# coding=utf-8 +import os import string import random from django.core.paginator import Paginator from django.utils.formats import date_format from django.utils.timezone import localtime +from pyqcg import QCG +from pyqcg.utils import Credential +from pyqcg.description import JobDescription +from filex.ftp import FTPOperation from qcg import constants +from django.utils import encoding def get_attributes(obj, attrs): return {name: getattr(obj, name) for name in attrs if getattr(obj, name) is not None} @@ -48,3 +55,134 @@ def random_id(size=8, chars=string.ascii_uppercase + string.digits): def chunks(seq, size): return (seq[pos:pos + size] for pos in xrange(0, len(seq), size)) + +def generate_md_inputfile(params): + md_input = list() + # Opis pliku wyjsciowego + opis=params['note'][:80] + md_input.append(encoding.smart_str(opis, encoding='ascii', errors='ignore')) + # Dane kontrolne obliczen + md_input.append('SEED=-3059743 PDBREF ONE_LETTER MD EXTCONF RESCALE_MODE=2') + ctl_data='nstep='+str(params['nstep'])+' ntwe='+str(params['ntwe']) + ctl_data+=' ntwx='+str(params['ntwx'])+' dt='+str(params['dt'])+' damax='+str(params['damax'])+'lang=0 tbf' + md_input.append('{:<79}&'.format(ctl_data)) + md_input.append('tau_bath=1.0 t_bath=300 reset_vel=10000 respa ntime_split=1 maxtime_split=512') + # Paramatry pól siłowych + if params['force_field'] == 'GAB': + # Wagi pola GAB + md_input.append('WLONG=1.35279 WSCP=1.59304 WELEC=0.71534 WBOND=1.00000 WANG=1.13873 &') + md_input.append('WSCLOC=0.16258 WTOR=1.98599 WTORD=1.57069 WCORRH=0.42887 WCORR5=0.00000 &') + md_input.append('WCORR6=0.00000 WEL_LOC=0.16036 WTURN3=1.68722 WTURN4=0.66230 WTURN6=0.00000 &') + md_input.append('WVDWPP=0.11371 WHPB=1.00000 &') + md_input.append('CUTOFF=7.00000 WCORR4=0.00000 WSCCOR=0.0') + else: + # Wagi pola E0LLY + md_input.append('WLONG=1.00000 WSCP=1.23315 WELEC=0.84476 WBOND=1.00000 WANG=0.62954 &') + md_input.append('WSCLOC=0.10554 WTOR=1.84316 WTORD=1.26571 WCORRH=0.19212 WCORR5=0.00000 &') + md_input.append('WCORR6=0.00000 WEL_LOC=0.37357 WTURN3=1.40323 WTURN4=0.64673 WTURN6=0.00000 &') + md_input.append('WVDWPP=0.23173 WHPB=1.00000 WSCCOR=0.0 &') + md_input.append('CUTOFF=7.00000 WCORR4=0.00000') + # Plik PDB + md_input.append(params['pdb_file'].split('/')[-1]) + # Sekwencja aminokwasów + md_input.append(len(params['sequence'])) + seq_str=params['sequence'] + while seq_str: + md_input.append(seq_str[:80]) + seq_str=seq_str[80:] + md_input.append(' 0') + md_input.append(' 0') + + return md_input + + +def to_job_desc(params, proxy): + QCG.start() + desc = JobDescription(Credential(proxy)) + + direct_map = ('env_variables', 'executable', 'arguments', 'note', 'grant', 'hosts', 'properties', 'queue', 'procs', + 'wall_time', 'memory', 'memory_per_slot', 'modules', 'input', 'stage_in', 'native', 'notify', + 'preprocess', 'postprocess', 'persistent') + + for name in direct_map: + if params[name]: + setattr(desc, name, params[name]) + + if params['application']: + desc.set_application(*params['application']) + desc.stage_in += [params['master_file']] + desc.arguments.insert(0, os.path.basename(params['master_file'])) + if params['script']: + ftp = FTPOperation(proxy) + + ftp.mkdir(constants.QCG_DATA_URL, parents=True) + url = os.path.join(constants.QCG_DATA_URL, 'script.{}.sh'.format(random_id())) + ftp.put(url) + + for chunk in chunks(params['script'], 4096): + ftp.stream.put(chunk) + ftp.stream.put(None) + ftp.wait() + + desc.executable = url + if params['nodes']: + desc.set_nodes(*params['nodes']) + if params['reservation']: + desc.set_reservation(params['reservation']) + if params['watch_output']: + desc.set_watch_output(params['watch_output'], params['watch_output_pattern']) + + # TODO monitoring + + return desc + + +def to_form_data(xml): + # prevent circular import errors + from forms import JobDescriptionForm + + QCG.start() + desc = JobDescription() + desc.xml_description = xml + + direct_map = ('env_variables', 'executable', 'arguments', 'note', 'grant', 'hosts', 'properties', 'queue', 'procs', + 'wall_time', 'memory', 'memory_per_slot', 'modules', 'input', 'stage_in', 'native', 'persistent') + + params = {} + for name in direct_map: + attr = getattr(desc, name) + if isinstance(attr, bool) or attr: + params[name] = attr + + if desc.application is not None: + app_name, app_ver = desc.application + params['application'] = app_name if app_ver is None else app_name + '/' + app_name + stage_in = params['stage_in'] + params['stage_in'], params['master_file'] = stage_in[:-1], stage_in[-1] + params['arguments'] = params['arguments'][1:] + if desc.nodes is not None: + params['nodes'] = ':'.join(map(str, desc.nodes)) + if desc.reservation is not None: + res_id, res_type = desc.reservation + params['reservation'] = res_id + if desc.notify is not None: + params['notify_type'], params['notify_address'] = desc.notify.split(':') + if desc.watch_output is not None: + watch_output, params['watch_output_pattern'] = desc.watch_output + params['watch_output_type'], params['watch_output_address'] = watch_output.split(':') + if desc.preprocess is not None: + if desc.preprocess.startswith('gsiftp://'): + params['preprocess_type'] = JobDescriptionForm.Process.SCRIPT + params['preprocess_script'] = desc.preprocess + else: + params['preprocess_type'] = JobDescriptionForm.Process.CMD + params['preprocess_cmd'] = desc.preprocess + if desc.postprocess is not None: + if desc.postprocess.startswith('gsiftp://'): + params['postprocess_type'] = JobDescriptionForm.Process.SCRIPT + params['postprocess_script'] = desc.postprocess + else: + params['postprocess_type'] = JobDescriptionForm.Process.CMD + params['postprocess_cmd'] = desc.postprocess + + return params