Skip to content

Commit

Permalink
moved plants executable inside the repo #1
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeZ committed Aug 14, 2018
1 parent 244d9e5 commit 9778f10
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 45 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
###Git ignore file for LIEStudio repository
###Git ignore file for MDStudio repository

### LIEStudio specific
app/typings/
Expand Down Expand Up @@ -127,4 +127,3 @@ cerise_config.json
venv
.env
**/.settings.*.yml
plants_linux
6 changes: 1 addition & 5 deletions lie_plants_docking/schemas/endpoints/docking_request.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"description": "Directory to run the docking simulation",
"default": "/tmp/mdstudio/plants_docking"
},
"exec_path": {
"$ref": "resource://mdgroup/common_resources/path_file/v1"
},
"scoring_function": {
"type": "string",
"description": "",
Expand Down Expand Up @@ -296,7 +293,6 @@
"required": [
"bindingsite_center",
"ligand_file",
"protein_file",
"exec_path"
"protein_file"
]
}
9 changes: 0 additions & 9 deletions lie_plants_docking/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ def _schema_to_data(schema, data=None, defdict=None):
return default_data


def copy_exec_to_workdir(content, workdir, name='plants_linux'):
"""
Copy the executable to the workdir
"""
path = os.path.join(workdir, name)
with open(path, 'wb') as f:
f.write(content)


def prepare_work_dir(path, user=None, create=False):
"""
Prepare a docking working directory at the target path.
Expand Down
23 changes: 9 additions & 14 deletions lie_plants_docking/wamp_services.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-

from lie_plants_docking.plants_docking import PlantsDocking
from lie_plants_docking.utils import (
copy_exec_to_workdir, prepare_work_dir)
from lie_plants_docking.utils import prepare_work_dir
from mdstudio.component.session import ComponentSession
from mdstudio.api.endpoint import endpoint
import base64
import os


Expand All @@ -27,23 +25,20 @@ def run_docking(self, request, claims):
# Docking options are equal to the request
plants_config = request.copy()

# Transfer the files content
plants_config['protein_file'] = request['protein_file']['content']
plants_config['ligand_file'] = request['ligand_file']['content']

# Prepare docking directory
workdir = os.path.abspath(request['workdir'])
plants_config["workdir"] = prepare_work_dir(
workdir, create=True)

exec_path = request['exec_path']
encoding = exec_path['encoding'].lower()
# location of the executable
file_path = os.path.realpath(__file__)
root = os.path.split(file_path)[0]

# The binaries are first encode to base64 then decode to ascii
# To get the original binary the inverse operation is applied
if 'bytes' == encoding:
content = exec_path['content']
binary = base64.b64decode(content.encode())
copy_exec_to_workdir(binary, workdir)
else:
msg = "expecting binary exec_path but the encoding is: {}".format(encoding)
raise RuntimeError(msg)
plants_config['exec_path'] = os.path.join(root, 'plants_linux')

# Run d ocking
docking = PlantsDocking(**plants_config)
Expand Down
31 changes: 16 additions & 15 deletions tests/wamp_test/test_lie_plants_docking.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
from mdstudio.deferred.chainable import chainable
from mdstudio.component.session import ComponentSession
from mdstudio.runner import main
import base64
import os
import json

file_path = os.path.realpath(__file__)
root = os.path.split(file_path)[0]

def create_path_file_obj(path, encoding='utf8'):

def create_path_file_obj(path):
"""
Encode the input files
"""
extension = os.path.splitext(path)[1]
mode = 'rb' if encoding == 'bytes' else 'r'
with open(path, mode) as f:
with open(path, 'r') as f:
content = f.read()
if encoding == 'bytes':
content = base64.b64encode(content).decode('ascii')

return {
'path': path, 'encoding': encoding,
'content': content, 'extension': extension}
'path': path, 'content': content,
'extension': extension}


workdir = "/tmp/lie_plants_docking"
workdir = "/tmp"
cwd = os.getcwd()
os.makedirs(workdir, exist_ok=True)

protein_file = create_path_file_obj(
os.path.join(cwd, "DT_conf_1.mol2"))
os.path.join(root, "DT_conf_1.mol2"))
ligand_file = create_path_file_obj(
os.path.join(cwd, "ligand.mol2"))
exec_path = create_path_file_obj(
os.path.join(cwd, "plants_linux"), encoding='bytes')
os.path.join(root, "ligand.mol2"))


class Run_docking(ComponentSession):
Expand All @@ -49,8 +47,11 @@ def on_run(self):
"bindingsite_radius": 12.0,
"bindingsite_center": [
4.926394772324452, 19.079624537618873, 21.98915631296689],
"workdir": workdir,
"exec_path": exec_path})
"workdir": workdir})

with open("output.json", 'w') as f:
json.dump(result, f)

assert result['status'] == 'completed'


Expand Down

0 comments on commit 9778f10

Please sign in to comment.