Skip to content

Commit

Permalink
Merge pull request #95 from talagayev/OpenMMDL_Setup_Simulation_restr…
Browse files Browse the repository at this point in the history
…ucture

Restructure of OpenMMDL Setup
  • Loading branch information
talagayev authored Aug 13, 2024
2 parents 4eaeb21 + 5a39d8e commit b8ad678
Show file tree
Hide file tree
Showing 11 changed files with 2,555 additions and 2,475 deletions.
649 changes: 649 additions & 0 deletions openmmdl/openmmdl_setup/amberscript_creator.py

Large diffs are not rendered by default.

558 changes: 558 additions & 0 deletions openmmdl/openmmdl_setup/configfile_creator.py

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions openmmdl/openmmdl_setup/file_operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import tempfile
import shutil
from werkzeug.utils import secure_filename


class LigandExtractor:
@staticmethod
def extract_ligand_name(lig_file_name):
"""
Extracts the ligand name from the file name based on its extension.
This method determines the ligand name by stripping the file extension from the provided ligand
file name. It handles files with `.pdb` extensions by removing the extension, while it assigns a
default name `"UNL"` to files with `.sdf` extensions.
Params:
-------
lig_file_name: str
The name of the ligand file, including its extension (e.g., `ligand.pdb` or `ligand.sdf`).
Returns:
--------
lig_name: str
The extracted ligand name. For `.pdb` files, this is the file name without the `.pdb` extension.
For `.sdf` files, it returns a default name `"UNL"`.
"""
if lig_file_name.endswith(".sdf"):
lig_name = "UNL"
elif lig_file_name.endswith(".pdb"):
lig_name = lig_file_name[:-4]
else:
raise ValueError(
"Unsupported file format. Only .sdf and .pdb are supported."
)

return lig_name


class FileUploader:
"""
Handles uploading and temporary storage of files.
"""

@staticmethod
def save_uploaded_files(uploadedFiles, request):
"""
Saves files from the request into temporary storage and updates the given dictionary.
Parameters
----------
uploadedFiles : dict
Dictionary to store uploaded files. Keys are field names; values are lists of (temp file, filename) tuples.
request : object
The request object containing uploaded files.
Returns
-------
None
"""
uploadedFiles.clear()
for key in request.files:
filelist = []
for file in request.files.getlist(key):
temp = tempfile.TemporaryFile()
shutil.copyfileobj(file, temp)
filelist.append((temp, secure_filename(file.filename)))
uploadedFiles[key] = filelist
Loading

0 comments on commit b8ad678

Please sign in to comment.