From b0b453cf81a22a4af89b4f5882a54e01d38fde57 Mon Sep 17 00:00:00 2001 From: MichaelShohat <38256261+MichaelShohat@users.noreply.github.com> Date: Mon, 17 Jun 2019 00:06:14 +0300 Subject: [PATCH] latest debug sessoin --- environment.yml | 89 ++++++ runtime.txt | 1 + src/SimuMole/SimuMole/settings.py | 2 +- .../SimuMoleScripts/basicTrajectoryBuilder.py | 69 ++-- src/SimuMole/SimuMoleScripts/emailSender.py | 4 +- .../SimuMoleScripts/simulation_main_script.py | 140 +++----- .../SimuMoleScripts/uploaded_simulation.py | 35 +- src/SimuMole/SimuMoleWeb/forms.py | 301 +++++++++--------- .../templates/create_simulation.html | 12 +- .../templates/create_simulation_result.html | 5 + src/SimuMole/SimuMoleWeb/templates/home.html | 2 +- src/SimuMole/SimuMoleWeb/views.py | 72 ++--- .../media/files/_init_folder_file.txt | 1 - 13 files changed, 405 insertions(+), 328 deletions(-) create mode 100644 environment.yml create mode 100644 runtime.txt delete mode 100644 src/SimuMole/media/files/_init_folder_file.txt diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..717852c --- /dev/null +++ b/environment.yml @@ -0,0 +1,89 @@ +name: simumoleEnv +channels: + - omnia + - conda-forge + - schrodinger + - defaults +dependencies: + - apbs=1.5=h14c3975_3 + - asn1crypto=0.24.0=py37_0 + - blas=1.0=mkl + - ca-certificates=2019.3.9=hecc5488_0 + - certifi=2019.3.9=py37_0 + - cffi=1.12.3=py37h2e261b9_0 + - chardet=3.0.4=py37_1 + - cryptography=2.7=py37h72c5cf5_0 + - dbus=1.13.6=h746ee38_0 + - expat=2.2.6=he6710b0_0 + - fftw3f=3.3.4=2 + - fontconfig=2.13.0=h9420a91_0 + - freemol=1.158=py37_1 + - freetype=2.9.1=h8a8886c_1 + - glew=2.0.0=0 + - glib=2.56.2=hd408876_0 + - gst-plugins-base=1.14.0=hbbd80ab_1 + - gstreamer=1.14.0=hb453b48_1 + - h5py=2.9.0=py37h7918eee_0 + - hdf5=1.10.4=hb1b8bf9_0 + - icu=58.2=h9c2bf20_1 + - idna=2.8=py37_0 + - intel-openmp=2019.4=243 + - jpeg=9b=h024ee3a_2 + - libedit=3.1.20181209=hc058e9b_0 + - libffi=3.2.1=hd88cf55_4 + - libgcc-ng=8.2.0=hdf63c60_1 + - libgfortran-ng=7.3.0=hdf63c60_0 + - libglu=9.0.0=hf484d3e_1 + - libopenblas=0.3.6=h5a2b251_0 + - libpng=1.6.37=hbc83047_0 + - libstdcxx-ng=8.2.0=hdf63c60_1 + - libtiff=4.0.10=h2733197_2 + - libuuid=1.0.3=h1bed415_2 + - libxcb=1.13=h1bed415_1 + - libxml2=2.9.9=he19cac6_0 + - mengine=1=h14c3975_1 + - mkl=2019.4=243 + - mkl_fft=1.0.12=py37ha843d7b_0 + - mkl_random=1.0.2=py37hd81dba3_0 + - mpeg_encode=1=h14c3975_1 + - mtz2ccp4_px=1.0=h9ac9557_3 + - ncurses=6.1=he6710b0_1 + - numpy=1.16.4=py37h7e9f1db_0 + - numpy-base=1.16.4=py37hde5b4d6_0 + - olefile=0.46=py37_0 + - openmm=7.3.1=py37_cuda92_rc_2 + - openssl=1.1.1b=h14c3975_1 + - pcre=8.43=he6710b0_0 + - pdb2pqr=2.1.1=py37_1 + - pdbfixer=1.5=py37_0 + - pillow=6.0.0=py37h34e0f95_0 + - pip=19.1.1=py37_0 + - pmw=2.0.1=py37_2 + - pycparser=2.19=py37_0 + - pymol=2.3.2=py37h75f9260_0 + - pyopenssl=19.0.0=py37_0 + - pyqt=5.9.2=py37h05f1152_2 + - pysocks=1.7.0=py37_0 + - python=3.7.3=h0371630_0 + - qt=5.9.7=h5867ecd_1 + - readline=7.0=h7b6447c_5 + - requests=2.22.0=py37_0 + - rigimol=1.3=2 + - setuptools=41.0.1=py37_0 + - sip=4.19.8=py37hf484d3e_0 + - six=1.12.0=py37_0 + - sqlite=3.28.0=h7b6447c_0 + - tk=8.6.8=hbc83047_0 + - urllib3=1.24.2=py37_0 + - wheel=0.33.4=py37_0 + - xz=5.2.4=h14c3975_4 + - zlib=1.2.11=h7b6447c_3 + - zstd=1.3.7=h0b5b093_0 + - pip: + - django==2.2.2 + - django-formtools==2.1 + - py3wetransfer==0.0.2 + - python-magic==0.4.15 + - pytz==2019.1 + - sqlparse==0.3.0 + diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..9955289 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +Python 3.7.3 diff --git a/src/SimuMole/SimuMole/settings.py b/src/SimuMole/SimuMole/settings.py index 0fd89c6..08df801 100644 --- a/src/SimuMole/SimuMole/settings.py +++ b/src/SimuMole/SimuMole/settings.py @@ -24,7 +24,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['marinemr135.quickbox.io', '176.9.8.180'] # Application definition diff --git a/src/SimuMole/SimuMoleScripts/basicTrajectoryBuilder.py b/src/SimuMole/SimuMoleScripts/basicTrajectoryBuilder.py index 833b776..5702297 100644 --- a/src/SimuMole/SimuMoleScripts/basicTrajectoryBuilder.py +++ b/src/SimuMole/SimuMoleScripts/basicTrajectoryBuilder.py @@ -10,26 +10,29 @@ traj_dcd = 'trajectory.dcd' -def scr(input_coor_name, temperature, time_step_number): +def scr(input_coor_name, temperature, time_step_number, user_rand): + dir_path = 'media/files/' + user_rand + '/' + simulation_status_path = dir_path + 'simulation_status.txt' + simulation_status_during_run_path = dir_path + 'simulation_status_during_run.txt' + trajectory_path = dir_path pdb = app.PDBFile(input_coor_name) forcefield = app.ForceField('amber99sbildn.xml', 'tip3p.xml') - system = forcefield.createSystem(pdb.topology, nonbondedMethod=app.NoCutoff, constraints=app.HBonds, rigidWater=True) integrator = mm.LangevinIntegrator(temperature * unit.kelvin, 1.0 / unit.picoseconds, 2.0 * unit.femtoseconds) integrator.setConstraintTolerance(0.00001) - platform = mm.Platform.getPlatformByName('OpenCL') - properties = {'OpenCLPrecision': 'mixed'} - simulation = app.Simulation(pdb.topology, system, integrator, platform, properties) + platform = mm.Platform.getPlatformByName('CPU') + + simulation = app.Simulation(pdb.topology, system, integrator, platform) simulation.context.setPositions(pdb.positions) - update_simulation_status('Minimizing energy...') + update_simulation_status('Minimizing energy...', user_rand) simulation.minimizeEnergy() simulation.context.setVelocitiesToTemperature(temperature * unit.kelvin) - update_simulation_status('Equilibrating...') + update_simulation_status('Equilibrating...', user_rand) simulation.step(100) simulation.reporters.append(app.DCDReporter(trajectory_path + traj_dcd, 1000)) @@ -37,40 +40,46 @@ def scr(input_coor_name, temperature, time_step_number): app.StateDataReporter(simulation_status_during_run_path, 1000, progress=True, remainingTime=True, totalSteps=time_step_number, separator=',')) - update_simulation_status('Running simulation...') + update_simulation_status('Running simulation...', user_rand) simulation.step(time_step_number) -def update_simulation_status(status): +def update_simulation_status(status, user_rand): + dir_path = 'media/files/' + user_rand + '/' + simulation_status_path = dir_path + 'simulation_status.txt' + simulation_status_during_run_path = dir_path + 'simulation_status_during_run.txt' + trajectory_path = dir_path + with open(simulation_status_path, "w+") as f: f.write(status) -def scr_for_checks(input_coor_name): - forcefield = app.ForceField('amber96.xml', 'tip3p.xml') +def scr_for_checks(input_coor_name, user_rand, full_check=False): pdb = app.PDBFile(input_coor_name) + forcefield = app.ForceField('amber99sbildn.xml', 'tip3p.xml') - system = forcefield.createSystem(pdb.topology, nonbondedMethod=app.PME, - nonbondedCutoff=1.0 * unit.nanometers, constraints=app.HBonds, rigidWater=True, - ewaldErrorTolerance=0.0005) - integrator = mm.LangevinIntegrator(300 * unit.kelvin, 1.0 / unit.picoseconds, - 2.0 * unit.femtoseconds) - integrator.setConstraintTolerance(0.00001) + # The following line causes an error (when we do not perform "fix pdb") + system = forcefield.createSystem(pdb.topology, nonbondedMethod=app.NoCutoff, constraints=app.HBonds, + rigidWater=True) - platform = mm.Platform.getPlatformByName('OpenCL') - properties = {'OpenCLPrecision': 'mixed'} - simulation = app.Simulation(pdb.topology, system, integrator, platform, properties) - simulation.context.setPositions(pdb.positions) + if full_check: + integrator = mm.LangevinIntegrator(300 * unit.kelvin, 1.0 / unit.picoseconds, 2.0 * unit.femtoseconds) + integrator.setConstraintTolerance(0.00001) - print('Minimizing...') - simulation.minimizeEnergy() + platform = mm.Platform.getPlatformByName('CPU') + + simulation = app.Simulation(pdb.topology, system, integrator, platform) + simulation.context.setPositions(pdb.positions) - simulation.context.setVelocitiesToTemperature(300 * unit.kelvin) - print('Equilibrating...') - simulation.step(100) + # Minimizing + simulation.minimizeEnergy() + + simulation.context.setVelocitiesToTemperature(300 * unit.kelvin) + + # Equilibrating + simulation.step(100) - simulation.reporters.append(app.DCDReporter('media/files/' + 'very_good.dcd', 1000)) + simulation.reporters.append(app.DCDReporter('media/files/' + user_rand + '/' + 'scr_for_checks.dcd', 1000)) - print('Running Production...') - simulation.step(1000) - print('Done!') + # Running Production + simulation.step(1000) diff --git a/src/SimuMole/SimuMoleScripts/emailSender.py b/src/SimuMole/SimuMoleScripts/emailSender.py index d0ce66c..240b370 100644 --- a/src/SimuMole/SimuMoleScripts/emailSender.py +++ b/src/SimuMole/SimuMoleScripts/emailSender.py @@ -25,8 +25,8 @@ size_limit = 10 * megabyte -def send_email(receiver, file_name): - file_name = "./media/files/" + file_name +def send_email(receiver, file_name, user_rand): + file_name = "./media/files/" + user_rand + '/' + file_name size = os.stat(file_name).st_size if size < size_limit: send_file_attached(receiver, file_name) diff --git a/src/SimuMole/SimuMoleScripts/simulation_main_script.py b/src/SimuMole/SimuMoleScripts/simulation_main_script.py index 7193322..50fce4b 100644 --- a/src/SimuMole/SimuMoleScripts/simulation_main_script.py +++ b/src/SimuMole/SimuMoleScripts/simulation_main_script.py @@ -1,11 +1,10 @@ from time import sleep -import pymol +import pymol2 +import os from .fix_pdb import fix_pdb from .basicTrajectoryBuilder import scr, update_simulation_status -from .transformations import translate_pdb -temp = 'media/files/' # path to temp folder pdb = '.pdb' # pdb suffix @@ -13,10 +12,11 @@ class Simulation: def __init__(self, num_of_proteins, first_pdb_type, first_pdb_id, second_pdb_type, second_pdb_id, x1, y1, z1, x2, y2, z2, degXY_1, degYZ_1, degXY_2, degYZ_2, temperature_scale, temperature, - time_step_number): + time_step_number, user_rand): self.cmd = None - + self.user_rand = user_rand + self.temp = 'media/files/' + self.user_rand + '/' self.num_of_proteins = num_of_proteins self.first_pdb_type = first_pdb_type @@ -41,104 +41,59 @@ def __init__(self, num_of_proteins, first_pdb_type, first_pdb_id, second_pdb_typ self.time_step_number = (int(time_step_number) - 1) * 1000 def create_simulation(self): - pymol.finish_launching(['pymol', '-q']) # pymol: -q quiet launch, -c no gui, -e fullscreen - self.cmd = pymol.cmd - filename_1 = '_1_' - filename_2 = '_2_' - if self.num_of_proteins == '2': - # STEP 1: load input pdb - if self.first_pdb_type == 'by_id': - self.save_pdb_by_id(self.first_pdb_id, filename_1 + pdb) - if self.second_pdb_type == 'by_id': - self.save_pdb_by_id(self.second_pdb_id, filename_2 + pdb) - - # STEP 2: fix positions - filename_1_movement = filename_1 + '__movement' - filename_2_movement = filename_2 + '__movement' - translate_pdb(temp + filename_1 + pdb, temp + filename_1_movement + pdb, self.x1, self.y1, self.z1, - self.degXY_1, self.degYZ_1) - translate_pdb(temp + filename_2 + pdb, temp + filename_2_movement + pdb, self.x2, self.y2, self.z2, - self.degXY_2, self.degYZ_2) - - # STEP 2.5: fix pdb - fix_pdb(temp + filename_1_movement + pdb) - fix_pdb(temp + filename_2_movement + pdb) - - # STEP 3: merge to single pdb file - self.save_pdbs_in_one_pdb(filename_1_movement, filename_2_movement) - - # STEP 3.5: fix pdb - fix_pdb(temp + "both__" + filename_1_movement + '_' + filename_2_movement + pdb) - - # STEP 4: use OpenMM - input_coor_name = temp + "both__" + filename_1_movement + '_' + filename_2_movement + pdb - scr(input_coor_name, self.temperature, self.time_step_number) + #pymol.finish_launching(['pymol', '-q']) # pymol: -q quiet launch, -c no gui, -e fullscreen + #self.cmd = pymol.cmd + p1 = pymol2.PyMOL() + p1.start() + self.cmd = p1.cmd + + # define input files to 'create_simulation_pdb': + if self.num_of_proteins == '2': + input_coor_name = 'both_1_2' else: - # STEP 1: load input pdb - if self.first_pdb_type == 'by_id': - self.save_pdb_by_id(self.first_pdb_id, filename_1 + pdb) - - # STEP 2: fix positions - filename_1_movement = filename_1 + '__movement' - translate_pdb(temp + filename_1 + pdb, temp + filename_1_movement + pdb, self.x1, self.y1, self.z1, - self.degXY_1, self.degYZ_1) - - # STEP 2.5: fix pdb - fix_pdb(temp + filename_1_movement + pdb) - - # STEP 3: use OpenMM - input_coor_name = temp + filename_1_movement + pdb - try: - scr(input_coor_name, self.temperature, self.time_step_number) - except: - update_simulation_status('An error occurred while creating the simulation. Please try again later.') - return - - # save the DCD file using PyMOL + input_coor_name = '_1_' + try: + # run OpenMM: + input_coor_name = self.temp + input_coor_name + pdb + fix_pdb(input_coor_name) + scr(input_coor_name, self.temperature, self.time_step_number, self.user_rand) + + # save the DCD file using PyMOL self.cmd.reinitialize() + sleep(0.5) self.cmd.load(input_coor_name) - self.cmd.load_traj(temp + 'trajectory.dcd') - except: # mainly for "pymol.CmdException" - update_simulation_status('An error occurred while creating the simulation. Please try again later.') + self.cmd.load_traj(self.temp + 'trajectory.dcd') + + except Exception as e: # mainly for "pymol.CmdException" + print(str(e)) + update_simulation_status('An error occurred while creating the simulation. Please try again later.', self.user_rand) return - # create the animations: - update_simulation_status('Creates the animations') - create_movies_from_different_angles(self.cmd) # create movies in media/movies folder + try: + # create the animations: + update_simulation_status('Creates the animations', self.user_rand) + create_movies_from_different_angles(self.cmd, self.user_rand) # create movies in media/movies folder + except Exception as e: # mainly for "pymol.CmdException" + print(str(e)) + update_simulation_status('An error occurred while creating the animations. Please try again later.', self.user_rand) + return # complete simulation: - update_simulation_status('Done!') - # self.cmd.quit() # todo: need to close PyMol window + update_simulation_status('Done!', self.user_rand) - def clear_simulation(self): # todo: complete this! delete all temporary files + def clear_simulation(self): # todo: complete this, need to delete all temporary files # os.remove('path/to/files') return - def save_pdb_by_id(self, pdb_id, name_of_file): - self.cmd.reinitialize() - sleep(0.5) - - self.cmd.load("https://files.rcsb.org/download/" + pdb_id + pdb) - self.cmd.zoom() - self.cmd.save(temp + name_of_file) - - def save_pdbs_in_one_pdb(self, filename_1, filename_2): - self.cmd.reinitialize() - sleep(0.5) - - self.cmd.load(temp + filename_1 + pdb) - self.cmd.load(temp + filename_2 + pdb) - self.cmd.zoom() - self.cmd.save(temp + "both__" + filename_1 + '_' + filename_2 + pdb) - @staticmethod + #not used def merge_pdbs_by_copy(filename_1, filename_2, do_fix=True): - merged_pdb = temp + "both__" + filename_1 + "_" + filename_2 + pdb + merged_pdb = self.temp + "both__" + filename_1 + "_" + filename_2 + pdb merged_file = open(merged_pdb, 'w') - file1 = open(temp + filename_1 + pdb) - file2 = open(temp + filename_2 + pdb) + file1 = open(self.temp + filename_1 + pdb) + file2 = open(self.temp + filename_2 + pdb) for line in file1: if not (line.startswith('MASTER') or line.startswith('END')): merged_file.write(line) @@ -154,7 +109,8 @@ def merge_pdbs_by_copy(filename_1, filename_2, do_fix=True): # FUNCTION IS ASSUMING TRAJECTORY AND PDB FILES ARE LOADED # output: 3*3 + 1 auto generated movies from different angles -def create_movies_from_different_angles(cmd): +def create_movies_from_different_angles(cmd, user_rand): + os.mkdir("media/videos/" + user_rand) sleep(0.5) cmd.do("run SimuMoleScripts/axes.py") cmd.do("orient") @@ -173,7 +129,7 @@ def create_movies_from_different_angles(cmd): (0, 0, 90), (0, 0, 180), (0, 0, 270), # Z axis ] for x, y, z in angels: - update_simulation_status('Creates the animations ({} of {})'.format(i + 1, len(angels))) + update_simulation_status('Creates the animations ({} of {})'.format(i + 1, len(angels)), user_rand) x, y, z = str(x), str(y), str(z) cmd.sync() cmd.do("turn x, " + x) @@ -184,7 +140,7 @@ def create_movies_from_different_angles(cmd): cmd.sync() cmd.do("zoom complete = 1") cmd.sync() - cmd.do("movie.produce media/videos/video_" + str(i) + ".mp4, quality = 90,preserve=0") + cmd.do("movie.produce media/videos/" + user_rand + "/" + "video_" + str(i) + ".mp4, quality = 90,preserve=0") cmd.sync() sleep(3) # Sleep might not be a solution, but without it the commands run too fast and make errors. # Attempting to use the sync command on 'produce' doesnt seem to work. @@ -194,4 +150,6 @@ def create_movies_from_different_angles(cmd): cmd.sync() cmd.do("turn x, " + "-" + x) cmd.sync() - i = i + 1 \ No newline at end of file + i = i + 1 + + cmd.do("reinitialize") diff --git a/src/SimuMole/SimuMoleScripts/uploaded_simulation.py b/src/SimuMole/SimuMoleScripts/uploaded_simulation.py index 383cbb5..b22ba23 100644 --- a/src/SimuMole/SimuMoleScripts/uploaded_simulation.py +++ b/src/SimuMole/SimuMoleScripts/uploaded_simulation.py @@ -1,39 +1,44 @@ import pymol from .simulation_main_script import create_movies_from_different_angles from .basicTrajectoryBuilder import update_simulation_status +from time import sleep temp = 'media/files/' # path to temp folder -def pdb_and_dcd_match(pdb_file_name, dcd_file_name): # todo: remove gui +def pdb_and_dcd_match(pdb_file_name, dcd_file_name): pymol.finish_launching(['pymol', '-q']) # pymol: -q quiet launch, -c no gui, -e fullscreen cmd = pymol.cmd try: cmd.reinitialize() + sleep(0.5) cmd.load(temp + pdb_file_name) cmd.load_traj(temp + dcd_file_name) return True - except: + except Exception as e: + print(str(e)) return False def create_animations(): - # for now, only open pymol window: #todo: create the animations instead of only open PyMOL - pymol.finish_launching(['pymol', '-q']) # pymol: -q quiet launch, -c no gui, -e fullscreen - cmd = pymol.cmd try: + pymol.finish_launching(['pymol', '-q']) # pymol: -q quiet launch, -c no gui, -e fullscreen + cmd = pymol.cmd + + # load input cmd.reinitialize() + sleep(0.5) cmd.load(temp + "file_upload_pdb.pdb") cmd.load_traj(temp + "file_upload_dcd.dcd") - except: # mainly for "pymol.CmdException" - update_simulation_status( - 'An error occurred while creating the simulation. Please try again later.') # todo: change error message! - return - # create the animations: - update_simulation_status('Creates the animations') - create_movies_from_different_angles(cmd) # create movies in media/movies folder + # create the animations: + update_simulation_status('Creates the animations') + create_movies_from_different_angles(cmd) # create movies in media/movies folder + + # complete simulation: + update_simulation_status('Done!') - # complete simulation: - update_simulation_status('Done!') - # self.cmd.quit() # todo: need to close PyMol window + except Exception as e: # mainly for "pymol.CmdException" + print(str(e)) + update_simulation_status('An error occurred while creating the animations. Please try again later.') + return diff --git a/src/SimuMole/SimuMoleWeb/forms.py b/src/SimuMole/SimuMoleWeb/forms.py index 90036e0..202cb71 100644 --- a/src/SimuMole/SimuMoleWeb/forms.py +++ b/src/SimuMole/SimuMoleWeb/forms.py @@ -7,22 +7,20 @@ from django.conf import settings from SimuMoleScripts.basicTrajectoryBuilder import scr_for_checks from SimuMoleScripts.fix_pdb import fix_pdb -from SimuMoleScripts.transformations import get_atoms, get_atoms_string, translate_vecs, rotate_molecular +from SimuMoleScripts.transformations import get_atoms, get_atoms_string, translate_vecs, rotate_molecular, translate_pdb from SimuMoleScripts.uploaded_simulation import pdb_and_dcd_match - +import random +import string import os +import pymol2 +from time import sleep ################################ # Create Simulation ################################ -do_checks_cnt = 0 - class SimulationForm0_LoadPdb(forms.Form): - global do_checks - do_checks = True - num_of_proteins = forms.ChoiceField( required=True, label='Choose whether to load one or two proteins', @@ -46,124 +44,123 @@ class SimulationForm0_LoadPdb(forms.Form): widget=forms.RadioSelect) second_pdb_id = forms.CharField(required=False, label='Enter your second pdb ID', max_length=10) second_pdb_file = forms.FileField(required=False, label='Upload your second pdb file') - + + user_rand = forms.CharField(required=False, label='', initial = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8))) + @staticmethod def save_file(file: UploadedFile, filename: str): file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'files')) file_storage.delete(filename) # delete existing file with same name (due to clean_my_file previous calls) file_storage.save(filename, file) # save existing file - @staticmethod - def update_cnt(): - global do_checks_cnt - loop_amount = 9 - - if do_checks_cnt < loop_amount - 1: - do_checks_cnt += 1 - else: - do_checks_cnt = 0 - def clean(self): cleaned_data = super(SimulationForm0_LoadPdb, self).clean() - # data = {**self.initial, **cleaned_data} # self.initial->from previous steps, cleaned_data->from current step - SimulationForm0_LoadPdb.update_cnt() - return cleaned_data - - # first pdb validation: + data = {**self.initial, **cleaned_data} # self.initial->from previous steps, cleaned_data->from current step - def clean_first_pdb_type(self): - num_of_proteins = self.cleaned_data['num_of_proteins'] - first_pdb_type = self.cleaned_data['first_pdb_type'] + errors = [] + first_id_exist, first_file_exist, second_id_exist, second_file_exist = False, False, False, False + + # ....................................................................# + # check that the form structure is valid + # ("field is required" errors) + # ....................................................................# + + num_of_proteins = data.get('num_of_proteins', None) + first_pdb_type = data.get('first_pdb_type', None) + first_pdb_id, first_pdb_file = data.get('first_pdb_id', None), data.get('first_pdb_file', None) + second_pdb_type = data.get('second_pdb_type', None) + second_pdb_id, second_pdb_file = data.get('second_pdb_id', None), data.get('second_pdb_file', None) + user_rand = data.get('user_rand', None) + # clean_first_pdb_type if num_of_proteins == '1' or num_of_proteins == '2': - if first_pdb_type == '': - raise forms.ValidationError("This field is required.") - return first_pdb_type - - def clean_first_pdb_id(self): - num_of_proteins = self.cleaned_data['num_of_proteins'] - if self.cleaned_data.get('first_pdb_type') is not None: - first_pdb_type = self.cleaned_data['first_pdb_type'] - first_pdb_id = self.cleaned_data['first_pdb_id'] + if (first_pdb_type is None) or (first_pdb_type == ''): + errors.append(forms.ValidationError("First protein: The 'PDB type' field is required.")) + + # clean_first_pdb_id + if first_pdb_type is not None: if (num_of_proteins == '1' or num_of_proteins == '2') and first_pdb_type == 'by_id': - if first_pdb_id == '': - raise forms.ValidationError("This field is required.") + if (first_pdb_id is None) or (first_pdb_id == ''): + errors.append(forms.ValidationError("First protein: The 'by id' field is required.")) else: - self.pdb_id_validation(first_pdb_id) - return first_pdb_id + first_id_exist = True - def clean_first_pdb_file(self): - num_of_proteins = self.cleaned_data['num_of_proteins'] - if self.cleaned_data.get('first_pdb_type') is not None: - first_pdb_type = self.cleaned_data['first_pdb_type'] + # clean_first_pdb_file + if first_pdb_type is not None: first_pdb_file: UploadedFile = self.cleaned_data['first_pdb_file'] if (num_of_proteins == '1' or num_of_proteins == '2') and first_pdb_type == 'by_file': - if first_pdb_file == '': - raise forms.ValidationError("This field is required.") + if (first_pdb_file is None) or (first_pdb_file == ''): + errors.append(forms.ValidationError("First protein: The 'by file' field is required.")) else: - pass - # self.pdb_file_validation(first_pdb_file) - # TODO: fix - self.save_file(first_pdb_file, "_1_.pdb") - return first_pdb_file + first_file_exist = True - # second pdb validation: - - def clean_second_pdb_type(self): - num_of_proteins = self.cleaned_data['num_of_proteins'] - second_pdb_type = self.cleaned_data['second_pdb_type'] + # clean_second_pdb_type if num_of_proteins == '2': - if second_pdb_type == '': - raise forms.ValidationError("This field is required.") - return second_pdb_type - - def clean_second_pdb_id(self): - num_of_proteins = self.cleaned_data['num_of_proteins'] - if self.cleaned_data.get('second_pdb_type') is not None: - second_pdb_type = self.cleaned_data['second_pdb_type'] - second_pdb_id = self.cleaned_data['second_pdb_id'] + if (second_pdb_type is None) or (second_pdb_type == ''): + errors.append(forms.ValidationError("Second protein: The 'PDB type' field is required.")) + + # clean_second_pdb_id + if second_pdb_type is not None: if (num_of_proteins == '2') and second_pdb_type == 'by_id': - if second_pdb_id == '': - raise forms.ValidationError("This field is required.") + if (second_pdb_id is None) or (second_pdb_id == ''): + errors.append(forms.ValidationError("Second protein: The 'by id' field is required.")) else: - self.pdb_id_validation(second_pdb_id) - return second_pdb_id + second_id_exist = True - def clean_second_pdb_file(self): - num_of_proteins = self.cleaned_data['num_of_proteins'] - if self.cleaned_data.get('second_pdb_type') is not None: - second_pdb_type = self.cleaned_data['second_pdb_type'] + # clean_second_pdb_file + if second_pdb_type is not None: second_pdb_file: UploadedFile = self.cleaned_data['second_pdb_file'] if (num_of_proteins == '2') and second_pdb_type == 'by_file': - if second_pdb_file == '': - raise forms.ValidationError("This field is required.") + if (second_pdb_file is None) or (second_pdb_file == ''): + errors.append(forms.ValidationError("Second protein: The 'by file' field is required.")) else: - pass - # self.pdb_file_validation(second_pdb_file) - # TODO: fix - self.save_file(second_pdb_file, "_2_.pdb") - return second_pdb_file + second_file_exist = True - # pdb validation checks: - - def pdb_id_validation(self, pdb_id): - global do_checks_cnt - if do_checks_cnt != 0: - return + if len(errors) != 0: + raise forms.ValidationError(errors) - if not self.pdb_id_exists(pdb_id): - raise forms.ValidationError("invalid PDB id") + # ....................................................................# + # check that the input PDBs structure is valid + # ("Invalid PDB id" / "Protein not supported by OpenMM" errors) + # ....................................................................# + if (not os.path.exists("media/files/" + user_rand)): + os.mkdir("media/files/" + user_rand) + + if first_id_exist: + pdb_validation_result = self.pdb_id_validation(first_pdb_id, "_1_.pdb", user_rand) + if pdb_validation_result is not None: + errors.append(forms.ValidationError("First protein: " + pdb_validation_result)) + if first_file_exist: + self.save_file(first_pdb_file, "_1_.pdb") + pdb_validation_result = self.pdb_file_validation("media/files/" + user_rand + '/' + "_1_.pdb", user_rand) + if pdb_validation_result is not None: + errors.append(forms.ValidationError("First protein: " + pdb_validation_result)) + if second_id_exist: + pdb_validation_result = self.pdb_id_validation(second_pdb_id, "_2_.pdb", user_rand) + if pdb_validation_result is not None: + errors.append(forms.ValidationError("Second protein: " + pdb_validation_result)) + if second_file_exist: + self.save_file(second_pdb_file, "_2_.pdb") + pdb_validation_result = self.pdb_file_validation("media/files/" + user_rand + '/' + "_2_.pdb", user_rand) + if pdb_validation_result is not None: + errors.append(forms.ValidationError("Second protein: " + pdb_validation_result)) - # if not self.pdb_id_valid(pdb_id): - # raise forms.ValidationError("Protein not supported by OpenMM") - # TODO: fix + if len(errors) != 0: + raise forms.ValidationError(errors) + + #cleaned_data['user_rand'] = user_rand + return cleaned_data - def pdb_file_validation(self, pdb_id): - global do_checks_cnt - if do_checks_cnt != 0: - return + def pdb_id_validation(self, pdb_id, filename, user_rand): + if not self.pdb_id_exists(pdb_id): + return "Invalid PDB id" + if not self.pdb_id_valid(pdb_id, filename, user_rand): + return "Protein not supported by OpenMM" + return None - if not self.pdb_file_valid(pdb_id): - raise forms.ValidationError("Protein not supported by OpenMM") + def pdb_file_validation(self, pdb_id, user_rand): + if not self.pdb_file_valid(pdb_id, user_rand): + return "Protein not supported by OpenMM" + return None @staticmethod def pdb_id_exists(pdb_id): @@ -173,39 +170,39 @@ def pdb_id_exists(pdb_id): return True @staticmethod - def download_pdb(pdb_id): + def download_pdb(pdb_id, filename, user_rand): response = requests.get("https://files.rcsb.org/view/" + pdb_id + ".pdb") - pdb_file_name = "media/files/" + pdb_id + ".pdb" + pdb_file_name = "media/files/" + user_rand + '/' + filename pdb_file = open(pdb_file_name, 'w') pdb_file.write(response.text) pdb_file.close() response.close() return pdb_file_name - ''' - Checks whether a pdb id can be used in an openMM simulation by downloading the relevant file and testing it. - This function assumes the id is valid. - ''' - @staticmethod - def pdb_id_valid(pdb_id): - pdb_file_name = SimulationForm0_LoadPdb.download_pdb(pdb_id) - return SimulationForm0_LoadPdb.pdb_file_valid(pdb_file_name) - - ''' - Checks if the given file can be used in an openMM simulation. - If it can run without fixing then it returns true. - If it can run with fixing it will return true AND fix the file. - Otherwise it returns false. - ''' + def pdb_id_valid(pdb_id, filename, user_rand): + """ + Checks whether a pdb id can be used in an openMM simulation by downloading the relevant file and testing it. + This function assumes the id is valid. + """ + pdb_file_name = SimulationForm0_LoadPdb.download_pdb(pdb_id, filename, user_rand) + return SimulationForm0_LoadPdb.pdb_file_valid(pdb_file_name, user_rand) @staticmethod - def pdb_file_valid(pdb_file): - dcd_file = "media/files/very_good.dcd" + def pdb_file_valid(pdb_file_name, user_rand): + """ + Checks if the given file can be used in an openMM simulation. + If it can run without fixing then it returns true. + If it can run with fixing it will return true AND fix the file. + Otherwise it returns false. + """ + dcd_file = "media/files/" + user_rand + '/' + "scr_for_checks.dcd" + fix_not_needed = True try: - scr_for_checks(pdb_file) - except Exception: + scr_for_checks(pdb_file_name, user_rand) + except Exception as e: + # print(str(e)) fix_not_needed = False finally: if os.path.exists(dcd_file): @@ -215,13 +212,12 @@ def pdb_file_valid(pdb_file): return True try: - fix_pdb(pdb_file) - scr_for_checks(pdb_file) - except Exception: + fix_pdb(pdb_file_name) + scr_for_checks(pdb_file_name, user_rand) + except Exception as e: + print(str(e)) return False - finally: - if os.path.exists(dcd_file): - os.remove(dcd_file) + return True @@ -245,20 +241,48 @@ def clean(self): if data[field] == '' or data[field] is None: raise forms.ValidationError("All fields are required.") - if not self.position_is_valid(data['x1'], data['y1'], data['z1'], - data['x2'], data['y2'], data['z2'], - data['degXY_1'], data['degYZ_1'], data['degXY_2'], data['degYZ_2'], - data['first_pdb_id'], data['second_pdb_id'], data['first_pdb_type'], - data['second_pdb_type'], data['first_pdb_file'], data['second_pdb_file']): + if not self.position_is_valid(data['x1'], data['y1'], data['z1'], data['x2'], data['y2'], data['z2'], + data['degXY_1'], data['degYZ_1'], data['degXY_2'], data['degYZ_2'], data['user_rand']): raise forms.ValidationError("Positions are not possible: The proteins collide with each other") + self.change_relative_position(data['x1'], data['y1'], data['z1'], data['x2'], data['y2'], data['z2'], + data['degXY_1'], data['degYZ_1'], data['degXY_2'], data['degYZ_2'], data['user_rand']) + return cleaned_data @staticmethod - def position_is_valid(x1, y1, z1, x2, y2, z2, degXY_1, degYZ_1, degXY_2, degYZ_2, - first_pdb_id, second_pdb_id, first_pdb_type, second_pdb_type, - first_pdb_file, second_pdb_file): - # DONE 6: check with PyMol that the proteins do not collide with each other (need to add the pdbs parameters) + def change_relative_position(x1, y1, z1, x2, y2, z2, degXY_1, degYZ_1, degXY_2, degYZ_2, user_rand): + """ + Save PDB file that represents the 2 PDB files after you change the positions and running pdb_fixer + """ + # change positions + filename_1, filename_2, pdb, temp = '_1_', '_2_', '.pdb', 'media/files/' + user_rand + '/' + filename_1_movement, filename_2_movement = filename_1 + '__movement', filename_2 + '__movement' + translate_pdb(temp + filename_1 + pdb, temp + filename_1_movement + pdb, x1, y1, z1, degXY_1, degYZ_1) + translate_pdb(temp + filename_2 + pdb, temp + filename_2_movement + pdb, x2, y2, z2, degXY_2, degYZ_2) + + # fix pdb + fix_pdb(temp + filename_1_movement + pdb) + fix_pdb(temp + filename_2_movement + pdb) + + # merge to single pdb file + #pymol.finish_launching(['pymol', '-q']) # pymol: -q quiet launch, -c no gui, -e fullscreen + #cmd = pymol.cmd + p1 = pymol2.PyMOL() + p1.start() + cmd = p1.cmd + cmd.reinitialize() + sleep(0.5) + cmd.load(temp + filename_1_movement + pdb) + cmd.load(temp + filename_2_movement + pdb) + cmd.zoom() + cmd.save(temp + "both_1_2" + pdb) + + @staticmethod + def position_is_valid(x1, y1, z1, x2, y2, z2, degXY_1, degYZ_1, degXY_2, degYZ_2, user_rand): + """ + check with PyMol that the proteins do not collide with each other + """ # return max X,Y,Z locations from all the atoms in vecs def get_max_XYZ(vecs): @@ -269,18 +293,12 @@ def get_min_XYZ(vecs): return min(vecs, key=lambda v: v[0])[0], min(vecs, key=lambda v: v[1])[1], min(vecs, key=lambda v: v[2])[2] # get the atoms of the first protein after moving it in x1,y1,z1 - if first_pdb_type == 'by_id': - vecs1 = get_atoms_string(requests.get('https://files.rcsb.org/view/' + first_pdb_id + '.pdb').text) - else: - vecs1 = get_atoms('media/files/_1_.pdb') + vecs1 = get_atoms('media/files/' + user_rand + '/' + '_1_.pdb') translate_vecs(x1, y1, z1, vecs1) rotate_molecular(x1, y1, z1, degXY_1, degYZ_1, vecs1) # get the atoms of the second protein after moving it in x2,y2,z2 - if second_pdb_type == 'by_id': - vecs2 = get_atoms_string(requests.get("https://files.rcsb.org/view/" + second_pdb_id + ".pdb").text) - else: - vecs2 = get_atoms('media/files/_2_.pdb') + vecs2 = get_atoms('media/files/' + user_rand + '/' + '_2_.pdb') translate_vecs(x2, y2, z2, vecs2) rotate_molecular(x2, y2, z2, degXY_2, degYZ_2, vecs2) @@ -311,9 +329,6 @@ class SimulationForm2_SimulationParameters(forms.Form): widget=forms.RadioSelect, initial='celsius') temperature = forms.FloatField(required=False, label='Enter temperature', initial=30) - # time_step_duration = forms.FloatField(required=False, - # label='Enter the duration of the time step (in fs/femto-second)', - # initial=2.0) // todo: check if we can add this field time_step_number = forms.IntegerField(required=False, label='Enter the number of time steps (frames)', initial=5) def clean(self): diff --git a/src/SimuMole/SimuMoleWeb/templates/create_simulation.html b/src/SimuMole/SimuMoleWeb/templates/create_simulation.html index 548557b..a2945cd 100644 --- a/src/SimuMole/SimuMoleWeb/templates/create_simulation.html +++ b/src/SimuMole/SimuMoleWeb/templates/create_simulation.html @@ -127,7 +127,15 @@

Set the parameters for the simulation

-

Loading...

+
+ {% if wizard.steps.current == '0' %} +

Checks that the PDB is valid (ID exist / file format is correct), and supported by OpenMM

+ {% elif wizard.steps.current == '1' %} +

Checks that the position is legal (the proteins do not collide with each other)

+ {% elif wizard.steps.current == '2' %} +

Validates your request

+ {% endif %} +
@@ -289,7 +297,7 @@

Set the parameters for the simulation

function hide_errorlist() { let errors = document.getElementsByClassName("errorlist"); for (let l = 0; l < errors.length; l++) { - errors[l].style.display = 'none'; + {#errors[l].style.display = 'none';#} } } diff --git a/src/SimuMole/SimuMoleWeb/templates/create_simulation_result.html b/src/SimuMole/SimuMoleWeb/templates/create_simulation_result.html index 7663dfa..18c7df8 100644 --- a/src/SimuMole/SimuMoleWeb/templates/create_simulation_result.html +++ b/src/SimuMole/SimuMoleWeb/templates/create_simulation_result.html @@ -348,6 +348,9 @@

Download output files

$.ajax({ url: '{% url 'update_simulation_status' %}', type: "get", + data: { + 'user_rand': "{{user_rand}}", + }, dataType: 'json', success: function (data) { @@ -425,6 +428,7 @@

Download output files

'dcd_file': dcd_file, 'animation_files': animations_files, 'previous_page': "{{ previous_page }}", + 'user_rand': "{{user_rand}}", }, dataType: 'json', success: function () { @@ -459,6 +463,7 @@

Download output files

'animation_files': animations_files, 'email': email, 'previous_page': "{{ previous_page }}", + 'user_rand': "{{user_rand}}", }, dataType: 'json', success: diff --git a/src/SimuMole/SimuMoleWeb/templates/home.html b/src/SimuMole/SimuMoleWeb/templates/home.html index 463653b..1ff056a 100644 --- a/src/SimuMole/SimuMoleWeb/templates/home.html +++ b/src/SimuMole/SimuMoleWeb/templates/home.html @@ -71,7 +71,7 @@

Technologies

PyMOL: a user-sponsored molecular visualization

-

Used for displaying the simulations.

{# todo: chnage this #} +

Used for displaying the simulations.

diff --git a/src/SimuMole/SimuMoleWeb/views.py b/src/SimuMole/SimuMoleWeb/views.py index 33fd84c..2114128 100644 --- a/src/SimuMole/SimuMoleWeb/views.py +++ b/src/SimuMole/SimuMoleWeb/views.py @@ -25,43 +25,29 @@ def home(request): return render(request, 'home.html', some_dict) -def news(request): - some_dict = {} - return render(request, 'news.html', some_dict) - - -def contact(request): - some_dict = {} - return render(request, 'contact.html', some_dict) - - -def about(request): - some_dict = {} - return render(request, 'about.html', some_dict) - - ################################ # Simulation Result ################################ def update_simulation_status(request): - f = open(os.path.join(settings.MEDIA_ROOT, 'files', 'simulation_status.txt'), 'r') + user_rand = request.GET.get('user_rand') + f = open(os.path.join(settings.MEDIA_ROOT, 'files' ,user_rand , 'simulation_status.txt'), 'r') simulation_status = f.read() f.close() - f = open(os.path.join(settings.MEDIA_ROOT, 'files', 'simulation_status_during_run.txt'), 'r') + f = open(os.path.join(settings.MEDIA_ROOT, 'files',user_rand, 'simulation_status_during_run.txt'), 'r') simulation_status_during_run_lines = f.readlines() simulation_status_during_run = '' if len(simulation_status_during_run_lines) == 0 \ else simulation_status_during_run_lines[-1] f.close() - video_url = settings.MEDIA_URL + 'videos/' + video_url = settings.MEDIA_URL + 'videos/' + user_rand + '/' context = {'simulation_status': simulation_status, 'simulation_status_during_run': simulation_status_during_run, 'video_path': video_url} return JsonResponse(context) -def download__create_zip(num_of_proteins, include_pdb_file, include_dcd_file, include_animations_files, previous_page): +def download__create_zip(num_of_proteins, include_pdb_file, include_dcd_file, include_animations_files, previous_page, user_rand): files = [] files_names = [] @@ -69,19 +55,19 @@ def download__create_zip(num_of_proteins, include_pdb_file, include_dcd_file, in if previous_page == 'create_simulation': file_name = '' if num_of_proteins == '1': - file_name = '_1___movement.pdb' + file_name = '_1_.pdb' if num_of_proteins == '2': - file_name = 'both___1___movement__2___movement.pdb' - files.append(os.path.join(settings.MEDIA_ROOT, 'files', file_name)) + file_name = 'both_1_2.pdb' + files.append(os.path.join(settings.MEDIA_ROOT, 'files', user_rand, file_name)) if previous_page == 'upload_files': - files.append(os.path.join(settings.MEDIA_ROOT, 'files', 'file_upload_pdb.pdb')) + files.append(os.path.join(settings.MEDIA_ROOT, 'files', user_rand, 'file_upload_pdb.pdb')) files_names.append('pdb.pdb') if include_dcd_file: if previous_page == 'create_simulation': - files.append(os.path.join(settings.MEDIA_ROOT, 'files', 'trajectory.dcd')) + files.append(os.path.join(settings.MEDIA_ROOT, 'files',user_rand, 'trajectory.dcd')) if previous_page == 'upload_files': - files.append(os.path.join(settings.MEDIA_ROOT, 'files', 'file_upload_dcd.dcd')) + files.append(os.path.join(settings.MEDIA_ROOT, 'files',user_rand, 'file_upload_dcd.dcd')) files_names.append('dcd.dcd') if include_animations_files: @@ -91,30 +77,31 @@ def download__create_zip(num_of_proteins, include_pdb_file, include_dcd_file, in (0, 0, 90), (0, 0, 180), (0, 0, 270), ] # Z axis for i, (x, y, z) in zip(range(0, 10), angels): video_name = 'video_{}.mp4'.format(str(i)) - files.append(os.path.join(settings.MEDIA_ROOT, 'videos', video_name)) + files.append(os.path.join(settings.MEDIA_ROOT, 'videos', user_rand, video_name)) video_name_at_download = 'video_{}__X{}_Y{}_Z{}.mp4'.format(str(i), str(x), str(y), str(z)) files_names.append(video_name_at_download) - print(files_names) - zip_file = zipfile.ZipFile(os.path.join(settings.MEDIA_ROOT, 'files', "SimuMole_output.zip"), "w") + zip_file = zipfile.ZipFile(os.path.join(settings.MEDIA_ROOT, 'files',user_rand, "SimuMole_output.zip"), "w") for file, file_name in zip(files, files_names): zip_file.write(file, file_name) zip_file.close() def download__zip(request): + user_rand = request.GET.get('user_rand') num_of_proteins = request.GET.get('num_of_proteins') include_pdb_file = (request.GET.get('pdb_file') == 'true') include_dcd_file = (request.GET.get('dcd_file') == 'true') include_animations_files = (request.GET.get('animation_files') == 'true') previous_page = request.GET.get('previous_page') - download__create_zip(num_of_proteins, include_pdb_file, include_dcd_file, include_animations_files, previous_page) + download__create_zip(num_of_proteins, include_pdb_file, include_dcd_file, include_animations_files, previous_page, user_rand) return JsonResponse({}) def download__email(request): + user_rand = request.GET.get('user_rand') num_of_proteins = request.GET.get('num_of_proteins') include_pdb_file = (request.GET.get('pdb_file') == 'true') include_dcd_file = (request.GET.get('dcd_file') == 'true') @@ -126,8 +113,8 @@ def download__email(request): response = {'email_success': 'true'} try: download__create_zip(num_of_proteins, include_pdb_file, include_dcd_file, include_animations_files, - previous_page) - send_email(email, "SimuMole_output.zip") + previous_page, user_rand) + send_email(email, "SimuMole_output.zip", user_rand) except Exception: response = {'email_success': 'false'} @@ -161,7 +148,7 @@ def clean_form_dict(self, dict_): degXY_1, degYZ_1, degXY_2, degYZ_2 = '0', '0', '0', '0' num_of_proteins = dict_.get('num_of_proteins') - + user_rand = dict_.get('user_rand') first_pdb_type = dict_.get('first_pdb_type') if first_pdb_type == 'by_id': first_pdb_id = dict_.get('first_pdb_id') @@ -187,7 +174,8 @@ def clean_form_dict(self, dict_): temperature_scale = dict_.get('temperature_scale', '') temperature = dict_.get('temperature', '') time_step_number = dict_.get('time_step_number', '') - + + clean_dict['user_rand'] = user_rand clean_dict['num_of_proteins'] = num_of_proteins clean_dict['first_pdb_type'] = first_pdb_type clean_dict['first_pdb_id'] = first_pdb_id @@ -220,7 +208,7 @@ def create_simulation_thread(self, form_dict): form_dict['degXY_1'], form_dict['degYZ_1'], form_dict['degXY_2'], form_dict['degYZ_2'], form_dict['temperature_scale'], form_dict['temperature'], - form_dict['time_step_number']) + form_dict['time_step_number'], form_dict['user_rand']) s.create_simulation() def done(self, form_list, **kwargs): @@ -238,16 +226,16 @@ def done(self, form_list, **kwargs): t.start() # Initialize the status file: - with open(os.path.join(settings.MEDIA_ROOT, 'files', 'simulation_status.txt'), "w+") as f: + with open(os.path.join(settings.MEDIA_ROOT, 'files' , form_dict['user_rand'] , 'simulation_status.txt'), "w+") as f: f.write("Processing your parameters...") - with open(os.path.join(settings.MEDIA_ROOT, 'files', 'simulation_status_during_run.txt'), "w+") as f: + with open(os.path.join(settings.MEDIA_ROOT, 'files', form_dict['user_rand'], 'simulation_status_during_run.txt'), "w+") as f: f.write("") # Render 'create_simulation_result.html' without waiting until the simulation is complete: return render(self.request, 'create_simulation_result.html', {'form_data': form_dict, 'num_of_proteins': form_dict['num_of_proteins'], 'previous_page': 'create_simulation', - 'video_path': settings.MEDIA_URL + 'videos/'}) # todo: change "video_path" + 'video_path': settings.MEDIA_URL + 'videos/' + form_dict['user_rand'] + '/', 'user_rand':form_dict['user_rand']}) def get_form_initial(self, step): """ @@ -264,8 +252,8 @@ def get_form_initial(self, step): 'first_pdb_file': step_0_prev_data.get('0-first_pdb_file'), 'second_pdb_type': step_0_prev_data.get('0-second_pdb_type'), 'second_pdb_id': step_0_prev_data.get('0-second_pdb_id'), - 'second_pdb_file': step_0_prev_data.get('0-second_pdb_file'), } - + 'second_pdb_file': step_0_prev_data.get('0-second_pdb_file'), + 'user_rand': step_0_prev_data.get('0-user_rand'),} # SimulationForm1_DetermineRelativePosition step_1_prev_data = self.storage.get_step_data('1') step_1_prev_data = {} if step_1_prev_data is None \ @@ -291,7 +279,7 @@ def show_form1(wizard: CookieWizardView): if 'num_of_proteins'==1: return FALSE, and then navigate to step 2 (simulation parameters) else, if 'num_of_proteins'==2: return TRUE, and then navigate to step 1 (determine relative position) """ - cleaned_data = wizard.get_cleaned_data_for_step('0') or {} + cleaned_data = wizard.get_form_initial('0') or {} return cleaned_data.get('num_of_proteins') == '2' @@ -315,9 +303,9 @@ def upload_files(request): f.write("") return render(request, 'create_simulation_result.html', - {'video_path': settings.MEDIA_URL + 'videos/', # todo: change "video_path" + {'video_path': settings.MEDIA_URL + 'videos/', 'previous_page': "upload_files", 'num_of_proteins': 0}) # num_of_proteins is irrelevant else: form = UploadFiles() - return render(request, 'file_upload.html', {'form': form}) \ No newline at end of file + return render(request, 'file_upload.html', {'form': form}) diff --git a/src/SimuMole/media/files/_init_folder_file.txt b/src/SimuMole/media/files/_init_folder_file.txt deleted file mode 100644 index e73b925..0000000 --- a/src/SimuMole/media/files/_init_folder_file.txt +++ /dev/null @@ -1 +0,0 @@ -This file is intended to initialize the "files" folder (git does not upload empty folders) \ No newline at end of file