Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
Refactor settings structure, build upload_to_gromppery.py
Browse files Browse the repository at this point in the history
  • Loading branch information
justinrporter committed Aug 25, 2017
1 parent 0a9b9f9 commit 7b01948
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 52 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# The Gromppery
Its thirst for simulations cannot be slaked.

## Configuration

In gromppery/gromppery/local.py, you can set important local configuration options. An example is provided.

## Basic Use

The provided client/gromppery_client.py is a script that can request work from the gromppery, run it, and return it.

It is invoked like:

```bash
$ python ~/projects/gromppery/client/gromppery_client.py \
--gromppery http://localhost:43443/api \
--scratch ~/sim/ \
--protein lambda-repressor \
--iterations 2
```

This command will connect to a gromppery running at `localhost:43443`, download a work unit from the project called `lambda-repressor`, run it in a directory like `~/sim/YEAR-MONTH-DAY-HASH`, and return it. Because the `--iterations` flag is 2, it will then repeat this process again. If `--iterations` is not specified, it will run until terminated.
21 changes: 19 additions & 2 deletions client/gromppery_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,31 @@ def simulate(tpr_fname, nt=None):
return files


def submit_work(gromppery, tag, files):
def submit_work(gromppery, tag, files, hostname=None):
"""Submit a (presumably finished) simulation to the gromppery.
Parameters
----------
gromppery: str
URL where the gromppery is found. Usually of the form
[IPADDR]:[PORT] or http(s)://[DOMAIN]:[PORT].
tag: str
Name of the project to which the work unit should be submitted.
hostname: str, default=None
Name of this host under which to submit the finished simulation.
If none, hostname will automatically be determined by
platform.node().
files: dict
Dictionary of paths to files that will be uploaded. Requires
keys: ['xtc', 'cpt', 'gro', 'log', 'edr', 'tpr'].
"""

url = '/'.join([gromppery, 'tprs', tag, 'submit/'])
print(url)

r = requests.post(
url,
data={'hostname': platform.node()},
data={'hostname': platform.node() if hostname is None else hostname},
files={t: open(files[t], 'rb') for t
in ['xtc', 'cpt', 'gro', 'log', 'edr', 'tpr']})

Expand Down
53 changes: 53 additions & 0 deletions client/upload_to_gromppery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import sys
import argparse

from .gromppery_client import submit_work


def process_command_line(argv):
'''Parse the command line and do a first-pass on processing them into a
format appropriate for the rest of the script.'''

parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Upload a bundle of files to the gromppery as a '
'Submission (usually a finished simulation).')

for ftype in ['xtc', 'cpt', 'gro', 'log', 'edr', 'tpr']:
parser.add_argument(
"--%s" % ftype, required=True,
help="The GROMACS %s file to upload to the gromppery." % ftype)

parser.add_argument(
"--gromppery", required=True,
help="The URL and port where the gromppery can be found.")
parser.add_argument(
"--protein", required=True,
help="Always choose this protein from the gromppery.")
parser.add_argument(
"--hostname", default=None,
help="Override the current hostname when indicating the host "
"that ran the simulation.")

args = parser.parse_args(argv[1:])

return args


def main(argv=None):
'''Run the driver script for this module. This code only runs if we're
being run as a script. Otherwise, it's silent and just exposes methods.'''
args = process_command_line(argv)

submit_work(
gromppery=args.gromppery,
tag=args.protein,
files={[getattr(args, ftype) for ftype in
['xtc', 'cpt', 'gro', 'log', 'edr', 'tpr']]}
)


return 0

if __name__ == "__main__":
sys.exit(main(sys.argv))
54 changes: 6 additions & 48 deletions gromppery/settings.py → gromppery/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,6 @@
https://docs.djangoproject.com/en/1.10/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRETS_DIR = os.path.join(BASE_DIR, 'secrets')

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
with open(os.path.join(SECRETS_DIR, 'django_key.txt'), 'r') as f:
SECRET_KEY = f.read().rstrip()

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
Expand Down Expand Up @@ -73,17 +54,6 @@
WSGI_APPLICATION = 'gromppery.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators

Expand All @@ -102,6 +72,12 @@
},
]

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
],
'PAGE_SIZE': 10
}

# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
Expand All @@ -115,21 +91,3 @@
USE_L10N = True

USE_TZ = True

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
],
'PAGE_SIZE': 10
}

GROMACS_TIMEOUT = 10 # seconds

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
46 changes: 46 additions & 0 deletions gromppery/dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from __future__ import absolute_import, unicode_literals
import os

from .base import *

ALLOWED_HOSTS = []

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRETS_DIR = os.path.join(BASE_DIR, 'secrets')

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
with open(os.path.join(SECRETS_DIR, 'django_key.txt'), 'r') as f:
SECRET_KEY = f.read().rstrip()

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


try:
from .local import *
except ImportError:
pass
2 changes: 2 additions & 0 deletions gromppery/local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GROMACS_TIMEOUT = 10
FILE_UPLOAD_MAX_MEMORY_SIZE = 1024 * 1024 * 64
2 changes: 1 addition & 1 deletion gromppery/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gromppery.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gromppery.dev")

application = get_wsgi_application()
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gromppery.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gromppery.dev")
try:
from django.core.management import execute_from_command_line
except ImportError:
Expand Down

0 comments on commit 7b01948

Please sign in to comment.