diff --git a/.gitignore b/.gitignore index 8fef5f38..b26dd80b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,9 @@ transfer_logs/* logs/* test_xchem/test_xchem/settings.py db/migrations/* +# Warren added - to get instance on Diamond in sync with Git repo +luigi.log +*.cif +mArh.json +bkup/* +#.nfs00000000a33355f40000008a diff --git a/luigi.cfg b/luigi.cfg deleted file mode 100644 index 8b56fe72..00000000 --- a/luigi.cfg +++ /dev/null @@ -1,31 +0,0 @@ -[VerneConfig] -username='' -hostname='' -remote_root='' -target_list=target_list.txt -update_user='' -update_token='' -rand_string='' -open_target_list=sgc_targets.txt - -[SentryConfig] -key='' -ident='' - -#[email] -#iforce-send=True -#format=html -#prefix=[LUIGI-PIPELINE] -#receiver=rachael.skyner@diamond.ac.uk - -[SoakDBConfig] -default_path=/pipeline/tests/data/ - -[DirectoriesConfig] -hit_directory='' -staging_directory='' -log_directory=/pipeline/logs -input_directory='' - -[resources] -django=1 diff --git a/make_investigation.py b/make_investigation.py new file mode 100755 index 00000000..68fa7e77 --- /dev/null +++ b/make_investigation.py @@ -0,0 +1,286 @@ +from rdkit.Chem.rdMolDescriptors import CalcMolFormula +from rdkit import Chem +from setup_django import setup_django +setup_django() +# This line gets moved... move it back... +from xchem_db.xchem_db.models import * +import argparse +import os + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("-t", "--target", help = "Target name e.g. Mpro", required=True) + parser.add_argument("-x", "--exclude", default='', help = "Proposals to Exclude, seperated by commas") + parser.add_argument("-o", "--output", help = "Output File", required=True) + + args = vars(parser.parse_args()) + + + skeleton = { + "_pdbx_investigation": { + "id": args["target"], + "type": "Fragment screening", + "db": "fragalysis", + "project": args["target"], + "url": f'https://fragalysis.diamond.ac.uk/viewer/react/preview/target/{args["target"]}', + "details": "Fragment screening project" + }, + "_pdbx_investigation_frag_screening": { + "investigation_id": args["target"], + "campaign_id": '1', + "target": args["target"], + "common_unp": "FILLME", + "facility": "DLS", + "proc_pipeline": "XChem", + "internal_id": "FILLME" + }, + "_pdbx_investigation_series": { + "frag_screening_campaign_id": [1, 1], + "id": [1, 2], + "fragment_lib": ["FILLME", 'FILLME'], + "fragment_batch": ["v1.0", "v1.0"], + "description": ["Placeholder Description", "Placeholder Description"] + }, + "_pdbx_investigation_exp": { + "series_id": [], + "exp_id": [], + "exp_acc": [], + "exp_poly": [], + "exp_non_poly": [], + "exp_method": [], + "db": [], + "db_ac": [], + "exp_details": [], + "exp_url": [] + }, + "_pdbx_investigation_frag_screening_exp": { + "id": [], + "exp_id": [], + "instance_id": [], + "exp_fragment": [], + "bound_fragments": [], + "hit": [], + "hit_assessment": [], + "exp_details": [] + }, + "_pdbi_entity_poly_link": { + "id": [1], + "entity_id": [1] + }, + "_pdbi_entity_nonpoly_link": { + "id": [], + "entity_id": [] + }, + "_pdbi_entity_poly": { + "entity_id": "1", + "type": "polypeptide(L)", + "src_method": "man", + "pdbx_seq_one_letter_code": "?", + "db_name": "?", + "db_code": "?", + "pdbx_db_accession": "?" + }, + "_pdbi_entity_nonpoly": { + "entity_id": [], + "name": [], + "src_method": [], + "comp_id": [], + "formula": [], + "formula_weight": [], + "inchi_descriptor": [] + }, + "_pdbi_entity_frag_library": { + "entity_id": [], + "parent_id": [], + "series_id": [], + "name": [], + "details": [], + "src_method": [], + "comp_id": [], + "formula": [], + "formula_weight": [], + "inchi_descriptor": [] + }, + "_pdbx_contact_author": { + "id": [], + "address_1": [], + "address_2": [], + "address_3": [], + "legacy_address": [], + "city": [], + "state_province": [], + "postal_code": [], + "email": [], + "fax": [], + "name_first": [], + "name_last": [], + "name_mi": [], + "name_salutation": [], + "country": [], + "continent": [], + "phone": [], + "role": [], + "organization_type": [], + "identifier_ORCID": [] + }, + "_audit_author": { + "pdbx_ordinal": [], + "address": [], + "name": [], + "identifier_ORCID": [] + }, + "_pdbx_audit_support": { + "ordinal": [], + "funding_organization": [], + "country": [], + "grant_number": [], + "details": [] + }, + "_pdbx_database_status": { + "entry_id": "FILLME", + "status_code": "FILLME", + "dep_release_code": "FILLME", + "author_release_status_code": "FILLME", + "recvd_initial_deposition_date": "FILLME", + "date_accepted_terms_and_conditions": "FILLME" + } + } + + exclude_list = args["exclude"].split(',') + print(args["target"]) + crystal_set2 = Refinement.objects.filter( + crystal_name__crystal_name__contains=args["target"]) + if exclude_list == '': + crystal_set = crystal_set2 + else : + crystal_set = [x for x in crystal_set2 if x.crystal_name.visit.proposal.proposal not in exclude_list] + + print(f"Processing {len(crystal_set)} Structures") + + outcomes = {1: 'Collecting', 2: 'Preprocessing', 3: 'Refinement', + 4: 'Review', 5: 'Accepted', 6: 'Accepted', 7: 'Rejected'} + + for crystal in crystal_set: + print(crystal.crystal_name.crystal_name) + if crystal.bound_conf: + strfil = crystal.bound_conf + elif crystal.pdb_latest: + strfil = crystal.pdb_latest + else: + strfil = None + if strfil: + if not os.path.exists(strfil): + continue + if strfil: + hets = {} + resids = [] + with open(strfil, 'r') as pdb: + for line in pdb: + if line.startswith('HETATM'): + resids.append(line[17:20].replace(' ', '')) + for non_poly in [x for x in set(resids) if 'LIG' not in x]: + block = [] + oldresnum, resnum = None, None + with open(strfil, 'r') as pdb: + for line in pdb: + if line.startswith('HETATM'): + if non_poly in line: + resnum = line[22:26].replace(' ', '') + if oldresnum: + if not oldresnum == resnum: + continue + block.append(line) + oldresnum = resnum + hets[non_poly] = Chem.MolFromPDBBlock(''.join(block)) + smile_mol = [ + Chem.MolFromSmiles(x.compound.smiles) for x in crystal.crystal_name.crystalcompoundpairs_set.all()] + code = [ + x.compound.compound_string for x in crystal.crystal_name.crystalcompoundpairs_set.all()] + smile_mol += list(hets.values()) + code_only_ligs = code + code += list(hets.keys()) + if len(skeleton["_pdbx_investigation_exp"]["exp_id"]) < 1: + exp_id = 1 + else: + exp_id = max(skeleton["_pdbx_investigation_exp"]["exp_id"])+1 + entity_ids_used = [] + for mol, cod in zip(smile_mol, code): + if mol is None: + continue + formula = CalcMolFormula(mol) + inchi = Chem.inchi.MolToInchi(mol) + wt = Chem.rdMolDescriptors.CalcExactMolWt(mol) + if cod not in skeleton["_pdbi_entity_nonpoly"]["name"]: + entity_id = len(skeleton["_pdbi_entity_nonpoly"]["entity_id"])+1 + comp_id = len(skeleton["_pdbi_entity_nonpoly"]["comp_id"])+1 + skeleton["_pdbi_entity_nonpoly"]["entity_id"].append(entity_id) + skeleton["_pdbi_entity_nonpoly"]["name"].append(cod) + skeleton["_pdbi_entity_nonpoly"]["src_method"].append('syn') + skeleton["_pdbi_entity_nonpoly"]["comp_id"].append(comp_id) + skeleton["_pdbi_entity_nonpoly"]["formula"].append(formula) + skeleton["_pdbi_entity_nonpoly"]["formula_weight"].append(wt) + skeleton["_pdbi_entity_nonpoly"]["inchi_descriptor"].append(inchi) + entity_ids_used.append(entity_id) + else: + entity_ids_used.append( + skeleton["_pdbi_entity_nonpoly"]["entity_id"][skeleton["_pdbi_entity_nonpoly"]["name"].index(cod)]) + for eid in set(entity_ids_used): + skeleton["_pdbi_entity_nonpoly_link"]["id"].append(exp_id) + skeleton["_pdbi_entity_nonpoly_link"]["entity_id"].append(eid) + details = outcomes.get(crystal.outcome) + if details == 'Review': + r = ReviewResponses.objects.filter(crystal=crystal.crystal_name) + if len(r) > 0: + details = r[0].reason + else: + details = 'Refined but Not Reviewed' + for ex in code_only_ligs: + try: + lig_entity = skeleton["_pdbi_entity_nonpoly"]["entity_id"][skeleton["_pdbi_entity_nonpoly"]["name"].index(ex)] + except ValueError: + print(f"Skipping {ex}") + continue + skeleton["_pdbx_investigation_exp"]["series_id"].append("1") + skeleton["_pdbx_investigation_exp"]["exp_id"].append(exp_id) + skeleton["_pdbx_investigation_exp"]["exp_acc"].append( + crystal.crystal_name.crystal_name) # Use names for the moment lol + skeleton["_pdbx_investigation_exp"]["exp_poly"].append(1) + skeleton["_pdbx_investigation_exp"]["exp_non_poly"].append(lig_entity) + skeleton["_pdbx_investigation_exp"]["exp_method"].append("X-ray") + skeleton["_pdbx_investigation_exp"]["db"].append("PDB") + skeleton["_pdbx_investigation_exp"]["db_ac"].append('XXXX') + skeleton["_pdbx_investigation_exp"]["exp_details"].append(details) + skeleton["_pdbx_investigation_exp"]["exp_url"].append(f'https://fragalysis.diamond.ac.uk/viewer/react/preview/direct/target/{args["target"]}/mols/{ex}/L/P/C') + # skeleton["_pdbx_investigation_exp"]["state"].append("?") + + cif_file = [f'{args["target"]}\n', "#\n"] + for k, v in skeleton.items(): + loop = False + lens = [] + for keys, values in v.items(): + if isinstance(values, int) or isinstance(values, str): + pass + else: + lens.append(len(values)) + if len(lens) > 0: + loop = True + if not loop: + for keys, values in v.items(): + if isinstance(values, str): + cif_file.append(f'{k}.{keys} "{values}"\n') + else: + cif_file.append(f'{k}.{keys} {values}\n') + else: + cif_file.append('loop_\n') + loop_data = [] + for keys, values in v.items(): + loop_data.append(values) + cif_file.append(f'{k}.{keys}\n') + for tup in zip(*loop_data): + conv = [f'{x}' if not isinstance( + x, str) else f'"{x}"' for x in tup] + cif_file.append(' '.join(conv)+'\n') + cif_file.append("#\n") + + with open(args["output"], 'w') as f: + f.write(''.join(cif_file)) diff --git a/single_soakdb.py b/single_soakdb.py index 88bfd416..f7a6a761 100644 --- a/single_soakdb.py +++ b/single_soakdb.py @@ -7,7 +7,7 @@ from functions import db_functions from functions import misc_functions from functions.pandda_functions import * -from xchem_db.models import * +from xchem_db.xchem_db.models import * from utils.refinement import RefinementObjectFiles from dateutil.parser import parse @@ -211,30 +211,30 @@ def create_links(filename, link_dir): required=True, ) - parser.add_argument( - "-o", - "--output_directory", - default='', - help="Output directory where bound-state pdb files will be", - required=True, - ) + #parser.add_argument( + # "-o", + # "--output_directory", + # default='', + # help="Output directory where bound-state pdb files will be", + # required=True, + #) args = vars(parser.parse_args()) filename = args["soakdb_file"] - link_dir = args["output_directory"] + link_dir = '' print('Will process: ' + filename) print('symlinks to the bound-state pdbs will be found in: ' + link_dir) print('Checking wether ' + filename + ' is a new or existing entry in XCDB...') - status = check_file(filename) + status = 0 #check_file(filename) print(status) if status==0 or status==1: print('Transferring the data from the soakDB file into XCDB (this may take a while!)...') run_transfer(filename) print('Creating the symbolic links to the bound-state pdb files...') - create_links(filename, link_dir) + #create_links(filename, link_dir) print('Telling the database this file is now up-to-date...') sdb = SoakdbFiles.objects.get(filename=filename) sdb.status = 2 diff --git a/xchem_db/.github/workflows/auto-commits.yml b/xchem_db/.github/workflows/auto-commits.yml new file mode 100644 index 00000000..7f698f73 --- /dev/null +++ b/xchem_db/.github/workflows/auto-commits.yml @@ -0,0 +1,72 @@ +# This is a basic workflow to help you get started with Actions + +name: CI - Setup environment, build & add autogenerated files (migrations, SQL & schema image) + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + build: + runs-on: ubuntu-latest + services: + mysql: + image: mariadb:10.4 + env: + MYSQL_ROOT_PASSWORD: docker-root + MYSQL_DATABASE: docker + MYSQL_USER: docker + MYSQL_PASSWORD: docker + MYSQL_HOST: db + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10 + strategy: + matrix: + python-version: [3.6] + steps: + - name: Step 1 - Setup environment (apt-get) + run: | + sudo apt-get update + sudo apt-get install -y libpq-dev graphviz libgraphviz-dev + sudo apt-get install -y default-libmysqlclient-dev build-essential + sudo apt-get remove -y default-libmysqlclient-dev build-essential + - name : Step 2 - Checkout code + uses: actions/checkout@v2 + - name: Step 3 - Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Step 4 - Install Dependencies (requirements.txt) + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Step 5 - Install dependencies (setup.py) + run: pip install -e . + - name: Step 6 - Apply existing migrations + run: python manage.py migrate + - name: Step 7 - Create new migrations + run: python manage.py makemigrations xchem_db + - name: Step 8 - Apply new migrations + run: python manage.py migrate xchem_db + - name: Step 9 - Create new schema image + run: python manage.py graph_models -a -o schema.png + - name: Step 10 - Generate SQL for ISPyB + run: python run_sql_gen.py + - name: Step 11 - Append new SQL to master file + run: python compile_init.py + - name: Step 12 - Commit changed files + if: $${{ matrix.python-version }} == 3.6 + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Auto-commit of new versions of migrations, SQL files & schema image + # push_options: --force + file_pattern: '*.png *.sql sql/*.sql */migrations/*' diff --git a/xchem_db/.github/workflows/ispyb-push.yml b/xchem_db/.github/workflows/ispyb-push.yml new file mode 100644 index 00000000..f6fb5213 --- /dev/null +++ b/xchem_db/.github/workflows/ispyb-push.yml @@ -0,0 +1,35 @@ +name: Commit files to ISPyB repo +env: + API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +on: + release: + types: [released] + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: +jobs: + push_ispyb: + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v2 + - name: add files to ispyb (xchem-updates) + env: + API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} + run: | + git config --global user.email "reskyner@googlemail.com" + git config --global user.name "Rachael Skyner" + git config --global pull.ff only + git clone https://$API_TOKEN_GITHUB@github.com/DiamondLightSource/ispyb-database + cd ispyb-database + git checkout -b xchem-updates + git pull origin xchem-updates + mkdir -p schemas/xchem_db + mkdir -p schemas/xchem_db/updates + cp ../init.sql schemas/xchem_db + cp ../sql/*.sql schemas/xchem_db/updates + git add schemas/xchem_db/* + git add schemas/xchem_db/updates/* + git commit -a -m 'Auto-commit for updates to XChemDB schema' + git push origin xchem-updates diff --git a/xchem_db/.github/workflows/python-publish.yml b/xchem_db/.github/workflows/python-publish.yml new file mode 100644 index 00000000..2d8c73dc --- /dev/null +++ b/xchem_db/.github/workflows/python-publish.yml @@ -0,0 +1,29 @@ +name: Release to PyPI + +on: + release: + types: [released] + +jobs: + release: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.6 + uses: actions/setup-python@v2 + with: + python-version: 3.6 + - name: Install Tools + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Package and Upload + env: + STACKMANAGER_VERSION: ${{ github.event.release.tag_name }} + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* diff --git a/xchem_db/.gitignore b/xchem_db/.gitignore new file mode 100644 index 00000000..37869ca8 --- /dev/null +++ b/xchem_db/.gitignore @@ -0,0 +1,3 @@ +__pychache__ +.idea/* +*.pyc diff --git a/xchem_db/Dockerfile b/xchem_db/Dockerfile new file mode 100644 index 00000000..e2c07f25 --- /dev/null +++ b/xchem_db/Dockerfile @@ -0,0 +1,18 @@ +# base image +FROM python:3.6-slim + +# environment for python logging +# send output to terminal without buffer +ENV PYTHONBUFFERED 1 + +RUN mkdir /xcdb +WORKDIR /xcdb +ADD . /xcdb +RUN chmod -R 777 /xcdb + +# install needed packages +RUN apt-get update \ + && apt-get install -y python-psycopg2 graphviz libgraphviz-dev \ + && apt-get install -y default-libmysqlclient-dev build-essential \ + && pip install --trusted-host pypi.python.org -r requirements.txt \ + && apt-get remove -y default-libmysqlclient-dev build-essential diff --git a/xchem_db/README.md b/xchem_db/README.md new file mode 100644 index 00000000..3a5533b0 --- /dev/null +++ b/xchem_db/README.md @@ -0,0 +1,100 @@ +![CI - Setup environment, build & add autogenerated files (migrations, SQL & schema image)](https://github.com/xchem/xchem_db/workflows/CI%20-%20Setup%20environment,%20build%20&%20add%20autogenerated%20files%20(migrations,%20SQL%20&%20schema%20image)/badge.svg) +![Release to PyPI](https://github.com/xchem/xchem_db/workflows/Release%20to%20PyPI/badge.svg) + + +# xchem_db +This repository contains the django models used to generate the XCDB schema. + +## To do: +- ~~automate migration on push to main~~ +- ~~automate sql on push to main~~ +- ~~automate commit to xchem branch on ispyb for sql~~ +- automate PR to xchem branch on ispyb for sql + +## Getting started +This repository contains everything you should need to develop new models for XChemDB. + +You can develop locally by making use of the containerisation handled in the ``docker-compose`` files here. There are +two files: (a)``docker-compose.yml`` and (b)``docker-compose.dev.yml``. + +File (a) will create a version of all of the code within the container, which will not dynamically change as the +directory changes on your local machine. This file is most useful for automated builds. File (b) will mount the local +copy of the repository directly into the container, and so is best for development in real-time (locally). This is +achieved by the inclusion of a volume mount: + +```yaml +volumes: + - .:/xcdb +``` + +The docker-compose action will set up two containers that interact with each other. The first container pulls an official +mariaDB image from dockerhub and runs it under the name ``db``. The second ``xcdb`` container depends on the ``db`` +container, and contains all of the django code needed to setup the database, and make changes to it. + +To build the containers from ``docker-compose.yml``: + +```bash +docker-compose up +``` + +To build the containers from ``docker-compose.dev.yml``: + +```bash +docker-compose -f docker-compose.dev.yml up +``` + +If the build was successful, you should see the django landing page at ``http://localhost:8000``. + +During the setup of the ``db`` container, the ``init.sql`` file is used to pre-populate the database with the tables +that are expected to exist already (based on the migrations in xchem_db). This is acheived by the following lines in +the docker-compose file: + +```yaml +command: ['--character-set-server=utf8', '--collation-server=utf8_general_ci', '--init-file=/data/application/init.sql'] + volumes: + - .init.sql:/data/application/init.sql +``` + +After the ``db`` (database) container has been set up and run, the ``xcdb`` (django) container does the following: +1. Check to see if there are any new models that need to be added to the database and makes the appropriate django +migration files +2. Applies the migrations to the database (adding/changing tables) +3. Creates a new schema image +4. generates a file under sql containing the sql statements needed to create new tables (mimic of migrations files) +5. Updates the ``init.sql`` file for next time the server is run + +This is controlled by: + +```yaml +command: > + /bin/bash -c "python3.6 manage.py makemigrations && + python3.6 manage.py migrate && + python3.6 manage.py makemigrations xchem_db && + python3.6 manage.py migrate xchem_db && + python3.6 manage.py graph_models -a -o schema.png && + python3.6 run_sql_gen.py && + python3.6 compile_init.py && + python3.6 manage.py runserver 0.0.0.0:8000" +``` + +### Useful commands +- To stop the containers, use ``ctrl+C`` +- To remove the images use ``docker-compose rm`` +- To rebuild the web image use ``docker-compose build .`` +- To specify which docker-compose file to use in any command use the ``-f`` flag +- To get into the container use ``docker run -it xcdb /bin/bash`` +- To run a command in the web container ``docker-compose run web `` + + +## Instructions for deploying changes +**UNDER CONSTRUCTION - DEPENDS ON TO DO** + +The docker-compose file can be used to create the necessary files to update the database. The files needed by Diamond +are found in the ``sql/`` directory. + +Once you have updated the models in ``xchem_db/models.py``, you can generate the necessary files by running +``docker-compose up`` from within the local version of your repository. + +This will ensure that your new models can be added to the database by running the necessary django code. + + diff --git a/xchem_db/apps.py b/xchem_db/apps.py deleted file mode 100644 index 8669eee9..00000000 --- a/xchem_db/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class DbConfig(AppConfig): - name = 'xchem_db' diff --git a/xchem_db/compile_init.py b/xchem_db/compile_init.py new file mode 100644 index 00000000..d1681d09 --- /dev/null +++ b/xchem_db/compile_init.py @@ -0,0 +1,14 @@ +import glob +import os + +str_out = '' +for f in glob.glob('./sql/*.sql'): + to_add = open(f, 'r').read() + str_out += to_add + +with open('init.sql', 'w+') as w: + w.write(str_out) + +if not os.path.isfile('init.sql'): + raise Exception('init.sql file not generated - this needs to exist to create XCDB!') + diff --git a/xchem_db/docker-compose.dev.yml b/xchem_db/docker-compose.dev.yml new file mode 100644 index 00000000..85d9b728 --- /dev/null +++ b/xchem_db/docker-compose.dev.yml @@ -0,0 +1,34 @@ +services: + db: + image: mariadb:10.4 + restart: always + container_name: db + command: ['--character-set-server=utf8', '--collation-server=utf8_general_ci', '--init-file=/data/application/init.sql'] + volumes: + - .init.sql:/data/application/init.sql + environment: + MYSQL_DATABASE: "docker" + MYSQL_USER: "docker" + MYSQL_PASSWORD: "docker" + MYSQL_ROOT_PASSWORD: "docker-root" + MYSQL_ROOT_HOST: "%" + + web: + depends_on: + - db + build: . + volumes: + - .:/xcdb + command: > + /bin/bash -c "python3.6 manage.py makemigrations && + python3.6 manage.py migrate && + python3.6 manage.py makemigrations xchem_db && + python3.6 manage.py migrate xchem_db && + python3.6 manage.py graph_models -a -o schema.png && + python3.6 run_sql_gen.py && + python3.6 compile_init.py && + python3.6 manage.py runserver 0.0.0.0:8000" + container_name: xcdb + restart: always + ports: + - "8000:8000" diff --git a/xchem_db/docker-compose.yml b/xchem_db/docker-compose.yml new file mode 100644 index 00000000..43f3f25b --- /dev/null +++ b/xchem_db/docker-compose.yml @@ -0,0 +1,32 @@ +services: + db: + image: mariadb + restart: always + container_name: db + command: ['--character-set-server=utf8', '--collation-server=utf8_general_ci', '--init-file=/data/application/init.sql'] + volumes: + - .init.sql:/data/application/init.sql + environment: + MYSQL_DATABASE: "docker" + MYSQL_USER: "docker" + MYSQL_PASSWORD: "docker" + MYSQL_ROOT_PASSWORD: "docker-root" + MYSQL_ROOT_HOST: "%" + + web: + depends_on: + - db + build: . + command: > + /bin/bash -c "python3.6 manage.py makemigrations && + python3.6 manage.py migrate && + python3.6 manage.py makemigrations xchem_db && + python3.6 manage.py migrate xchem_db && + python3.6 manage.py graph_models -a -o schema.png && + python3.6 run_sql_gen.py && + python3.6 compile_init.py && + python3.6 manage.py runserver 0.0.0.0:8000" + container_name: xcdb + restart: always + ports: + - "8000:8000" \ No newline at end of file diff --git a/xchem_db/init.sql b/xchem_db/init.sql new file mode 100644 index 00000000..b4092df6 --- /dev/null +++ b/xchem_db/init.sql @@ -0,0 +1,183 @@ +-- +-- Add field comment to reviewresponses +-- +ALTER TABLE `review_responses` ADD COLUMN `comment` longtext NULL; +-- +-- Create model Compounds +-- +CREATE TABLE `compound` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `smiles` varchar(255) NULL, `compound_string` varchar(255) NULL); +-- +-- Create model Crystal +-- +CREATE TABLE `crystal` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `crystal_name` varchar(255) NOT NULL, `status` varchar(2) NOT NULL, `well` varchar(4) NULL, `echo_x` integer NULL, `echo_y` integer NULL, `score` integer NULL); +-- +-- Create model DataProcessing +-- +CREATE TABLE `data_processing` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `auto_assigned` longtext NULL, `cchalf_high` double precision NULL, `cchalf_low` double precision NULL, `cchalf_overall` double precision NULL, `completeness_high` double precision NULL, `completeness_low` double precision NULL, `completeness_overall` double precision NULL, `dimple_mtz_path` longtext NULL, `dimple_pdb_path` longtext NULL, `dimple_status` longtext NULL, `image_path` longtext NULL, `isig_high` double precision NULL, `isig_low` double precision NULL, `isig_overall` double precision NULL, `lattice` longtext NULL, `log_name` longtext NULL, `logfile_path` longtext NULL, `mtz_name` longtext NULL, `mtz_path` longtext NULL, `multiplicity_high` double precision NULL, `multiplicity_low` double precision NULL, `multiplicity_overall` double precision NULL, `original_directory` longtext NULL, `point_group` longtext NULL, `program` longtext NULL, `r_cryst` double precision NULL, `r_free` double precision NULL, `r_merge_high` double precision NULL, `r_merge_low` double precision NULL, `r_merge_overall` double precision NULL, `res_high` double precision NULL, `res_high_15_sigma` double precision NULL, `res_high_outer_shell` double precision NULL, `res_low` double precision NULL, `res_low_inner_shell` double precision NULL, `res_overall` longtext NULL, `score` double precision NULL, `spacegroup` longtext NULL, `status` longtext NULL, `unique_ref_overall` integer NULL, `unit_cell` longtext NULL, `unit_cell_vol` double precision NULL, `crystal_name_id` integer NOT NULL UNIQUE); +-- +-- Create model FragalysisLigand +-- +CREATE TABLE `fragalysis_ligand` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `ligand_name` varchar(255) NOT NULL, `crystallographic_bound` varchar(500) NOT NULL, `lig_mol_file` varchar(500) NOT NULL, `apo_pdb` varchar(500) NOT NULL, `bound_pdb` varchar(500) NOT NULL, `smiles_file` varchar(500) NOT NULL, `desolvated_pdb` varchar(500) NOT NULL, `solvated_pdb` varchar(500) NOT NULL, `pandda_event` varchar(500) NOT NULL, `two_fofc` varchar(500) NOT NULL, `fofc` varchar(500) NOT NULL, `modification_date` bigint NOT NULL); +-- +-- Create model Ligand +-- +CREATE TABLE `ligand` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `crystal_id` integer NOT NULL, `fragalysis_ligand_id` integer NOT NULL); +-- +-- Create model MiscFiles +-- +CREATE TABLE `misc_files` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `file` varchar(500) NOT NULL, `description` longtext NOT NULL); +-- +-- Create model PanddaAnalysis +-- +CREATE TABLE `pandda_analysis` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `pandda_dir` varchar(255) NOT NULL UNIQUE); +-- +-- Create model PanddaEvent +-- +CREATE TABLE `pandda_event` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `event` integer NULL, `event_centroid_x` double precision NULL, `event_centroid_y` double precision NULL, `event_centroid_z` double precision NULL, `event_dist_from_site_centroid` longtext NULL, `lig_centroid_x` double precision NULL, `lig_centroid_y` double precision NULL, `lig_centroid_z` double precision NULL, `lig_dist_event` double precision NULL, `lig_id` longtext NULL, `pandda_event_map_native` longtext NULL, `pandda_event_map_cut` longtext NULL, `pandda_model_pdb` longtext NULL, `pandda_input_mtz` longtext NULL, `pandda_input_pdb` longtext NULL, `ligand_confidence_inspect` longtext NULL, `ligand_confidence` longtext NULL, `comment` longtext NULL, `interesting` bool NOT NULL, `event_status` longtext NULL, `created_date` datetime(6) NULL, `modified_date` datetime(6) NULL, `ligand_confidence_source` varchar(2) NOT NULL, `crystal_id` integer NOT NULL, `data_proc_id` integer NOT NULL); +-- +-- Create model PanddaRun +-- +CREATE TABLE `pandda_run` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `input_dir` longtext NULL, `pandda_log` varchar(255) NOT NULL UNIQUE, `pandda_version` longtext NULL, `sites_file` longtext NULL, `events_file` longtext NULL, `pandda_analysis_id` integer NOT NULL); +-- +-- Create model Proposals +-- +CREATE TABLE `proposals` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `proposal` varchar(255) NOT NULL UNIQUE, `title` varchar(10) NULL, `fedids` longtext NULL); +-- +-- Create model ProteinSite +-- +CREATE TABLE `protein_sites` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `site_name` varchar(50) NOT NULL, `site_chain` varchar(50) NOT NULL, `site_conformation` varchar(50) NOT NULL, `site_crystal_form` varchar(50) NOT NULL, `site_residue_names` longtext NOT NULL, `site_residue_indicies` longtext NOT NULL, `creator` varchar(255) NOT NULL, `fragalysis_ligand_reference_id` integer NOT NULL); +-- +-- Create model Reference +-- +CREATE TABLE `reference` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `reference_pdb` varchar(255) NULL UNIQUE); +-- +-- Create model Target +-- +CREATE TABLE `target` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `target_name` varchar(255) NOT NULL UNIQUE, `uniprot_id` varchar(255) NULL, `alias` varchar(255) NULL, `pl_reference` varchar(500) NOT NULL, `pl_monomeric` bool NOT NULL, `pl_reduce_reference_frame` bool NOT NULL, `pl_covalent_attachments` bool NOT NULL, `pl_additional_headers` longtext NOT NULL, `pl_active` bool NOT NULL); +-- +-- Create model SoakdbFiles +-- +CREATE TABLE `soakdb_files` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `filename` varchar(255) NOT NULL UNIQUE, `modification_date` bigint NOT NULL, `visit` longtext NOT NULL, `status` integer NULL, `proposal_id` integer NOT NULL); +-- +-- Create model SiteMapping +-- +CREATE TABLE `site_mapping` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `ligand_id` integer NOT NULL, `site_id` integer NOT NULL); +-- +-- Create model ReviewResponses +-- +CREATE TABLE `review_responses` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `fedid` longtext NOT NULL, `decision_int` integer NOT NULL, `decision_str` longtext NOT NULL, `reason` longtext NOT NULL, `time_submitted` integer NOT NULL, `crystal_id` integer NOT NULL, `ligand_name_id` integer NOT NULL); +-- +-- Create model Refinement +-- +CREATE TABLE `refinement` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `bound_conf` varchar(255) NULL UNIQUE, `cif` longtext NULL, `cif_prog` longtext NULL, `cif_status` longtext NULL, `lig_bound_conf` longtext NULL, `lig_cc` longtext NULL, `lig_confidence` longtext NULL, `lig_confidence_int` integer NULL, `lig_confidence_string` longtext NULL, `matrix_weight` longtext NULL, `molprobity_score` double precision NULL, `mtz_free` longtext NULL, `mtz_latest` longtext NULL, `outcome` integer NULL, `pdb_latest` longtext NULL, `r_free` double precision NULL, `ramachandran_favoured` longtext NULL, `ramachandran_outliers` longtext NULL, `rcryst` double precision NULL, `refinement_path` longtext NULL, `res` double precision NULL, `rmsd_angles` longtext NULL, `rmsd_bonds` longtext NULL, `spacegroup` longtext NULL, `status` longtext NULL, `crystal_name_id` integer NOT NULL UNIQUE); +-- +-- Create model PanddaSite +-- +CREATE TABLE `pandda_site` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `site` integer NULL, `site_aligned_centroid_x` double precision NULL, `site_aligned_centroid_y` double precision NULL, `site_aligned_centroid_z` double precision NULL, `site_native_centroid_x` double precision NULL, `site_native_centroid_y` double precision NULL, `site_native_centroid_z` double precision NULL, `pandda_run_id` integer NOT NULL); +-- +-- Create model PanddaEventStats +-- +CREATE TABLE `pandda_event_stats` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `one_minus_bdc` double precision NULL, `cluster_size` integer NULL, `glob_corr_av_map` double precision NULL, `glob_corr_mean_map` double precision NULL, `loc_corr_av_map` double precision NULL, `loc_corr_mean_map` double precision NULL, `z_mean` double precision NULL, `z_peak` double precision NULL, `b_factor_scaled` double precision NULL, `high_res` double precision NULL, `low_res` double precision NULL, `r_free` double precision NULL, `r_work` double precision NULL, `ref_rmsd` double precision NULL, `wilson_scaled_b` double precision NULL, `wilson_scaled_ln_dev` double precision NULL, `wilson_scaled_ln_dev_z` double precision NULL, `wilson_scaled_ln_rmsd` double precision NULL, `wilson_scaled_ln_rmsd_z` double precision NULL, `wilson_scaled_below_four_rmsd` double precision NULL, `wilson_scaled_below_four_rmsd_z` double precision NULL, `wilson_scaled_above_four_rmsd` double precision NULL, `wilson_scaled_above_four_rmsd_z` double precision NULL, `wilson_scaled_rmsd_all` double precision NULL, `wilson_scaled_rmsd_all_z` double precision NULL, `wilson_unscaled` double precision NULL, `wilson_unscaled_ln_dev` double precision NULL, `wilson_unscaled_ln_dev_z` double precision NULL, `wilson_unscaled_ln_rmsd` double precision NULL, `wilson_unscaled_ln_rmsd_z` double precision NULL, `wilson_unscaled_below_four_rmsd` double precision NULL, `wilson_unscaled_below_four_rmsd_z` double precision NULL, `wilson_unscaled_above_four_rmsd` double precision NULL, `wilson_unscaled_above_four_rmsd_z` double precision NULL, `wilson_unscaled_rmsd_all` double precision NULL, `wilson_unscaled_rmsd_all_z` double precision NULL, `resolution` double precision NULL, `map_uncertainty` double precision NULL, `obs_map_mean` double precision NULL, `obs_map_rms` double precision NULL, `z_map_kurt` double precision NULL, `z_map_mean` double precision NULL, `z_map_skew` double precision NULL, `z_map_std` double precision NULL, `scl_map_mean` double precision NULL, `scl_map_rms` double precision NULL, `event_id` integer NOT NULL); +-- +-- Add field pandda_run to panddaevent +-- +ALTER TABLE `pandda_event` ADD COLUMN `pandda_run_id` integer NOT NULL , ADD CONSTRAINT `pandda_event_pandda_run_id_4fa1247e_fk_pandda_run_id` FOREIGN KEY (`pandda_run_id`) REFERENCES `pandda_run`(`id`); +-- +-- Add field refinement to panddaevent +-- +ALTER TABLE `pandda_event` ADD COLUMN `refinement_id` integer NOT NULL , ADD CONSTRAINT `pandda_event_refinement_id_f7d60b87_fk_refinement_id` FOREIGN KEY (`refinement_id`) REFERENCES `refinement`(`id`); +-- +-- Add field site to panddaevent +-- +ALTER TABLE `pandda_event` ADD COLUMN `site_id` integer NOT NULL , ADD CONSTRAINT `pandda_event_site_id_a50af98f_fk_pandda_site_id` FOREIGN KEY (`site_id`) REFERENCES `pandda_site`(`id`); +-- +-- Create model MetaData +-- +CREATE TABLE `meta_data` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `site_Label` varchar(255) NOT NULL, `new_smiles` longtext NOT NULL, `alternate_name` varchar(255) NOT NULL, `pdb_id` varchar(255) NOT NULL, `fragalysis_name` varchar(255) NOT NULL UNIQUE, `original_name` varchar(255) NOT NULL, `status` varchar(255) NOT NULL, `ligand_name_id` integer NOT NULL); +-- +-- Add field target to ligand +-- +ALTER TABLE `ligand` ADD COLUMN `target_id` integer NOT NULL , ADD CONSTRAINT `ligand_target_id_7e14f3c9_fk_target_id` FOREIGN KEY (`target_id`) REFERENCES `target`(`id`); +-- +-- Create model Lab +-- +CREATE TABLE `lab` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `cryo_frac` double precision NULL, `cryo_status` longtext NULL, `cryo_stock_frac` double precision NULL, `cryo_transfer_vol` double precision NULL, `data_collection_visit` longtext NULL, `expr_conc` double precision NULL, `harvest_status` longtext NULL, `library_name` longtext NULL, `library_plate` longtext NULL, `mounting_result` longtext NULL, `mounting_time` longtext NULL, `soak_status` longtext NULL, `soak_time` longtext NULL, `soak_vol` double precision NULL, `solv_frac` double precision NULL, `stock_conc` double precision NULL, `visit` longtext NULL, `puck` varchar(100) NULL, `position` varchar(100) NULL, `pin_barcode` varchar(100) NULL, `arrival_time` datetime(6) NULL, `mounted_timestamp` datetime(6) NULL, `ispyb_status` varchar(100) NULL, `crystal_name_id` integer NOT NULL UNIQUE); +-- +-- Create model FragalysisTarget +-- +CREATE TABLE `fragalysis_target` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `target` varchar(255) NOT NULL, `metadata_file` varchar(500) NOT NULL, `input_root` longtext NOT NULL, `staging_root` longtext NOT NULL, `reference` varchar(500) NOT NULL, `biomol` varchar(500) NOT NULL); +CREATE TABLE `fragalysis_target_additional_files` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `fragalysistarget_id` integer NOT NULL, `miscfiles_id` integer NOT NULL); +-- +-- Add field fragalysis_target to fragalysisligand +-- +ALTER TABLE `fragalysis_ligand` ADD COLUMN `fragalysis_target_id` integer NOT NULL , ADD CONSTRAINT `fragalysis_ligand_fragalysis_target_id_6a3fe295_fk_fragalysi` FOREIGN KEY (`fragalysis_target_id`) REFERENCES `fragalysis_target`(`id`); +-- +-- Create model CrystalCompoundPairs +-- +CREATE TABLE `crystal_compound_pairs` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `product_smiles` varchar(255) NULL, `compound_id` integer NOT NULL, `crystal_id` integer NOT NULL); +-- +-- Add field compound to crystal +-- +-- +-- Add field target to crystal +-- +ALTER TABLE `crystal` ADD COLUMN `target_id` integer NOT NULL , ADD CONSTRAINT `crystal_target_id_36cc8752_fk_target_id` FOREIGN KEY (`target_id`) REFERENCES `target`(`id`); +-- +-- Add field visit to crystal +-- +ALTER TABLE `crystal` ADD COLUMN `visit_id` integer NOT NULL , ADD CONSTRAINT `crystal_visit_id_94356d5f_fk_soakdb_files_id` FOREIGN KEY (`visit_id`) REFERENCES `soakdb_files`(`id`); +-- +-- Create model BadAtoms +-- +CREATE TABLE `bad_atoms` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `atomid` longtext NOT NULL, `comment` longtext NOT NULL, `atomname` longtext NOT NULL, `ligand_id` integer NOT NULL); +-- +-- Create model PanddaStatisticalMap +-- +CREATE TABLE `pandda_statistical_map` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `resolution_from` double precision NULL, `resolution_to` double precision NULL, `dataset_list` longtext NOT NULL, `pandda_run_id` integer NOT NULL); +-- +-- Alter unique_together for panddaevent (1 constraint(s)) +-- +ALTER TABLE `pandda_event` ADD CONSTRAINT `pandda_event_site_id_event_crystal_id_2b9d759c_uniq` UNIQUE (`site_id`, `event`, `crystal_id`, `pandda_run_id`); +-- +-- Create model Dimple +-- +CREATE TABLE `dimple` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `mtz_path` varchar(255) NULL, `pdb_path` varchar(255) NULL, `r_free` double precision NULL, `res_high` double precision NULL, `status` longtext NULL, `crystal_name_id` integer NOT NULL UNIQUE, `reference_id` integer NULL); +-- +-- Alter unique_together for crystal (1 constraint(s)) +-- +ALTER TABLE `crystal` ADD CONSTRAINT `crystal_crystal_name_visit_id_9764d856_uniq` UNIQUE (`crystal_name`, `visit_id`); +ALTER TABLE `compound` ADD CONSTRAINT `compound_smiles_compound_string_a048b9e9_uniq` UNIQUE (`smiles`, `compound_string`); +CREATE INDEX `compound_smiles_e2c0fc93` ON `compound` (`smiles`); +CREATE INDEX `compound_compound_string_62e9304b` ON `compound` (`compound_string`); +CREATE INDEX `crystal_crystal_name_6111053e` ON `crystal` (`crystal_name`); +ALTER TABLE `data_processing` ADD CONSTRAINT `data_processing_crystal_name_id_fb3aea44_fk_crystal_id` FOREIGN KEY (`crystal_name_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `ligand` ADD CONSTRAINT `ligand_crystal_id_de4f8b7e_fk_crystal_id` FOREIGN KEY (`crystal_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `ligand` ADD CONSTRAINT `ligand_fragalysis_ligand_id_8662068f_fk_fragalysis_ligand_id` FOREIGN KEY (`fragalysis_ligand_id`) REFERENCES `fragalysis_ligand` (`id`); +ALTER TABLE `pandda_event` ADD CONSTRAINT `pandda_event_crystal_id_b75ed338_fk_crystal_id` FOREIGN KEY (`crystal_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `pandda_event` ADD CONSTRAINT `pandda_event_data_proc_id_2623d96f_fk_data_processing_id` FOREIGN KEY (`data_proc_id`) REFERENCES `data_processing` (`id`); +CREATE INDEX `pandda_event_event_81acae4d` ON `pandda_event` (`event`); +ALTER TABLE `pandda_run` ADD CONSTRAINT `pandda_run_pandda_analysis_id_21fae35d_fk_pandda_analysis_id` FOREIGN KEY (`pandda_analysis_id`) REFERENCES `pandda_analysis` (`id`); +ALTER TABLE `protein_sites` ADD CONSTRAINT `protein_sites_fragalysis_ligand_re_bd19c3ac_fk_fragalysi` FOREIGN KEY (`fragalysis_ligand_reference_id`) REFERENCES `fragalysis_ligand` (`id`); +ALTER TABLE `soakdb_files` ADD CONSTRAINT `soakdb_files_proposal_id_524d1fc3_fk_proposals_id` FOREIGN KEY (`proposal_id`) REFERENCES `proposals` (`id`); +ALTER TABLE `site_mapping` ADD CONSTRAINT `site_mapping_ligand_id_9615b358_fk_fragalysis_ligand_id` FOREIGN KEY (`ligand_id`) REFERENCES `fragalysis_ligand` (`id`); +ALTER TABLE `site_mapping` ADD CONSTRAINT `site_mapping_site_id_3533ce74_fk_protein_sites_id` FOREIGN KEY (`site_id`) REFERENCES `protein_sites` (`id`); +ALTER TABLE `review_responses` ADD CONSTRAINT `review_responses_crystal_id_bc90b8d9_fk_crystal_id` FOREIGN KEY (`crystal_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `review_responses` ADD CONSTRAINT `review_responses_ligand_name_id_9900afe9_fk_ligand_id` FOREIGN KEY (`ligand_name_id`) REFERENCES `ligand` (`id`); +ALTER TABLE `refinement` ADD CONSTRAINT `refinement_crystal_name_id_38c8a07b_fk_crystal_id` FOREIGN KEY (`crystal_name_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `pandda_site` ADD CONSTRAINT `pandda_site_pandda_run_id_site_48013a5b_uniq` UNIQUE (`pandda_run_id`, `site`); +ALTER TABLE `pandda_site` ADD CONSTRAINT `pandda_site_pandda_run_id_be084b50_fk_pandda_run_id` FOREIGN KEY (`pandda_run_id`) REFERENCES `pandda_run` (`id`); +CREATE INDEX `pandda_site_site_80cc797a` ON `pandda_site` (`site`); +ALTER TABLE `pandda_event_stats` ADD CONSTRAINT `pandda_event_stats_event_id_5f015036_fk_pandda_event_id` FOREIGN KEY (`event_id`) REFERENCES `pandda_event` (`id`); +ALTER TABLE `meta_data` ADD CONSTRAINT `meta_data_ligand_name_id_820bd396_fk_fragalysis_ligand_id` FOREIGN KEY (`ligand_name_id`) REFERENCES `fragalysis_ligand` (`id`); +ALTER TABLE `lab` ADD CONSTRAINT `lab_crystal_name_id_0412c3fb_fk_crystal_id` FOREIGN KEY (`crystal_name_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `fragalysis_target_additional_files` ADD CONSTRAINT `fragalysis_target_additi_fragalysistarget_id_misc_88fee56b_uniq` UNIQUE (`fragalysistarget_id`, `miscfiles_id`); +ALTER TABLE `fragalysis_target_additional_files` ADD CONSTRAINT `fragalysis_target_ad_fragalysistarget_id_8343cb31_fk_fragalysi` FOREIGN KEY (`fragalysistarget_id`) REFERENCES `fragalysis_target` (`id`); +ALTER TABLE `fragalysis_target_additional_files` ADD CONSTRAINT `fragalysis_target_ad_miscfiles_id_2dc8527c_fk_misc_file` FOREIGN KEY (`miscfiles_id`) REFERENCES `misc_files` (`id`); +ALTER TABLE `crystal_compound_pairs` ADD CONSTRAINT `crystal_compound_pairs_compound_id_b3fa5eda_fk_compound_id` FOREIGN KEY (`compound_id`) REFERENCES `compound` (`id`); +ALTER TABLE `crystal_compound_pairs` ADD CONSTRAINT `crystal_compound_pairs_crystal_id_7a72bb21_fk_crystal_id` FOREIGN KEY (`crystal_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `bad_atoms` ADD CONSTRAINT `bad_atoms_ligand_id_44742335_fk_ligand_id` FOREIGN KEY (`ligand_id`) REFERENCES `ligand` (`id`); +ALTER TABLE `pandda_statistical_map` ADD CONSTRAINT `pandda_statistical_map_resolution_from_resoluti_14bb7f7b_uniq` UNIQUE (`resolution_from`, `resolution_to`, `pandda_run_id`); +ALTER TABLE `pandda_statistical_map` ADD CONSTRAINT `pandda_statistical_map_pandda_run_id_eb293e7e_fk_pandda_run_id` FOREIGN KEY (`pandda_run_id`) REFERENCES `pandda_run` (`id`); +ALTER TABLE `dimple` ADD CONSTRAINT `dimple_pdb_path_mtz_path_6c49ab75_uniq` UNIQUE (`pdb_path`, `mtz_path`); +ALTER TABLE `dimple` ADD CONSTRAINT `dimple_crystal_name_id_c29f59d1_fk_crystal_id` FOREIGN KEY (`crystal_name_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `dimple` ADD CONSTRAINT `dimple_reference_id_6af81759_fk_reference_id` FOREIGN KEY (`reference_id`) REFERENCES `reference` (`id`); diff --git a/xchem_db/manage.py b/xchem_db/manage.py new file mode 100755 index 00000000..483d2bf9 --- /dev/null +++ b/xchem_db/manage.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'xchem_db.settings') + os.environ.setdefault('SETTINGS_MODULE', 'xchem_db.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/xchem_db/requirements.txt b/xchem_db/requirements.txt new file mode 100644 index 00000000..eb7c7d4c --- /dev/null +++ b/xchem_db/requirements.txt @@ -0,0 +1,10 @@ +asgiref==3.3.1 +django==3.1.7 +django-extensions==3.1.1 +django-mysql==3.11.1 +mysql-connector-python==8.0.23 +protobuf==3.15.6 +psycopg2-binary==2.8.6 +pytz==2021.1 +six==1.15.0 +sqlparse==0.4.1 diff --git a/xchem_db/run_migrations.sh b/xchem_db/run_migrations.sh new file mode 100644 index 00000000..310dda92 --- /dev/null +++ b/xchem_db/run_migrations.sh @@ -0,0 +1,7 @@ +!#/bin/bash + +python3.6 /xcdb/manage.py makemigrations +python3.6 /xcdb/manage.py migrate +python3.6 /xcdb/manage.py makemigrations xchem_db +python3.6 /xcdb/manage.py migrate xchem_db +python3.6 /xcdb/manage.py runserver 0.0.0.0:8000 \ No newline at end of file diff --git a/xchem_db/run_sql_gen.py b/xchem_db/run_sql_gen.py new file mode 100644 index 00000000..33c3f1ea --- /dev/null +++ b/xchem_db/run_sql_gen.py @@ -0,0 +1,11 @@ +import os +import glob + +if not os.path.isdir('xchem_db/migrations'): + raise Exception('No migrations found! Please ensure these are generated so that SQL can be generated.') + +if os.path.isdir('xchem_db/migrations'): + for f in glob.glob('xchem_db/migrations/*.py'): + if '__init__' not in f: + migration_name = f.split('/')[-1].replace('.py', '') + os.system(f'python manage.py sqlmigrate xchem_db {migration_name} > sql/{migration_name}.sql') diff --git a/xchem_db/schema.png b/xchem_db/schema.png new file mode 100644 index 00000000..ad1931fc Binary files /dev/null and b/xchem_db/schema.png differ diff --git a/xchem_db/serializers.py b/xchem_db/serializers.py deleted file mode 100644 index d89b5a71..00000000 --- a/xchem_db/serializers.py +++ /dev/null @@ -1,175 +0,0 @@ -from rest_framework import serializers - -from xchem_db.models import * - - -class ProposalsSerializer(serializers.ModelSerializer): - class Meta: - model = Proposals - fields = ('__all__',) - - -class TargetSerializer(serializers.ModelSerializer): - class Meta: - model = Target - fields = ('__all__',) - - -class CompoundsSerializer(serializers.ModelSerializer): - class Meta: - model = Compounds - fields = ('__all__',) - - -class ReferenceSerializer(serializers.ModelSerializer): - class Meta: - model = Reference - fields = ('__all__',) - - -class SoakdbFilesSerializer(serializers.ModelSerializer): - class Meta: - model = SoakdbFiles - fields = ('__all__',) - - -class CrystalSerializer(serializers.ModelSerializer): - class Meta: - model = Crystal - fields = ('__all__',) - - -class DataProcessingSerializer(serializers.ModelSerializer): - class Meta: - model = DataProcessing - fields = ('__all__',) - - -class DimpleSerializer(serializers.ModelSerializer): - class Meta: - model = Dimple - fields = ('__all__',) - - -class LabSerializer(serializers.ModelSerializer): - class Meta: - model = Lab - fields = ('__all__',) - - -class RefinementSerializer(serializers.ModelSerializer): - class Meta: - model = Refinement - fields = ('__all__',) - - -class PanddaAnalysisSerializer(serializers.ModelSerializer): - class Meta: - model = PanddaAnalysis - fields = ('__all__',) - - -class PanddaRunSerializer(serializers.ModelSerializer): - class Meta: - model = PanddaRun - fields = ('__all__',) - - -class PanddaSiteSerializer(serializers.ModelSerializer): - class Meta: - model = PanddaSite - fields = ('__all__',) - - -class PanddaEventSerializer(serializers.ModelSerializer): - class Meta: - model = PanddaEvent - fields = ('__all__',) - - -class PanddaEventStatsSerializer(serializers.ModelSerializer): - class Meta: - model = PanddaEventStats - fields = ('__all__',) - - -class FragspectCrystalSerializer(serializers.ModelSerializer): - crystal = serializers.CharField(source='crystal.crystal_name') - site_number = serializers.IntegerField(source='site.site') - event_number = serializers.IntegerField(source='event') - target_name = serializers.CharField(source='crystal.target.target_name') - crystal_status = serializers.CharField(source='refinement.outcome') - confidence = serializers.CharField(source='ligand_confidence') - crystal_resolution = serializers.CharField(source='refinement.res') - smiles = serializers.CharField(source='crystal.compound.smiles') - spacegroup = serializers.CharField(source='refinement.spacegroup') - cell = serializers.CharField(source='data_proc.unit_cell') - event_comment = serializers.CharField(source='comment') - - class Meta: - model = PanddaEvent - fields = ( - 'id', - 'crystal', - 'site_number', - 'event_number', - 'lig_id', - 'target_name', - 'crystal_status', - 'event_status', - 'confidence', - 'crystal_resolution', - 'smiles', - 'spacegroup', - 'cell', - 'event_comment', - 'interesting', - ) - - -class MiscFilesSerializer(serializers.ModelSerializer): - class Meta: - model = MiscFiles - fields = ('__all__',) - - -class FragalysisTargetSerializer(serializers.ModelSerializer): - class Meta: - model = FragalysisTarget - fields = ('__all__',) - - -class FragalysisLigandSerializer(serializers.ModelSerializer): - class Meta: - model = FragalysisLigand - fields = ('__all__',) - - -class LigandSerializer(serializers.ModelSerializer): - class Meta: - model = Ligand - fields = ('__all__',) - - -class ReviewResponsesSerializer(serializers.ModelSerializer): - class Meta: - model = ReviewResponses - fields = ('__all__',) - - -class ReviewResponses2Serializer(serializers.ModelSerializer): - class Meta: - model = ReviewResponses2 - fields = ('__all__',) - - -class BadAtomsSerializer(serializers.ModelSerializer): - class Meta: - model = BadAtoms - fields = ('__all__',) - - -class MetaDataSerializer(serializers.ModelSerializer): - class Meta: - model = MetaData - fields = ('__all__',) diff --git a/xchem_db/setup.py b/xchem_db/setup.py new file mode 100644 index 00000000..7299bb88 --- /dev/null +++ b/xchem_db/setup.py @@ -0,0 +1,79 @@ +# To use a consistent encoding +from codecs import open +from os import path +from os import environ + +# Always prefer setuptools over distutils +from setuptools import setup, find_packages + +here = path.abspath(path.dirname(__file__)) + +long_description = "Stand-alone version of django module for xchem db. See github.com/xchem/xchem_db for more info" + +print(find_packages(exclude=["contrib", "docs", "tests"])) +setup( + name="xcdb", + # Versions should comply with PEP440. For a discussion on single-sourcing + # the version across setup.py and the project code, see + # https://packaging.python.org/en/latest/single_source_version.html + version=environ.get('STACKMANAGER_VERSION'), + description="Library for XChem Django database", + long_description=long_description, + # The project's main homepage. + url="https://github.com/xchem/xchem_db.git", + # Author details + author="Rachael Skyner", + author_email="rachael.skyner@diamond.ac.uk", + # Choose your license + license="Apache 2.0", + # See https://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ + # How mature is this project? Common values are + # 3 - Alpha + # 4 - Beta + # 5 - Production/Stable + "Development Status :: 4 - Beta", + # Indicate who your project is intended for + "Intended Audience :: Developers", + "Topic :: Software Development :: Build Tools", + # Pick your license as you wish (should match "license" above) + "License :: OSI Approved :: Apache Software License", + # Specify the Python versions you support here. In particular, ensure + # that you indicate whether you support Python 2, Python 3 or both. + "Programming Language :: Python :: 3.6", + ], + # What does your project relate to? + keywords="", + # You can just specify the packages manually here if your project is + # simple. Or you can use find_packages(). + packages=find_packages(exclude=["contrib", "docs", "tests"]), + # Alternatively, if you want to distribute just a my_module.py, uncomment + # this: + # py_modules=["my_module"], + # List run-time dependencies here. These will be installed by pip when + # your project is installed. For an analysis of "install_requires" vs pip's + # requirements files see: + # https://packaging.python.org/en/latest/requirements.html + install_requires=['django', 'psycopg2-binary', 'django_extensions', 'django-mysql', 'mysql-connector-python', 'pygraphviz'], + # List additional groups of dependencies here (e.g. development + # dependencies). You can install these using the following syntax, + # for example: + # $ pip install -e .[dev,test] + extras_require={"dev": ["check-manifest"], "test": ["coverage"]}, + # If there are data files included in your packages that need to be + # installed, specify them here. If using Python 2.6 or less, then these + # have to be included in MANIFEST.in as well. + package_data={}, + # Although 'package_data' is the preferred approach, in some case you may + # need to place data files outside of your packages. See: + # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa + # In this case, 'data_file' will be installed into '/my_data' + # data_files=[('my_data', ['data/data_file'])], + # To provide executable scripts, use entry points in preference to the + # "scripts" keyword. Entry points provide cross-platform support and allow + # pip to create the appropriate form of executable for the target platform. + entry_points={ + "console_scripts": [ + ] + }, +) diff --git a/xchem_db/sql/0001_initial.sql b/xchem_db/sql/0001_initial.sql new file mode 100644 index 00000000..7729eeb2 --- /dev/null +++ b/xchem_db/sql/0001_initial.sql @@ -0,0 +1,179 @@ +-- +-- Create model Compounds +-- +CREATE TABLE `compound` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `smiles` varchar(255) NULL, `compound_string` varchar(255) NULL); +-- +-- Create model Crystal +-- +CREATE TABLE `crystal` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `crystal_name` varchar(255) NOT NULL, `status` varchar(2) NOT NULL, `well` varchar(4) NULL, `echo_x` integer NULL, `echo_y` integer NULL, `score` integer NULL); +-- +-- Create model DataProcessing +-- +CREATE TABLE `data_processing` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `auto_assigned` longtext NULL, `cchalf_high` double precision NULL, `cchalf_low` double precision NULL, `cchalf_overall` double precision NULL, `completeness_high` double precision NULL, `completeness_low` double precision NULL, `completeness_overall` double precision NULL, `dimple_mtz_path` longtext NULL, `dimple_pdb_path` longtext NULL, `dimple_status` longtext NULL, `image_path` longtext NULL, `isig_high` double precision NULL, `isig_low` double precision NULL, `isig_overall` double precision NULL, `lattice` longtext NULL, `log_name` longtext NULL, `logfile_path` longtext NULL, `mtz_name` longtext NULL, `mtz_path` longtext NULL, `multiplicity_high` double precision NULL, `multiplicity_low` double precision NULL, `multiplicity_overall` double precision NULL, `original_directory` longtext NULL, `point_group` longtext NULL, `program` longtext NULL, `r_cryst` double precision NULL, `r_free` double precision NULL, `r_merge_high` double precision NULL, `r_merge_low` double precision NULL, `r_merge_overall` double precision NULL, `res_high` double precision NULL, `res_high_15_sigma` double precision NULL, `res_high_outer_shell` double precision NULL, `res_low` double precision NULL, `res_low_inner_shell` double precision NULL, `res_overall` longtext NULL, `score` double precision NULL, `spacegroup` longtext NULL, `status` longtext NULL, `unique_ref_overall` integer NULL, `unit_cell` longtext NULL, `unit_cell_vol` double precision NULL, `crystal_name_id` integer NOT NULL UNIQUE); +-- +-- Create model FragalysisLigand +-- +CREATE TABLE `fragalysis_ligand` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `ligand_name` varchar(255) NOT NULL, `crystallographic_bound` varchar(500) NOT NULL, `lig_mol_file` varchar(500) NOT NULL, `apo_pdb` varchar(500) NOT NULL, `bound_pdb` varchar(500) NOT NULL, `smiles_file` varchar(500) NOT NULL, `desolvated_pdb` varchar(500) NOT NULL, `solvated_pdb` varchar(500) NOT NULL, `pandda_event` varchar(500) NOT NULL, `two_fofc` varchar(500) NOT NULL, `fofc` varchar(500) NOT NULL, `modification_date` bigint NOT NULL); +-- +-- Create model Ligand +-- +CREATE TABLE `ligand` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `crystal_id` integer NOT NULL, `fragalysis_ligand_id` integer NOT NULL); +-- +-- Create model MiscFiles +-- +CREATE TABLE `misc_files` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `file` varchar(500) NOT NULL, `description` longtext NOT NULL); +-- +-- Create model PanddaAnalysis +-- +CREATE TABLE `pandda_analysis` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `pandda_dir` varchar(255) NOT NULL UNIQUE); +-- +-- Create model PanddaEvent +-- +CREATE TABLE `pandda_event` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `event` integer NULL, `event_centroid_x` double precision NULL, `event_centroid_y` double precision NULL, `event_centroid_z` double precision NULL, `event_dist_from_site_centroid` longtext NULL, `lig_centroid_x` double precision NULL, `lig_centroid_y` double precision NULL, `lig_centroid_z` double precision NULL, `lig_dist_event` double precision NULL, `lig_id` longtext NULL, `pandda_event_map_native` longtext NULL, `pandda_event_map_cut` longtext NULL, `pandda_model_pdb` longtext NULL, `pandda_input_mtz` longtext NULL, `pandda_input_pdb` longtext NULL, `ligand_confidence_inspect` longtext NULL, `ligand_confidence` longtext NULL, `comment` longtext NULL, `interesting` bool NOT NULL, `event_status` longtext NULL, `created_date` datetime(6) NULL, `modified_date` datetime(6) NULL, `ligand_confidence_source` varchar(2) NOT NULL, `crystal_id` integer NOT NULL, `data_proc_id` integer NOT NULL); +-- +-- Create model PanddaRun +-- +CREATE TABLE `pandda_run` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `input_dir` longtext NULL, `pandda_log` varchar(255) NOT NULL UNIQUE, `pandda_version` longtext NULL, `sites_file` longtext NULL, `events_file` longtext NULL, `pandda_analysis_id` integer NOT NULL); +-- +-- Create model Proposals +-- +CREATE TABLE `proposals` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `proposal` varchar(255) NOT NULL UNIQUE, `title` varchar(10) NULL, `fedids` longtext NULL); +-- +-- Create model ProteinSite +-- +CREATE TABLE `protein_sites` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `site_name` varchar(50) NOT NULL, `site_chain` varchar(50) NOT NULL, `site_conformation` varchar(50) NOT NULL, `site_crystal_form` varchar(50) NOT NULL, `site_residue_names` longtext NOT NULL, `site_residue_indicies` longtext NOT NULL, `creator` varchar(255) NOT NULL, `fragalysis_ligand_reference_id` integer NOT NULL); +-- +-- Create model Reference +-- +CREATE TABLE `reference` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `reference_pdb` varchar(255) NULL UNIQUE); +-- +-- Create model Target +-- +CREATE TABLE `target` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `target_name` varchar(255) NOT NULL UNIQUE, `uniprot_id` varchar(255) NULL, `alias` varchar(255) NULL, `pl_reference` varchar(500) NOT NULL, `pl_monomeric` bool NOT NULL, `pl_reduce_reference_frame` bool NOT NULL, `pl_covalent_attachments` bool NOT NULL, `pl_additional_headers` longtext NOT NULL, `pl_active` bool NOT NULL); +-- +-- Create model SoakdbFiles +-- +CREATE TABLE `soakdb_files` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `filename` varchar(255) NOT NULL UNIQUE, `modification_date` bigint NOT NULL, `visit` longtext NOT NULL, `status` integer NULL, `proposal_id` integer NOT NULL); +-- +-- Create model SiteMapping +-- +CREATE TABLE `site_mapping` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `ligand_id` integer NOT NULL, `site_id` integer NOT NULL); +-- +-- Create model ReviewResponses +-- +CREATE TABLE `review_responses` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `fedid` longtext NOT NULL, `decision_int` integer NOT NULL, `decision_str` longtext NOT NULL, `reason` longtext NOT NULL, `time_submitted` integer NOT NULL, `crystal_id` integer NOT NULL, `ligand_name_id` integer NOT NULL); +-- +-- Create model Refinement +-- +CREATE TABLE `refinement` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `bound_conf` varchar(255) NULL UNIQUE, `cif` longtext NULL, `cif_prog` longtext NULL, `cif_status` longtext NULL, `lig_bound_conf` longtext NULL, `lig_cc` longtext NULL, `lig_confidence` longtext NULL, `lig_confidence_int` integer NULL, `lig_confidence_string` longtext NULL, `matrix_weight` longtext NULL, `molprobity_score` double precision NULL, `mtz_free` longtext NULL, `mtz_latest` longtext NULL, `outcome` integer NULL, `pdb_latest` longtext NULL, `r_free` double precision NULL, `ramachandran_favoured` longtext NULL, `ramachandran_outliers` longtext NULL, `rcryst` double precision NULL, `refinement_path` longtext NULL, `res` double precision NULL, `rmsd_angles` longtext NULL, `rmsd_bonds` longtext NULL, `spacegroup` longtext NULL, `status` longtext NULL, `crystal_name_id` integer NOT NULL UNIQUE); +-- +-- Create model PanddaSite +-- +CREATE TABLE `pandda_site` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `site` integer NULL, `site_aligned_centroid_x` double precision NULL, `site_aligned_centroid_y` double precision NULL, `site_aligned_centroid_z` double precision NULL, `site_native_centroid_x` double precision NULL, `site_native_centroid_y` double precision NULL, `site_native_centroid_z` double precision NULL, `pandda_run_id` integer NOT NULL); +-- +-- Create model PanddaEventStats +-- +CREATE TABLE `pandda_event_stats` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `one_minus_bdc` double precision NULL, `cluster_size` integer NULL, `glob_corr_av_map` double precision NULL, `glob_corr_mean_map` double precision NULL, `loc_corr_av_map` double precision NULL, `loc_corr_mean_map` double precision NULL, `z_mean` double precision NULL, `z_peak` double precision NULL, `b_factor_scaled` double precision NULL, `high_res` double precision NULL, `low_res` double precision NULL, `r_free` double precision NULL, `r_work` double precision NULL, `ref_rmsd` double precision NULL, `wilson_scaled_b` double precision NULL, `wilson_scaled_ln_dev` double precision NULL, `wilson_scaled_ln_dev_z` double precision NULL, `wilson_scaled_ln_rmsd` double precision NULL, `wilson_scaled_ln_rmsd_z` double precision NULL, `wilson_scaled_below_four_rmsd` double precision NULL, `wilson_scaled_below_four_rmsd_z` double precision NULL, `wilson_scaled_above_four_rmsd` double precision NULL, `wilson_scaled_above_four_rmsd_z` double precision NULL, `wilson_scaled_rmsd_all` double precision NULL, `wilson_scaled_rmsd_all_z` double precision NULL, `wilson_unscaled` double precision NULL, `wilson_unscaled_ln_dev` double precision NULL, `wilson_unscaled_ln_dev_z` double precision NULL, `wilson_unscaled_ln_rmsd` double precision NULL, `wilson_unscaled_ln_rmsd_z` double precision NULL, `wilson_unscaled_below_four_rmsd` double precision NULL, `wilson_unscaled_below_four_rmsd_z` double precision NULL, `wilson_unscaled_above_four_rmsd` double precision NULL, `wilson_unscaled_above_four_rmsd_z` double precision NULL, `wilson_unscaled_rmsd_all` double precision NULL, `wilson_unscaled_rmsd_all_z` double precision NULL, `resolution` double precision NULL, `map_uncertainty` double precision NULL, `obs_map_mean` double precision NULL, `obs_map_rms` double precision NULL, `z_map_kurt` double precision NULL, `z_map_mean` double precision NULL, `z_map_skew` double precision NULL, `z_map_std` double precision NULL, `scl_map_mean` double precision NULL, `scl_map_rms` double precision NULL, `event_id` integer NOT NULL); +-- +-- Add field pandda_run to panddaevent +-- +ALTER TABLE `pandda_event` ADD COLUMN `pandda_run_id` integer NOT NULL , ADD CONSTRAINT `pandda_event_pandda_run_id_4fa1247e_fk_pandda_run_id` FOREIGN KEY (`pandda_run_id`) REFERENCES `pandda_run`(`id`); +-- +-- Add field refinement to panddaevent +-- +ALTER TABLE `pandda_event` ADD COLUMN `refinement_id` integer NOT NULL , ADD CONSTRAINT `pandda_event_refinement_id_f7d60b87_fk_refinement_id` FOREIGN KEY (`refinement_id`) REFERENCES `refinement`(`id`); +-- +-- Add field site to panddaevent +-- +ALTER TABLE `pandda_event` ADD COLUMN `site_id` integer NOT NULL , ADD CONSTRAINT `pandda_event_site_id_a50af98f_fk_pandda_site_id` FOREIGN KEY (`site_id`) REFERENCES `pandda_site`(`id`); +-- +-- Create model MetaData +-- +CREATE TABLE `meta_data` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `site_Label` varchar(255) NOT NULL, `new_smiles` longtext NOT NULL, `alternate_name` varchar(255) NOT NULL, `pdb_id` varchar(255) NOT NULL, `fragalysis_name` varchar(255) NOT NULL UNIQUE, `original_name` varchar(255) NOT NULL, `status` varchar(255) NOT NULL, `ligand_name_id` integer NOT NULL); +-- +-- Add field target to ligand +-- +ALTER TABLE `ligand` ADD COLUMN `target_id` integer NOT NULL , ADD CONSTRAINT `ligand_target_id_7e14f3c9_fk_target_id` FOREIGN KEY (`target_id`) REFERENCES `target`(`id`); +-- +-- Create model Lab +-- +CREATE TABLE `lab` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `cryo_frac` double precision NULL, `cryo_status` longtext NULL, `cryo_stock_frac` double precision NULL, `cryo_transfer_vol` double precision NULL, `data_collection_visit` longtext NULL, `expr_conc` double precision NULL, `harvest_status` longtext NULL, `library_name` longtext NULL, `library_plate` longtext NULL, `mounting_result` longtext NULL, `mounting_time` longtext NULL, `soak_status` longtext NULL, `soak_time` longtext NULL, `soak_vol` double precision NULL, `solv_frac` double precision NULL, `stock_conc` double precision NULL, `visit` longtext NULL, `puck` varchar(100) NULL, `position` varchar(100) NULL, `pin_barcode` varchar(100) NULL, `arrival_time` datetime(6) NULL, `mounted_timestamp` datetime(6) NULL, `ispyb_status` varchar(100) NULL, `crystal_name_id` integer NOT NULL UNIQUE); +-- +-- Create model FragalysisTarget +-- +CREATE TABLE `fragalysis_target` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `target` varchar(255) NOT NULL, `metadata_file` varchar(500) NOT NULL, `input_root` longtext NOT NULL, `staging_root` longtext NOT NULL, `reference` varchar(500) NOT NULL, `biomol` varchar(500) NOT NULL); +CREATE TABLE `fragalysis_target_additional_files` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `fragalysistarget_id` integer NOT NULL, `miscfiles_id` integer NOT NULL); +-- +-- Add field fragalysis_target to fragalysisligand +-- +ALTER TABLE `fragalysis_ligand` ADD COLUMN `fragalysis_target_id` integer NOT NULL , ADD CONSTRAINT `fragalysis_ligand_fragalysis_target_id_6a3fe295_fk_fragalysi` FOREIGN KEY (`fragalysis_target_id`) REFERENCES `fragalysis_target`(`id`); +-- +-- Create model CrystalCompoundPairs +-- +CREATE TABLE `crystal_compound_pairs` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `product_smiles` varchar(255) NULL, `compound_id` integer NOT NULL, `crystal_id` integer NOT NULL); +-- +-- Add field compound to crystal +-- +-- +-- Add field target to crystal +-- +ALTER TABLE `crystal` ADD COLUMN `target_id` integer NOT NULL , ADD CONSTRAINT `crystal_target_id_36cc8752_fk_target_id` FOREIGN KEY (`target_id`) REFERENCES `target`(`id`); +-- +-- Add field visit to crystal +-- +ALTER TABLE `crystal` ADD COLUMN `visit_id` integer NOT NULL , ADD CONSTRAINT `crystal_visit_id_94356d5f_fk_soakdb_files_id` FOREIGN KEY (`visit_id`) REFERENCES `soakdb_files`(`id`); +-- +-- Create model BadAtoms +-- +CREATE TABLE `bad_atoms` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `atomid` longtext NOT NULL, `comment` longtext NOT NULL, `atomname` longtext NOT NULL, `ligand_id` integer NOT NULL); +-- +-- Create model PanddaStatisticalMap +-- +CREATE TABLE `pandda_statistical_map` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `resolution_from` double precision NULL, `resolution_to` double precision NULL, `dataset_list` longtext NOT NULL, `pandda_run_id` integer NOT NULL); +-- +-- Alter unique_together for panddaevent (1 constraint(s)) +-- +ALTER TABLE `pandda_event` ADD CONSTRAINT `pandda_event_site_id_event_crystal_id_2b9d759c_uniq` UNIQUE (`site_id`, `event`, `crystal_id`, `pandda_run_id`); +-- +-- Create model Dimple +-- +CREATE TABLE `dimple` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `mtz_path` varchar(255) NULL, `pdb_path` varchar(255) NULL, `r_free` double precision NULL, `res_high` double precision NULL, `status` longtext NULL, `crystal_name_id` integer NOT NULL UNIQUE, `reference_id` integer NULL); +-- +-- Alter unique_together for crystal (1 constraint(s)) +-- +ALTER TABLE `crystal` ADD CONSTRAINT `crystal_crystal_name_visit_id_9764d856_uniq` UNIQUE (`crystal_name`, `visit_id`); +ALTER TABLE `compound` ADD CONSTRAINT `compound_smiles_compound_string_a048b9e9_uniq` UNIQUE (`smiles`, `compound_string`); +CREATE INDEX `compound_smiles_e2c0fc93` ON `compound` (`smiles`); +CREATE INDEX `compound_compound_string_62e9304b` ON `compound` (`compound_string`); +CREATE INDEX `crystal_crystal_name_6111053e` ON `crystal` (`crystal_name`); +ALTER TABLE `data_processing` ADD CONSTRAINT `data_processing_crystal_name_id_fb3aea44_fk_crystal_id` FOREIGN KEY (`crystal_name_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `ligand` ADD CONSTRAINT `ligand_crystal_id_de4f8b7e_fk_crystal_id` FOREIGN KEY (`crystal_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `ligand` ADD CONSTRAINT `ligand_fragalysis_ligand_id_8662068f_fk_fragalysis_ligand_id` FOREIGN KEY (`fragalysis_ligand_id`) REFERENCES `fragalysis_ligand` (`id`); +ALTER TABLE `pandda_event` ADD CONSTRAINT `pandda_event_crystal_id_b75ed338_fk_crystal_id` FOREIGN KEY (`crystal_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `pandda_event` ADD CONSTRAINT `pandda_event_data_proc_id_2623d96f_fk_data_processing_id` FOREIGN KEY (`data_proc_id`) REFERENCES `data_processing` (`id`); +CREATE INDEX `pandda_event_event_81acae4d` ON `pandda_event` (`event`); +ALTER TABLE `pandda_run` ADD CONSTRAINT `pandda_run_pandda_analysis_id_21fae35d_fk_pandda_analysis_id` FOREIGN KEY (`pandda_analysis_id`) REFERENCES `pandda_analysis` (`id`); +ALTER TABLE `protein_sites` ADD CONSTRAINT `protein_sites_fragalysis_ligand_re_bd19c3ac_fk_fragalysi` FOREIGN KEY (`fragalysis_ligand_reference_id`) REFERENCES `fragalysis_ligand` (`id`); +ALTER TABLE `soakdb_files` ADD CONSTRAINT `soakdb_files_proposal_id_524d1fc3_fk_proposals_id` FOREIGN KEY (`proposal_id`) REFERENCES `proposals` (`id`); +ALTER TABLE `site_mapping` ADD CONSTRAINT `site_mapping_ligand_id_9615b358_fk_fragalysis_ligand_id` FOREIGN KEY (`ligand_id`) REFERENCES `fragalysis_ligand` (`id`); +ALTER TABLE `site_mapping` ADD CONSTRAINT `site_mapping_site_id_3533ce74_fk_protein_sites_id` FOREIGN KEY (`site_id`) REFERENCES `protein_sites` (`id`); +ALTER TABLE `review_responses` ADD CONSTRAINT `review_responses_crystal_id_bc90b8d9_fk_crystal_id` FOREIGN KEY (`crystal_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `review_responses` ADD CONSTRAINT `review_responses_ligand_name_id_9900afe9_fk_ligand_id` FOREIGN KEY (`ligand_name_id`) REFERENCES `ligand` (`id`); +ALTER TABLE `refinement` ADD CONSTRAINT `refinement_crystal_name_id_38c8a07b_fk_crystal_id` FOREIGN KEY (`crystal_name_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `pandda_site` ADD CONSTRAINT `pandda_site_pandda_run_id_site_48013a5b_uniq` UNIQUE (`pandda_run_id`, `site`); +ALTER TABLE `pandda_site` ADD CONSTRAINT `pandda_site_pandda_run_id_be084b50_fk_pandda_run_id` FOREIGN KEY (`pandda_run_id`) REFERENCES `pandda_run` (`id`); +CREATE INDEX `pandda_site_site_80cc797a` ON `pandda_site` (`site`); +ALTER TABLE `pandda_event_stats` ADD CONSTRAINT `pandda_event_stats_event_id_5f015036_fk_pandda_event_id` FOREIGN KEY (`event_id`) REFERENCES `pandda_event` (`id`); +ALTER TABLE `meta_data` ADD CONSTRAINT `meta_data_ligand_name_id_820bd396_fk_fragalysis_ligand_id` FOREIGN KEY (`ligand_name_id`) REFERENCES `fragalysis_ligand` (`id`); +ALTER TABLE `lab` ADD CONSTRAINT `lab_crystal_name_id_0412c3fb_fk_crystal_id` FOREIGN KEY (`crystal_name_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `fragalysis_target_additional_files` ADD CONSTRAINT `fragalysis_target_additi_fragalysistarget_id_misc_88fee56b_uniq` UNIQUE (`fragalysistarget_id`, `miscfiles_id`); +ALTER TABLE `fragalysis_target_additional_files` ADD CONSTRAINT `fragalysis_target_ad_fragalysistarget_id_8343cb31_fk_fragalysi` FOREIGN KEY (`fragalysistarget_id`) REFERENCES `fragalysis_target` (`id`); +ALTER TABLE `fragalysis_target_additional_files` ADD CONSTRAINT `fragalysis_target_ad_miscfiles_id_2dc8527c_fk_misc_file` FOREIGN KEY (`miscfiles_id`) REFERENCES `misc_files` (`id`); +ALTER TABLE `crystal_compound_pairs` ADD CONSTRAINT `crystal_compound_pairs_compound_id_b3fa5eda_fk_compound_id` FOREIGN KEY (`compound_id`) REFERENCES `compound` (`id`); +ALTER TABLE `crystal_compound_pairs` ADD CONSTRAINT `crystal_compound_pairs_crystal_id_7a72bb21_fk_crystal_id` FOREIGN KEY (`crystal_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `bad_atoms` ADD CONSTRAINT `bad_atoms_ligand_id_44742335_fk_ligand_id` FOREIGN KEY (`ligand_id`) REFERENCES `ligand` (`id`); +ALTER TABLE `pandda_statistical_map` ADD CONSTRAINT `pandda_statistical_map_resolution_from_resoluti_14bb7f7b_uniq` UNIQUE (`resolution_from`, `resolution_to`, `pandda_run_id`); +ALTER TABLE `pandda_statistical_map` ADD CONSTRAINT `pandda_statistical_map_pandda_run_id_eb293e7e_fk_pandda_run_id` FOREIGN KEY (`pandda_run_id`) REFERENCES `pandda_run` (`id`); +ALTER TABLE `dimple` ADD CONSTRAINT `dimple_pdb_path_mtz_path_6c49ab75_uniq` UNIQUE (`pdb_path`, `mtz_path`); +ALTER TABLE `dimple` ADD CONSTRAINT `dimple_crystal_name_id_c29f59d1_fk_crystal_id` FOREIGN KEY (`crystal_name_id`) REFERENCES `crystal` (`id`); +ALTER TABLE `dimple` ADD CONSTRAINT `dimple_reference_id_6af81759_fk_reference_id` FOREIGN KEY (`reference_id`) REFERENCES `reference` (`id`); diff --git a/xchem_db/sql/0002_reviewresponses_comment.sql b/xchem_db/sql/0002_reviewresponses_comment.sql new file mode 100644 index 00000000..50bb9878 --- /dev/null +++ b/xchem_db/sql/0002_reviewresponses_comment.sql @@ -0,0 +1,4 @@ +-- +-- Add field comment to reviewresponses +-- +ALTER TABLE `review_responses` ADD COLUMN `comment` longtext NULL; diff --git a/xchem_db/sql/README.md b/xchem_db/sql/README.md new file mode 100644 index 00000000..e1a20a09 --- /dev/null +++ b/xchem_db/sql/README.md @@ -0,0 +1 @@ +Files for DLS diff --git a/xchem_db/tests.py b/xchem_db/tests.py deleted file mode 100644 index a39b155a..00000000 --- a/xchem_db/tests.py +++ /dev/null @@ -1 +0,0 @@ -# Create your tests here. diff --git a/xchem_db/views.py b/xchem_db/views.py deleted file mode 100644 index 724ead40..00000000 --- a/xchem_db/views.py +++ /dev/null @@ -1,312 +0,0 @@ -from rest_framework import viewsets - -from .serializers import * - - -class TargetView(viewsets.ReadOnlyModelViewSet): - """ - Target: target names - Filters: - - target_name - Returns: - - target_name - """ - queryset = Target.objects.filter() - serializer_class = TargetSerializer - filter_fields = ( - "target_name", - ) - - -class CompoundsView(viewsets.ReadOnlyModelViewSet): - """ - Compounds: smiles strings for compounds - """ - queryset = Compounds.objects.filter() - serializer_class = CompoundsSerializer - filter_fields = ( - "smiles", - ) - - -class ReferenceView(viewsets.ReadOnlyModelViewSet): - """ - Reference: reference pdb files - """ - queryset = Reference.objects.filter() - serializer_class = ReferenceSerializer - filter_fields = ( - "reference_pdb", - ) - - -class SoakdbFilesView(viewsets.ReadOnlyModelViewSet): - queryset = SoakdbFiles.objects.filter() - serializer_class = SoakdbFilesSerializer - filter_fields = ( - "filename", - "proposal__proposal", - "visit", - ) - - -class CrystalView(viewsets.ReadOnlyModelViewSet): - queryset = Crystal.objects.filter() - serializer_class = CrystalSerializer - filter_fields = ( - "crystal_name", - "target__target_name", - "compound__smiles", - "visit__filename", - "visit__proposal__proposal", - "visit__visit", - ) - - -class DataProcessingView(viewsets.ReadOnlyModelViewSet): - queryset = DataProcessing.objects.filter() - serializer_class = DataProcessingSerializer - filter_fields = ( - "crystal_name__crystal_name", - "crystal_name__target__target_name", - "crystal_name__compound__smiles", - "crystal_name__visit__filename", - "crystal_name__visit__proposal__proposal", - "crystal_name__visit__visit", - ) - - -class DimpleView(viewsets.ReadOnlyModelViewSet): - queryset = Dimple.objects.filter() - serializer_class = DimpleSerializer - filter_fields = ( - "crystal_name__crystal_name", - "crystal_name__target__target_name", - "crystal_name__compound__smiles", - "crystal_name__visit__filename", - "crystal_name__visit__proposal__proposal", - "crystal_name__visit__visit", - "reference__reference_pdb" - ) - - -class LabView(viewsets.ReadOnlyModelViewSet): - queryset = Lab.objects.filter() - serializer_class = LabSerializer - filter_fields = ( - "crystal_name__crystal_name", - "crystal_name__target__target_name", - "crystal_name__compound__smiles", - "crystal_name__visit__filename", - "crystal_name__visit__proposal__proposal", - "crystal_name__visit__visit", - "data_collection_visit", - "library_name", - "library_plate", - ) - - -class RefinementView(viewsets.ReadOnlyModelViewSet): - queryset = Refinement.objects.filter() - serializer_class = RefinementSerializer - filter_fields = ( - "crystal_name__crystal_name", - "crystal_name__target__target_name", - "crystal_name__compound__smiles", - "crystal_name__visit__filename", - "crystal_name__visit__proposal__proposal", - "crystal_name__visit__visit", - "outcome", - ) - - -class PanddaAnalysisView(viewsets.ReadOnlyModelViewSet): - queryset = PanddaAnalysis.objects.filter() - serializer_class = PanddaAnalysisSerializer - filter_fields = ( - "pandda_dir", - ) - - -class PanddaRunView(viewsets.ReadOnlyModelViewSet): - queryset = PanddaRun.objects.filter() - serializer_class = PanddaRunSerializer - filter_fields = ( - "input_dir", - "pandda_analysis__pandda_dir", - "pandda_log", - "pandda_version", - "sites_file", - "events_file", - ) - - -class PanddaSiteView(viewsets.ReadOnlyModelViewSet): - queryset = PanddaSite.objects.filter() - serializer_class = PanddaSiteSerializer - filter_fields = ( - "pandda_run__pandda_analysis__pandda_dir", - "pandda_run__pandda_log", - "pandda_run__pandda_sites_file", - "pandda_run__pandda_events_file", - "pandda_run__input_dir", - "site", - ) - - -class PanddaEventView(viewsets.ReadOnlyModelViewSet): - queryset = PanddaEvent.objects.filter() - serializer_class = PanddaEventSerializer - filter_fields = ( - "crystal__crystal_name", - "crystal__target__target_name", - "crystal__compound__smiles", - "crystal__visit__filename", - "crystal__visit__proposal__proposal", - "crystal__visit__visit", - "pandda_run__pandda_analysis__pandda_dir", - "pandda_run__pandda_log", - "pandda_run__pandda_sites_file", - "pandda_run__pandda_events_file", - "pandda_run__input_dir", - "site__site", - "event", - "lig_id", - "pandda_event_map_native", - "pandda_model_pdb", - "pandda_input_mtz", - "pandda_input_pdb", - ) - - -class FragspectCrystalView(viewsets.ReadOnlyModelViewSet): - queryset = PanddaEvent.objects.filter().prefetch_related('crystal', 'site', 'refinement', 'data_proc') - serializer_class = FragspectCrystalSerializer - filter_fields = {'crystal__target__target_name': ['iexact']} - - -class MiscFilesView(viewsets.ReadOnlyModelViewSet): - queryset = MiscFiles.objects.filter() - serializer_class = MiscFilesSerializer - filter_fields = ( - 'file', - 'description' - ) - - -class FragalysisTargetView(viewsets.ReadOnlyModelViewSet): - queryset = FragalysisTarget.objects.filter() - serializer_class = FragalysisTargetSerializer - filter_fields = ( - 'open', - 'target', - 'metadata_file', - 'input_root', - 'staging_root', - 'biomol', - 'additional_files__file', - 'additional_files__description' - ) - - -class FragalysisLigandView(viewsets.ReadOnlyModelViewSet): - queryset = FragalysisLigand.objects.filter() - serializer_class = FragalysisLigandSerializer - filter_fields = ( - 'ligand_name', - 'fragalysis_target__open', - 'fragalysis_target__target', - 'crystallographic_bound', - 'lig_mol_file', - 'apo_pdb', - 'bound_pdb', - 'smiles_file', - 'desolvated_pdb', - 'solvated_pdb', - 'pandda_event', - 'two_fofc', - 'fofc', - 'modification_date' - ) - - -class LigandView(viewsets.ReadOnlyModelViewSet): - queryset = Ligand.objects.filter() - serializer_class = LigandSerializer - filter_fields = ( - 'fragalysis_ligand__ligand_name', - 'fragalysis_ligand__fragalysis_target__open', - 'fragalysis_ligand__fragalysis_target__target', - "crystal__crystal_name", - "crystal__target__target_name", - "crystal__compound__smiles", - "crystal__visit__filename", - "crystal__visit__proposal__proposal", - "crystal__visit__visit", - 'target__target_name', - 'compound__smiles' - ) - -class ReviewResponsesView(viewsets.ReadOnlyModelViewSet): - queryset = ReviewResponses.objects.filter() - serializer_class = ReviewResponsesSerializer - filter_fields = ( - "crystal__crystal_name", - "crystal__target__target_name", - "crystal__compound__smiles", - "crystal__visit__filename", - "crystal__visit__proposal__proposal", - "crystal__visit__visit", - 'fedid', - 'decision_int', - 'decision_str', - 'reason', - 'time_submitted' - ) - -class ReviewResponses2View(viewsets.ReadOnlyModelViewSet): - queryset = ReviewResponses2.objects.filter() - serializer_class = ReviewResponses2Serializer - filter_fields = ( - "crystal__crystal_name", - "crystal__target__target_name", - "crystal__compound__smiles", - "crystal__visit__filename", - "crystal__visit__proposal__proposal", - "crystal__visit__visit", - 'Ligand_name__fragalysis_ligand__ligand_name', - 'Ligand_name__fragalysis_ligand__fragalysis_target__open', - 'Ligand_name__fragalysis_ligand__fragalysis_target__target', - 'fedid', - 'decision_int', - 'decision_str', - 'reason', - 'time' - ) - -class BadAtomsView(viewsets.ReadOnlyModelViewSet): - queryset = BadAtoms.objects.filter() - serializer_class = BadAtomsSerializer - filter_fields = ( - 'review', - 'Ligand__fragalysis_ligand__ligand_name', - 'Ligand__fragalysis_ligand__fragalysis_target__open', - 'Ligand__fragalysis_ligand__fragalysis_target__target', - 'comment' - ) - -class MetaDataView(viewsets.ReadOnlyModelViewSet): - queryset = MetaData.objects.filter() - serializer = MetaDataSerializer - filter_fields = ( - 'Ligand_name__ligand_name', - 'Ligand_name__fragalysis_target__open', - 'Ligand_name__fragalysis_target__target', - 'Site_Label', - 'new_smiles', - 'alternate_name', - 'pdb_id', - 'fragalysis_name', - 'original_name' - - ) \ No newline at end of file diff --git a/xchem_db/migrations/__init__.py b/xchem_db/xchem_db/__init__.py similarity index 100% rename from xchem_db/migrations/__init__.py rename to xchem_db/xchem_db/__init__.py diff --git a/xchem_db/xchem_db/admin.py b/xchem_db/xchem_db/admin.py new file mode 100644 index 00000000..55e9985f --- /dev/null +++ b/xchem_db/xchem_db/admin.py @@ -0,0 +1,54 @@ +from django.contrib import admin +from xchem_db.models import ( +BadAtoms, +FragalysisLigand, +MiscFiles, +PanddaSite, +ReviewResponses, +Compounds, +FragalysisTarget, +PanddaAnalysis, +PanddaStatisticalMap, +Crystal, +Lab, +PanddaEvent, +Proposals, +SoakdbFiles, +DataProcessing, +Ligand, +PanddaEventStats, +Reference, +Target, +Dimple, +MetaData, +PanddaRun, +Refinement, +SiteMapping, +ProteinSite +) + +admin.site.register(BadAtoms) +admin.site.register(FragalysisLigand) +admin.site.register(MiscFiles) +admin.site.register(PanddaSite) +admin.site.register(ReviewResponses) +admin.site.register(Compounds) +admin.site.register(FragalysisTarget) +admin.site.register(PanddaAnalysis) +admin.site.register(PanddaStatisticalMap) +admin.site.register(SiteMapping) +admin.site.register(ProteinSite) +admin.site.register(Crystal) +admin.site.register(Lab) +admin.site.register(PanddaEvent) +admin.site.register(Proposals) +admin.site.register(SoakdbFiles) +admin.site.register(DataProcessing) +admin.site.register(Ligand) +admin.site.register(PanddaEventStats) +admin.site.register(Reference) +admin.site.register(Target) +admin.site.register(Dimple) +admin.site.register(MetaData) +admin.site.register(PanddaRun) +admin.site.register(Refinement) diff --git a/xchem_db/migrations/0001_initial.py b/xchem_db/xchem_db/migrations/0001_initial.py similarity index 67% rename from xchem_db/migrations/0001_initial.py rename to xchem_db/xchem_db/migrations/0001_initial.py index b90b85b2..4a8da79f 100644 --- a/xchem_db/migrations/0001_initial.py +++ b/xchem_db/xchem_db/migrations/0001_initial.py @@ -1,8 +1,8 @@ -# Generated by Django 2.0.5 on 2020-11-27 16:10 +# Generated by Django 3.1.7 on 2021-11-10 17:47 -import django.contrib.postgres.fields from django.db import migrations, models import django.db.models.deletion +import django_mysql.models class Migration(migrations.Migration): @@ -17,10 +17,12 @@ class Migration(migrations.Migration): name='Compounds', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('smiles', models.CharField(blank=True, db_index=True, max_length=255, null=True, unique=True)), + ('smiles', models.CharField(blank=True, db_index=True, max_length=255, null=True)), + ('compound_string', models.CharField(blank=True, db_index=True, max_length=255, null=True)), ], options={ - 'db_table': 'compounds', + 'db_table': 'compound', + 'unique_together': {('smiles', 'compound_string')}, }, ), migrations.CreateModel( @@ -28,9 +30,11 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('crystal_name', models.CharField(db_index=True, max_length=255)), - ('product', models.CharField(blank=True, max_length=255, null=True)), ('status', models.CharField(choices=[('PP', 'preprocessing'), ('PD', 'pandda'), ('RE', 'refinement'), ('CC', 'comp_chem'), ('DP', 'deposition')], default='PP', max_length=2)), - ('compound', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Compounds')), + ('well', models.CharField(blank=True, max_length=4, null=True)), + ('echo_x', models.IntegerField(blank=True, null=True)), + ('echo_y', models.IntegerField(blank=True, null=True)), + ('score', models.IntegerField(blank=True, null=True)), ], options={ 'db_table': 'crystal', @@ -82,95 +86,55 @@ class Migration(migrations.Migration): ('unique_ref_overall', models.IntegerField(blank=True, null=True)), ('unit_cell', models.TextField(blank=True, null=True)), ('unit_cell_vol', models.FloatField(blank=True, null=True)), - ('crystal_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Crystal', unique=True)), + ('crystal_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.crystal', unique=True)), ], options={ 'db_table': 'data_processing', }, ), migrations.CreateModel( - name='Dimple', + name='FragalysisLigand', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('mtz_path', models.CharField(blank=True, max_length=255, null=True)), - ('pdb_path', models.CharField(blank=True, max_length=255, null=True)), - ('r_free', models.FloatField(blank=True, null=True)), - ('res_high', models.FloatField(blank=True, null=True)), - ('status', models.TextField(blank=True, null=True)), - ('crystal_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Crystal', unique=True)), + ('ligand_name', models.CharField(max_length=255)), + ('crystallographic_bound', models.FileField(max_length=500, upload_to='')), + ('lig_mol_file', models.FileField(max_length=500, upload_to='')), + ('apo_pdb', models.FileField(max_length=500, upload_to='')), + ('bound_pdb', models.FileField(max_length=500, upload_to='')), + ('smiles_file', models.FileField(max_length=500, upload_to='')), + ('desolvated_pdb', models.FileField(max_length=500, upload_to='')), + ('solvated_pdb', models.FileField(max_length=500, upload_to='')), + ('pandda_event', models.FileField(blank=True, max_length=500, upload_to='')), + ('two_fofc', models.FileField(blank=True, max_length=500, upload_to='')), + ('fofc', models.FileField(blank=True, max_length=500, upload_to='')), + ('modification_date', models.BigIntegerField()), ], options={ - 'db_table': 'dimple', + 'db_table': 'fragalysis_ligand', }, ), migrations.CreateModel( - name='Lab', + name='Ligand', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('cryo_frac', models.FloatField(blank=True, null=True)), - ('cryo_status', models.TextField(blank=True, null=True)), - ('cryo_stock_frac', models.FloatField(blank=True, null=True)), - ('cryo_transfer_vol', models.FloatField(blank=True, null=True)), - ('data_collection_visit', models.TextField(blank=True, null=True)), - ('expr_conc', models.FloatField(blank=True, null=True)), - ('harvest_status', models.TextField(blank=True, null=True)), - ('library_name', models.TextField(blank=True, null=True)), - ('library_plate', models.TextField(blank=True, null=True)), - ('mounting_result', models.TextField(blank=True, null=True)), - ('mounting_time', models.TextField(blank=True, null=True)), - ('soak_status', models.TextField(blank=True, null=True)), - ('soak_time', models.TextField(blank=True, null=True)), - ('soak_vol', models.FloatField(blank=True, null=True)), - ('solv_frac', models.FloatField(blank=True, null=True)), - ('stock_conc', models.FloatField(blank=True, null=True)), - ('visit', models.TextField(blank=True, null=True)), - ('crystal_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Crystal', unique=True)), + ('crystal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.crystal')), + ('fragalysis_ligand', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.fragalysisligand')), ], options={ - 'db_table': 'lab', + 'db_table': 'ligand', }, ), migrations.CreateModel( - name='LigandEdstats', + name='MiscFiles', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('baa', models.FloatField(blank=True, null=True)), - ('ccpa', models.FloatField(blank=True, null=True)), - ('ccsa', models.FloatField(blank=True, null=True)), - ('npa', models.FloatField(blank=True, null=True)), - ('rga', models.FloatField(blank=True, null=True)), - ('ra', models.FloatField(blank=True, null=True)), - ('srga', models.FloatField(blank=True, null=True)), - ('zccpa', models.FloatField(blank=True, null=True)), - ('zd_a', models.FloatField(blank=True, null=True)), - ('zd_a_0', models.FloatField(blank=True, null=True)), - ('zda', models.FloatField(blank=True, null=True)), - ('zoa', models.FloatField(blank=True, null=True)), - ('ligand', models.CharField(blank=True, max_length=255, null=True)), - ('crystal_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Crystal')), + ('file', models.FileField(max_length=500, upload_to='')), + ('description', models.TextField()), ], options={ - 'db_table': 'ligand_edstats', + 'db_table': 'misc_files', }, ), - migrations.CreateModel( - name='Occupancy', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('refine_log', models.TextField(blank=True, null=True)), - ('all_occupancy', django.contrib.postgres.fields.ArrayField(base_field=models.FloatField(), size=None)), - ('occupancy', models.FloatField(blank=True, null=True)), - ('occupancy_group', models.IntegerField(blank=True, null=True)), - ('complete_group', models.TextField(blank=True, null=True)), - ('resid', models.IntegerField(blank=True, null=True)), - ('alte', models.CharField(blank=True, max_length=1, null=True)), - ('state', models.CharField(blank=True, max_length=7, null=True)), - ('resname', models.CharField(blank=True, max_length=3, null=True)), - ('comment', models.TextField(blank=True, null=True)), - ('edited', models.DateTimeField(auto_now=True)), - ('added', models.DateTimeField(auto_now_add=True)), - ], - ), migrations.CreateModel( name='PanddaAnalysis', fields=[ @@ -208,69 +172,13 @@ class Migration(migrations.Migration): ('created_date', models.DateTimeField(auto_now_add=True, null=True)), ('modified_date', models.DateTimeField(auto_now=True, null=True)), ('ligand_confidence_source', models.CharField(choices=[('NA', 'none'), ('SD', 'soak_db'), ('FS', 'fragspect')], default='NA', max_length=2)), - ('crystal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Crystal')), - ('data_proc', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.DataProcessing')), + ('crystal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.crystal')), + ('data_proc', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.dataprocessing')), ], options={ 'db_table': 'pandda_event', }, ), - migrations.CreateModel( - name='PanddaEventStats', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('one_minus_bdc', models.FloatField(blank=True, null=True)), - ('cluster_size', models.IntegerField(blank=True, null=True)), - ('glob_corr_av_map', models.FloatField(blank=True, null=True)), - ('glob_corr_mean_map', models.FloatField(blank=True, null=True)), - ('loc_corr_av_map', models.FloatField(blank=True, null=True)), - ('loc_corr_mean_map', models.FloatField(blank=True, null=True)), - ('z_mean', models.FloatField(blank=True, null=True)), - ('z_peak', models.FloatField(blank=True, null=True)), - ('b_factor_scaled', models.FloatField(blank=True, null=True)), - ('high_res', models.FloatField(blank=True, null=True)), - ('low_res', models.FloatField(blank=True, null=True)), - ('r_free', models.FloatField(blank=True, null=True)), - ('r_work', models.FloatField(blank=True, null=True)), - ('ref_rmsd', models.FloatField(blank=True, null=True)), - ('wilson_scaled_b', models.FloatField(blank=True, null=True)), - ('wilson_scaled_ln_dev', models.FloatField(blank=True, null=True)), - ('wilson_scaled_ln_dev_z', models.FloatField(blank=True, null=True)), - ('wilson_scaled_ln_rmsd', models.FloatField(blank=True, null=True)), - ('wilson_scaled_ln_rmsd_z', models.FloatField(blank=True, null=True)), - ('wilson_scaled_below_four_rmsd', models.FloatField(blank=True, null=True)), - ('wilson_scaled_below_four_rmsd_z', models.FloatField(blank=True, null=True)), - ('wilson_scaled_above_four_rmsd', models.FloatField(blank=True, null=True)), - ('wilson_scaled_above_four_rmsd_z', models.FloatField(blank=True, null=True)), - ('wilson_scaled_rmsd_all', models.FloatField(blank=True, null=True)), - ('wilson_scaled_rmsd_all_z', models.FloatField(blank=True, null=True)), - ('wilson_unscaled', models.FloatField(blank=True, null=True)), - ('wilson_unscaled_ln_dev', models.FloatField(blank=True, null=True)), - ('wilson_unscaled_ln_dev_z', models.FloatField(blank=True, null=True)), - ('wilson_unscaled_ln_rmsd', models.FloatField(blank=True, null=True)), - ('wilson_unscaled_ln_rmsd_z', models.FloatField(blank=True, null=True)), - ('wilson_unscaled_below_four_rmsd', models.FloatField(blank=True, null=True)), - ('wilson_unscaled_below_four_rmsd_z', models.FloatField(blank=True, null=True)), - ('wilson_unscaled_above_four_rmsd', models.FloatField(blank=True, null=True)), - ('wilson_unscaled_above_four_rmsd_z', models.FloatField(blank=True, null=True)), - ('wilson_unscaled_rmsd_all', models.FloatField(blank=True, null=True)), - ('wilson_unscaled_rmsd_all_z', models.FloatField(blank=True, null=True)), - ('resolution', models.FloatField(blank=True, null=True)), - ('map_uncertainty', models.FloatField(blank=True, null=True)), - ('obs_map_mean', models.FloatField(blank=True, null=True)), - ('obs_map_rms', models.FloatField(blank=True, null=True)), - ('z_map_kurt', models.FloatField(blank=True, null=True)), - ('z_map_mean', models.FloatField(blank=True, null=True)), - ('z_map_skew', models.FloatField(blank=True, null=True)), - ('z_map_std', models.FloatField(blank=True, null=True)), - ('scl_map_mean', models.FloatField(blank=True, null=True)), - ('scl_map_rms', models.FloatField(blank=True, null=True)), - ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.PanddaEvent')), - ], - options={ - 'db_table': 'pandda_event_stats', - }, - ), migrations.CreateModel( name='PanddaRun', fields=[ @@ -280,139 +188,108 @@ class Migration(migrations.Migration): ('pandda_version', models.TextField(blank=True, null=True)), ('sites_file', models.TextField(blank=True, null=True)), ('events_file', models.TextField(blank=True, null=True)), - ('pandda_analysis', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.PanddaAnalysis')), + ('pandda_analysis', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.panddaanalysis')), ], options={ 'db_table': 'pandda_run', }, ), migrations.CreateModel( - name='PanddaSite', + name='Proposals', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('site', models.IntegerField(blank=True, db_index=True, null=True)), - ('site_aligned_centroid_x', models.FloatField(blank=True, null=True)), - ('site_aligned_centroid_y', models.FloatField(blank=True, null=True)), - ('site_aligned_centroid_z', models.FloatField(blank=True, null=True)), - ('site_native_centroid_x', models.FloatField(blank=True, null=True)), - ('site_native_centroid_y', models.FloatField(blank=True, null=True)), - ('site_native_centroid_z', models.FloatField(blank=True, null=True)), - ('pandda_run', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.PanddaRun')), + ('proposal', models.CharField(db_index=True, max_length=255, unique=True)), + ('title', models.CharField(blank=True, max_length=10, null=True)), + ('fedids', models.TextField(blank=True, null=True)), ], options={ - 'db_table': 'pandda_site', + 'db_table': 'proposals', }, ), migrations.CreateModel( - name='PanddaStatisticalMap', + name='ProteinSite', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('resolution_from', models.FloatField(blank=True, null=True)), - ('resolution_to', models.FloatField(blank=True, null=True)), - ('dataset_list', models.TextField()), - ('pandda_run', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.PanddaRun')), + ('site_name', models.CharField(max_length=50)), + ('site_chain', models.CharField(max_length=50)), + ('site_conformation', models.CharField(max_length=50)), + ('site_crystal_form', models.CharField(max_length=50)), + ('site_residue_names', django_mysql.models.ListTextField(models.CharField(max_length=255), size=None)), + ('site_residue_indicies', django_mysql.models.ListTextField(models.IntegerField(), size=None)), + ('creator', models.CharField(blank=True, max_length=255)), + ('fragalysis_ligand_reference', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.fragalysisligand')), ], options={ - 'db_table': 'pandda_statistical_map', + 'db_table': 'protein_sites', }, ), migrations.CreateModel( - name='ProasisHits', + name='Reference', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('pdb_file', models.TextField()), - ('modification_date', models.TextField(blank=True, null=True)), - ('strucid', models.TextField(blank=True, null=True)), - ('ligand_list', models.TextField(blank=True, null=True)), - ('mtz', models.TextField()), - ('two_fofc', models.TextField()), - ('fofc', models.TextField()), - ('sdf', models.TextField(blank=True, null=True)), - ('altconf', models.CharField(blank=True, max_length=255, null=True)), - ('added', models.DateTimeField(auto_now_add=True)), - ('crystal_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Crystal')), + ('reference_pdb', models.CharField(default='not_assigned', max_length=255, null=True, unique=True)), ], options={ - 'db_table': 'proasis_hits', + 'db_table': 'reference', }, ), migrations.CreateModel( - name='ProasisLeads', + name='Target', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('strucid', models.CharField(blank=True, max_length=255, null=True, unique=True)), + ('target_name', models.CharField(db_index=True, max_length=255, unique=True)), + ('uniprot_id', models.CharField(blank=True, max_length=255, null=True)), + ('alias', models.CharField(blank=True, max_length=255, null=True)), + ('pl_reference', models.FileField(blank=True, max_length=500, upload_to='')), + ('pl_monomeric', models.BooleanField(default=False)), + ('pl_reduce_reference_frame', models.BooleanField(default=True)), + ('pl_covalent_attachments', models.BooleanField(default=True)), + ('pl_additional_headers', models.TextField(blank=True)), + ('pl_active', models.BooleanField(default=True)), ], options={ - 'db_table': 'proasis_leads', + 'db_table': 'target', }, ), migrations.CreateModel( - name='ProasisOut', + name='SoakdbFiles', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('ligand', models.CharField(max_length=255)), - ('ligid', models.IntegerField(blank=True, null=True)), - ('root', models.TextField(blank=True, null=True)), - ('start', models.TextField(blank=True, null=True)), - ('curated', models.TextField(blank=True, null=True)), - ('sdf', models.TextField(blank=True, null=True)), - ('apo', models.TextField(blank=True, null=True)), - ('mol', models.TextField(blank=True, null=True)), - ('mol2', models.TextField(blank=True, null=True)), - ('h_mol', models.TextField(blank=True, null=True)), - ('stripped', models.TextField(blank=True, null=True)), - ('event', models.TextField(blank=True, null=True)), - ('mtz', models.TextField(blank=True, null=True)), - ('contacts', models.TextField(blank=True, null=True)), - ('acc', models.TextField(blank=True, null=True)), - ('don', models.TextField(blank=True, null=True)), - ('lip', models.TextField(blank=True, null=True)), - ('pmap', models.TextField(blank=True, null=True)), - ('ppdb', models.TextField(blank=True, null=True)), - ('pjson', models.TextField(blank=True, null=True)), - ('pmtz', models.TextField(blank=True, null=True)), - ('added', models.DateTimeField(auto_now_add=True)), - ('crystal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Crystal')), - ('proasis', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.ProasisHits')), + ('filename', models.CharField(max_length=255, unique=True)), + ('modification_date', models.BigIntegerField()), + ('visit', models.TextField()), + ('status', models.IntegerField(blank=True, null=True)), + ('proposal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.proposals')), ], options={ - 'db_table': 'proasis_out', + 'db_table': 'soakdb_files', }, ), migrations.CreateModel( - name='ProasisPandda', + name='SiteMapping', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('event_map_native', models.TextField()), - ('model_pdb', models.TextField()), - ('crystal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Crystal')), - ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.PanddaEvent')), - ('hit', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.ProasisHits')), + ('ligand', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.fragalysisligand')), + ('site', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.proteinsite')), ], options={ - 'db_table': 'proasis_pandda', + 'db_table': 'site_mapping', }, ), migrations.CreateModel( - name='Proposals', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('proposal', models.CharField(db_index=True, max_length=255, unique=True)), - ('title', models.CharField(blank=True, max_length=10, null=True)), - ('fedids', models.TextField(blank=True, null=True)), - ], - options={ - 'db_table': 'proposals', - }, - ), - migrations.CreateModel( - name='Reference', + name='ReviewResponses', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('reference_pdb', models.CharField(default='not_assigned', max_length=255, null=True, unique=True)), + ('fedid', models.TextField()), + ('decision_int', models.IntegerField()), + ('decision_str', models.TextField()), + ('reason', models.TextField()), + ('time_submitted', models.IntegerField()), + ('crystal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.crystal')), + ('ligand_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.ligand')), ], options={ - 'db_table': 'reference', + 'db_table': 'review_responses', }, ), migrations.CreateModel( @@ -444,210 +321,254 @@ class Migration(migrations.Migration): ('rmsd_bonds', models.TextField(blank=True, null=True)), ('spacegroup', models.TextField(blank=True, null=True)), ('status', models.TextField(blank=True, null=True)), + ('crystal_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.crystal', unique=True)), ], options={ 'db_table': 'refinement', }, ), migrations.CreateModel( - name='ReviewResponses', + name='PanddaSite', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('fedid', models.TextField()), - ('decision_int', models.IntegerField()), - ('decision_str', models.TextField()), - ('reason', models.TextField()), - ('time_submitted', models.IntegerField()), - ('crystal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Crystal')), + ('site', models.IntegerField(blank=True, db_index=True, null=True)), + ('site_aligned_centroid_x', models.FloatField(blank=True, null=True)), + ('site_aligned_centroid_y', models.FloatField(blank=True, null=True)), + ('site_aligned_centroid_z', models.FloatField(blank=True, null=True)), + ('site_native_centroid_x', models.FloatField(blank=True, null=True)), + ('site_native_centroid_y', models.FloatField(blank=True, null=True)), + ('site_native_centroid_z', models.FloatField(blank=True, null=True)), + ('pandda_run', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.panddarun')), ], options={ - 'db_table': 'review_responses', + 'db_table': 'pandda_site', + 'unique_together': {('pandda_run', 'site')}, }, ), migrations.CreateModel( - name='SoakdbFiles', + name='PanddaEventStats', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('filename', models.CharField(max_length=255, unique=True)), - ('modification_date', models.BigIntegerField()), - ('visit', models.TextField()), - ('status', models.IntegerField(blank=True, null=True)), - ('proposal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Proposals')), + ('one_minus_bdc', models.FloatField(blank=True, null=True)), + ('cluster_size', models.IntegerField(blank=True, null=True)), + ('glob_corr_av_map', models.FloatField(blank=True, null=True)), + ('glob_corr_mean_map', models.FloatField(blank=True, null=True)), + ('loc_corr_av_map', models.FloatField(blank=True, null=True)), + ('loc_corr_mean_map', models.FloatField(blank=True, null=True)), + ('z_mean', models.FloatField(blank=True, null=True)), + ('z_peak', models.FloatField(blank=True, null=True)), + ('b_factor_scaled', models.FloatField(blank=True, null=True)), + ('high_res', models.FloatField(blank=True, null=True)), + ('low_res', models.FloatField(blank=True, null=True)), + ('r_free', models.FloatField(blank=True, null=True)), + ('r_work', models.FloatField(blank=True, null=True)), + ('ref_rmsd', models.FloatField(blank=True, null=True)), + ('wilson_scaled_b', models.FloatField(blank=True, null=True)), + ('wilson_scaled_ln_dev', models.FloatField(blank=True, null=True)), + ('wilson_scaled_ln_dev_z', models.FloatField(blank=True, null=True)), + ('wilson_scaled_ln_rmsd', models.FloatField(blank=True, null=True)), + ('wilson_scaled_ln_rmsd_z', models.FloatField(blank=True, null=True)), + ('wilson_scaled_below_four_rmsd', models.FloatField(blank=True, null=True)), + ('wilson_scaled_below_four_rmsd_z', models.FloatField(blank=True, null=True)), + ('wilson_scaled_above_four_rmsd', models.FloatField(blank=True, null=True)), + ('wilson_scaled_above_four_rmsd_z', models.FloatField(blank=True, null=True)), + ('wilson_scaled_rmsd_all', models.FloatField(blank=True, null=True)), + ('wilson_scaled_rmsd_all_z', models.FloatField(blank=True, null=True)), + ('wilson_unscaled', models.FloatField(blank=True, null=True)), + ('wilson_unscaled_ln_dev', models.FloatField(blank=True, null=True)), + ('wilson_unscaled_ln_dev_z', models.FloatField(blank=True, null=True)), + ('wilson_unscaled_ln_rmsd', models.FloatField(blank=True, null=True)), + ('wilson_unscaled_ln_rmsd_z', models.FloatField(blank=True, null=True)), + ('wilson_unscaled_below_four_rmsd', models.FloatField(blank=True, null=True)), + ('wilson_unscaled_below_four_rmsd_z', models.FloatField(blank=True, null=True)), + ('wilson_unscaled_above_four_rmsd', models.FloatField(blank=True, null=True)), + ('wilson_unscaled_above_four_rmsd_z', models.FloatField(blank=True, null=True)), + ('wilson_unscaled_rmsd_all', models.FloatField(blank=True, null=True)), + ('wilson_unscaled_rmsd_all_z', models.FloatField(blank=True, null=True)), + ('resolution', models.FloatField(blank=True, null=True)), + ('map_uncertainty', models.FloatField(blank=True, null=True)), + ('obs_map_mean', models.FloatField(blank=True, null=True)), + ('obs_map_rms', models.FloatField(blank=True, null=True)), + ('z_map_kurt', models.FloatField(blank=True, null=True)), + ('z_map_mean', models.FloatField(blank=True, null=True)), + ('z_map_skew', models.FloatField(blank=True, null=True)), + ('z_map_std', models.FloatField(blank=True, null=True)), + ('scl_map_mean', models.FloatField(blank=True, null=True)), + ('scl_map_rms', models.FloatField(blank=True, null=True)), + ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.panddaevent')), ], options={ - 'db_table': 'soakdb_files', + 'db_table': 'pandda_event_stats', }, ), + migrations.AddField( + model_name='panddaevent', + name='pandda_run', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.panddarun'), + ), + migrations.AddField( + model_name='panddaevent', + name='refinement', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.refinement'), + ), + migrations.AddField( + model_name='panddaevent', + name='site', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.panddasite'), + ), migrations.CreateModel( - name='Target', + name='MetaData', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('target_name', models.CharField(db_index=True, max_length=255, unique=True)), + ('site_Label', models.CharField(max_length=255)), + ('new_smiles', models.TextField(blank=True)), + ('alternate_name', models.CharField(blank=True, max_length=255)), + ('pdb_id', models.CharField(blank=True, max_length=255)), + ('fragalysis_name', models.CharField(max_length=255, unique=True)), + ('original_name', models.CharField(max_length=255)), + ('status', models.CharField(blank=True, max_length=255)), + ('ligand_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.fragalysisligand')), ], options={ - 'db_table': 'target', + 'db_table': 'meta_data', }, ), + migrations.AddField( + model_name='ligand', + name='target', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.target'), + ), migrations.CreateModel( - name='Tasks', + name='Lab', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('task_name', models.CharField(db_index=True, max_length=255)), - ('uuid', models.CharField(db_index=True, max_length=37, unique=True)), + ('cryo_frac', models.FloatField(blank=True, null=True)), + ('cryo_status', models.TextField(blank=True, null=True)), + ('cryo_stock_frac', models.FloatField(blank=True, null=True)), + ('cryo_transfer_vol', models.FloatField(blank=True, null=True)), + ('data_collection_visit', models.TextField(blank=True, null=True)), + ('expr_conc', models.FloatField(blank=True, null=True)), + ('harvest_status', models.TextField(blank=True, null=True)), + ('library_name', models.TextField(blank=True, null=True)), + ('library_plate', models.TextField(blank=True, null=True)), + ('mounting_result', models.TextField(blank=True, null=True)), + ('mounting_time', models.TextField(blank=True, null=True)), + ('soak_status', models.TextField(blank=True, null=True)), + ('soak_time', models.TextField(blank=True, null=True)), + ('soak_vol', models.FloatField(blank=True, null=True)), + ('solv_frac', models.FloatField(blank=True, null=True)), + ('stock_conc', models.FloatField(blank=True, null=True)), + ('visit', models.TextField(blank=True, null=True)), + ('puck', models.CharField(blank=True, max_length=100, null=True)), + ('position', models.CharField(blank=True, max_length=100, null=True)), + ('pin_barcode', models.CharField(blank=True, max_length=100, null=True)), + ('arrival_time', models.DateTimeField(blank=True, null=True)), + ('mounted_timestamp', models.DateTimeField(blank=True, null=True)), + ('ispyb_status', models.CharField(blank=True, max_length=100, null=True)), + ('crystal_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.crystal', unique=True)), ], options={ - 'db_table': 'tasks', + 'db_table': 'lab', }, ), migrations.CreateModel( - name='ConvergenceOccupancy', - fields=[ - ('occupancy_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='xchem_db.Occupancy')), - ], - bases=('xchem_db.occupancy',), - ), - migrations.CreateModel( - name='ConvergenceRefinement', + name='FragalysisTarget', fields=[ - ('refinement_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='xchem_db.Refinement')), - ('success', models.NullBooleanField()), - ('cycles', models.IntegerField(blank=True, null=True)), - ('error', models.TextField(blank=True, null=True)), + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('target', models.CharField(max_length=255)), + ('metadata_file', models.FileField(blank=True, max_length=500, upload_to='')), + ('input_root', models.TextField()), + ('staging_root', models.TextField()), + ('reference', models.FileField(blank=True, max_length=500, upload_to='')), + ('biomol', models.FileField(blank=True, max_length=500, upload_to='')), + ('additional_files', models.ManyToManyField(to='xchem_db.MiscFiles')), ], - bases=('xchem_db.refinement',), + options={ + 'db_table': 'fragalysis_target', + }, ), - migrations.CreateModel( - name='NonSuperposedOccupancy', - fields=[ - ('occupancy_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='xchem_db.Occupancy')), - ], - bases=('xchem_db.occupancy',), + migrations.AddField( + model_name='fragalysisligand', + name='fragalysis_target', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.fragalysistarget'), ), migrations.CreateModel( - name='NonSuperposedRefinement', + name='CrystalCompoundPairs', fields=[ - ('refinement_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='xchem_db.Refinement')), + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('product_smiles', models.CharField(blank=True, max_length=255, null=True)), + ('compound', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.compounds')), + ('crystal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.crystal')), ], - bases=('xchem_db.refinement',), - ), - migrations.AlterUniqueTogether( - name='tasks', - unique_together={('task_name', 'uuid')}, - ), - migrations.AddField( - model_name='refinement', - name='crystal_name', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Crystal', unique=True), - ), - migrations.AddField( - model_name='proasisleads', - name='reference_pdb', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Reference', to_field='reference_pdb', unique=True), - ), - migrations.AddField( - model_name='proasishits', - name='refinement', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Refinement'), - ), - migrations.AddField( - model_name='panddaevent', - name='pandda_run', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.PanddaRun'), - ), - migrations.AddField( - model_name='panddaevent', - name='refinement', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Refinement'), - ), - migrations.AddField( - model_name='panddaevent', - name='site', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.PanddaSite'), - ), - migrations.AddField( - model_name='occupancy', - name='crystal', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Crystal'), - ), - migrations.AddField( - model_name='occupancy', - name='refinement', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Refinement'), - ), - migrations.AddField( - model_name='ligandedstats', - name='strucid', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.ProasisHits'), + options={ + 'db_table': 'crystal_compound_pairs', + }, ), migrations.AddField( - model_name='dimple', - name='reference', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Reference'), + model_name='crystal', + name='compound', + field=models.ManyToManyField(through='xchem_db.CrystalCompoundPairs', to='xchem_db.Compounds'), ), migrations.AddField( model_name='crystal', name='target', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.Target'), + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.target'), ), migrations.AddField( model_name='crystal', name='visit', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.SoakdbFiles'), - ), - migrations.AlterUniqueTogether( - name='proasispandda', - unique_together={('crystal', 'hit', 'event')}, + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.soakdbfiles'), ), - migrations.AlterUniqueTogether( - name='proasisout', - unique_together={('crystal', 'proasis', 'ligand', 'ligid')}, - ), - migrations.AlterUniqueTogether( - name='proasishits', - unique_together={('refinement', 'crystal_name', 'altconf')}, - ), - migrations.AlterUniqueTogether( - name='panddastatisticalmap', - unique_together={('resolution_from', 'resolution_to', 'pandda_run')}, + migrations.CreateModel( + name='BadAtoms', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('atomid', models.TextField()), + ('comment', models.TextField()), + ('atomname', models.TextField(blank=True)), + ('ligand', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.ligand')), + ], + options={ + 'db_table': 'bad_atoms', + }, ), - migrations.AlterUniqueTogether( - name='panddasite', - unique_together={('pandda_run', 'site')}, + migrations.CreateModel( + name='PanddaStatisticalMap', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('resolution_from', models.FloatField(blank=True, null=True)), + ('resolution_to', models.FloatField(blank=True, null=True)), + ('dataset_list', models.TextField()), + ('pandda_run', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.panddarun')), + ], + options={ + 'db_table': 'pandda_statistical_map', + 'unique_together': {('resolution_from', 'resolution_to', 'pandda_run')}, + }, ), migrations.AlterUniqueTogether( name='panddaevent', unique_together={('site', 'event', 'crystal', 'pandda_run')}, ), - migrations.AddField( - model_name='nonsuperposedrefinement', - name='orignal_refinement', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='xchem_db.Refinement'), - ), - migrations.AddField( - model_name='nonsuperposedoccupancy', - name='nonsuper_refinement', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='xchem_db.NonSuperposedRefinement'), - ), - migrations.AlterUniqueTogether( - name='ligandedstats', - unique_together={('crystal_name', 'ligand', 'strucid')}, - ), - migrations.AlterUniqueTogether( - name='dimple', - unique_together={('pdb_path', 'mtz_path')}, + migrations.CreateModel( + name='Dimple', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('mtz_path', models.CharField(blank=True, max_length=255, null=True)), + ('pdb_path', models.CharField(blank=True, max_length=255, null=True)), + ('r_free', models.FloatField(blank=True, null=True)), + ('res_high', models.FloatField(blank=True, null=True)), + ('status', models.TextField(blank=True, null=True)), + ('crystal_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='xchem_db.crystal', unique=True)), + ('reference', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='xchem_db.reference')), + ], + options={ + 'db_table': 'dimple', + 'unique_together': {('pdb_path', 'mtz_path')}, + }, ), migrations.AlterUniqueTogether( name='crystal', - unique_together={('crystal_name', 'visit', 'compound', 'product')}, - ), - migrations.AddField( - model_name='convergencerefinement', - name='orignal_refinement', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='xchem_db.Refinement'), - ), - migrations.AddField( - model_name='convergenceoccupancy', - name='convergence_refinement', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='xchem_db.ConvergenceRefinement'), + unique_together={('crystal_name', 'visit')}, ), ] diff --git a/xchem_db/xchem_db/migrations/0002_reviewresponses_comment.py b/xchem_db/xchem_db/migrations/0002_reviewresponses_comment.py new file mode 100644 index 00000000..2d085694 --- /dev/null +++ b/xchem_db/xchem_db/migrations/0002_reviewresponses_comment.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.7 on 2021-11-29 12:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('xchem_db', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='reviewresponses', + name='comment', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/xchem_db/xchem_db/migrations/__init__.py b/xchem_db/xchem_db/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/xchem_db/models.py b/xchem_db/xchem_db/models.py similarity index 69% rename from xchem_db/models.py rename to xchem_db/xchem_db/models.py index 3212a5ba..db86ae49 100644 --- a/xchem_db/models.py +++ b/xchem_db/xchem_db/models.py @@ -6,49 +6,38 @@ # * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table # Feel free to rename the models, but don't rename db_table values or field names. from __future__ import unicode_literals - from django.db import models -from django.contrib.postgres.fields import ArrayField - +from django_mysql.models import ListTextField import os - -class Tasks(models.Model): - task_name = models.CharField(max_length=255, blank=False, null=False, unique=False, db_index=True) - uuid = models.CharField(max_length=37, blank=False, null=False, unique=True, db_index=True) - - class Meta: - app_label = 'xchem_db' - db_table = 'tasks' - unique_together = ('task_name', 'uuid') - - class Target(models.Model): target_name = models.CharField(max_length=255, blank=False, null=False, unique=True, db_index=True) - - # uniprot_id = models.CharField(blank=True, null=True) - # alias = models.CharField(blank=True, null=True) + uniprot_id = models.CharField(max_length=255, blank=True, null=True) + alias = models.CharField(max_length=255, blank=True, null=True) + pl_reference = models.FileField(max_length=500, blank=True) + pl_monomeric = models.BooleanField(default=False) + pl_reduce_reference_frame = models.BooleanField(default=True) + pl_covalent_attachments = models.BooleanField(default=True) + pl_additional_headers = models.TextField(blank=True, null=False) + pl_active = models.BooleanField(default=True) class Meta: - app_label = 'xchem_db' db_table = 'target' class Compounds(models.Model): - smiles = models.CharField(max_length=255, blank=True, null=True, db_index=True, unique=True) + smiles = models.CharField(max_length=255, blank=True, null=True, db_index=True) + compound_string = models.CharField(max_length=255, blank=True, null=True, db_index=True) # Zcode... class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' - db_table = 'compounds' - + db_table = 'compound' + unique_together = ['smiles', 'compound_string'] class Reference(models.Model): - reference_pdb = models.CharField(max_length=255, null=True, default='not_assigned', unique=True) + reference_pdb = models.CharField( + max_length=255, null=True, default='not_assigned', unique=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'reference' @@ -59,9 +48,6 @@ class Proposals(models.Model): fedids = models.TextField(blank=True, null=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' - db_table = 'proposals' @@ -73,22 +59,19 @@ class SoakdbFiles(models.Model): status = models.IntegerField(blank=True, null=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'soakdb_files' + - + class Crystal(models.Model): crystal_name = models.CharField(max_length=255, blank=False, null=False, db_index=True) target = models.ForeignKey(Target, on_delete=models.CASCADE) - compound = models.ForeignKey(Compounds, on_delete=models.CASCADE, null=True, blank=True) + compound = models.ManyToManyField(Compounds, through='CrystalCompoundPairs') visit = models.ForeignKey(SoakdbFiles, on_delete=models.CASCADE) - product = models.CharField(max_length=255, blank=True, null=True) # model types PREPROCESSING = 'PP' PANDDA = 'PD' - PROASIS = 'PR' REFINEMENT = 'RE' COMPCHEM = 'CC' DEPOSITION = 'DP' @@ -101,13 +84,38 @@ class Crystal(models.Model): (DEPOSITION, 'deposition') ) - status = models.CharField(choices=CHOICES, max_length=2, default=PREPROCESSING) + status = models.CharField( + choices=CHOICES, max_length=2, default=PREPROCESSING) + well = models.CharField(max_length=4, blank=True, null=True) + # double-check if it shouldn't be float + echo_x = models.IntegerField(blank=True, null=True) + # double-check if it shouldn't be float + echo_y = models.IntegerField(blank=True, null=True) + score = models.IntegerField(blank=True, null=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' + unique_together = ('crystal_name', 'visit',) db_table = 'crystal' - unique_together = ('crystal_name', 'visit', 'compound', 'product') + +class CrystalCompoundPairs(models.Model): + crystal = models.ForeignKey(Crystal, on_delete=models.CASCADE) + compound = models.ForeignKey(Compounds, on_delete=models.CASCADE) + product_smiles = models.CharField(max_length=255, blank=True, null=True) # Need to find way of specifying this... + + class Meta: + db_table = 'crystal_compound_pairs' + +# TODO: think about how to actually do this +# class CompoundCombination(models.Model): +# '''for combisoaks and cocktails''' +# visit = models.ForeignKey( +# Visit, blank=True, null=True, on_delete=models.PROTECT) +# number = models.IntegerField(blank=True, null=True) +# compounds = models.ManyToManyField(SpaCompound) +# related_crystals = models.CharField(max_length=64, null=True, blank=True) +# '''if a combination is based on the result of the previous soak, +# the crystals based on which the combination is created are recorder +# as related_crystals''' class DataProcessing(models.Model): @@ -156,8 +164,6 @@ class DataProcessing(models.Model): unit_cell_vol = models.FloatField(blank=True, null=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'data_processing' @@ -168,15 +174,13 @@ class Dimple(models.Model): r_free = models.FloatField(blank=True, null=True) res_high = models.FloatField(blank=True, null=True) status = models.TextField(blank=True, null=True) - reference = models.ForeignKey(Reference, blank=True, null=True, on_delete=models.CASCADE) + reference = models.ForeignKey( + Reference, blank=True, null=True, on_delete=models.CASCADE) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'dimple' unique_together = ('pdb_path', 'mtz_path') - class Lab(models.Model): cryo_frac = models.FloatField(blank=True, null=True) cryo_status = models.TextField(blank=True, null=True) @@ -196,15 +200,21 @@ class Lab(models.Model): solv_frac = models.FloatField(blank=True, null=True) stock_conc = models.FloatField(blank=True, null=True) visit = models.TextField(blank=True, null=True) + # added - can be ignored anyway + puck = models.CharField(max_length=100, blank=True, null=True) + position = models.CharField(max_length=100, blank=True, null=True) + pin_barcode = models.CharField(max_length=100, blank=True, null=True) + arrival_time = models.DateTimeField(blank=True, null=True) + mounted_timestamp = models.DateTimeField(blank=True, null=True) + ispyb_status = models.CharField(max_length=100, blank=True, null=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'lab' class Refinement(models.Model): - bound_conf = models.CharField(max_length=255, blank=True, null=True, unique=True) + bound_conf = models.CharField( + max_length=255, blank=True, null=True, unique=True) cif = models.TextField(blank=True, null=True) cif_prog = models.TextField(blank=True, null=True) cif_status = models.TextField(blank=True, null=True) @@ -232,8 +242,6 @@ class Refinement(models.Model): status = models.TextField(blank=True, null=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'refinement' @@ -241,22 +249,19 @@ class PanddaAnalysis(models.Model): pandda_dir = models.CharField(max_length=255, unique=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'pandda_analysis' class PanddaRun(models.Model): input_dir = models.TextField(blank=True, null=True) - pandda_analysis = models.ForeignKey(PanddaAnalysis, on_delete=models.CASCADE) + pandda_analysis = models.ForeignKey( + PanddaAnalysis, on_delete=models.CASCADE) pandda_log = models.CharField(max_length=255, unique=True) pandda_version = models.TextField(blank=True, null=True) sites_file = models.TextField(blank=True, null=True) events_file = models.TextField(blank=True, null=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'pandda_run' @@ -267,8 +272,6 @@ class PanddaStatisticalMap(models.Model): pandda_run = models.ForeignKey(PanddaRun, on_delete=models.CASCADE) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'pandda_statistical_map' unique_together = ('resolution_from', 'resolution_to', 'pandda_run') @@ -284,8 +287,6 @@ class PanddaSite(models.Model): site_native_centroid_z = models.FloatField(blank=True, null=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'pandda_site' unique_together = ('pandda_run', 'site') @@ -330,11 +331,10 @@ class PanddaEvent(models.Model): (FRAGSPECT, 'fragspect') ) - ligand_confidence_source = models.CharField(choices=CHOICES, max_length=2, default=NONE) + ligand_confidence_source = models.CharField( + choices=CHOICES, max_length=2, default=NONE) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'pandda_event' unique_together = ('site', 'event', 'crystal', 'pandda_run') @@ -372,9 +372,11 @@ class PanddaEventStats(models.Model): wilson_unscaled_ln_rmsd = models.FloatField(blank=True, null=True) wilson_unscaled_ln_rmsd_z = models.FloatField(blank=True, null=True) wilson_unscaled_below_four_rmsd = models.FloatField(blank=True, null=True) - wilson_unscaled_below_four_rmsd_z = models.FloatField(blank=True, null=True) + wilson_unscaled_below_four_rmsd_z = models.FloatField( + blank=True, null=True) wilson_unscaled_above_four_rmsd = models.FloatField(blank=True, null=True) - wilson_unscaled_above_four_rmsd_z = models.FloatField(blank=True, null=True) + wilson_unscaled_above_four_rmsd_z = models.FloatField( + blank=True, null=True) wilson_unscaled_rmsd_all = models.FloatField(blank=True, null=True) wilson_unscaled_rmsd_all_z = models.FloatField(blank=True, null=True) resolution = models.FloatField(blank=True, null=True) @@ -389,8 +391,6 @@ class PanddaEventStats(models.Model): scl_map_rms = models.FloatField(blank=True, null=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'pandda_event_stats' @@ -399,29 +399,27 @@ class MiscFiles(models.Model): description = models.TextField() class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' - db_table = 'MiscFiles' + db_table = 'misc_files' + class FragalysisTarget(models.Model): - open = models.BooleanField() target = models.CharField(max_length=255) metadata_file = models.FileField(blank=True, max_length=500) input_root = models.TextField() staging_root = models.TextField() + reference = models.FileField(blank=True, max_length=500) # Should this be a crystal_fk or a text field with the name of the file in it... biomol = models.FileField(blank=True, max_length=500) additional_files = models.ManyToManyField(MiscFiles) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' - db_table = 'FragalysisTarget' + db_table = 'fragalysis_target' class FragalysisLigand(models.Model): ligand_name = models.CharField(max_length=255) - fragalysis_target = models.ForeignKey(FragalysisTarget, on_delete=models.CASCADE) + fragalysis_target = models.ForeignKey( + FragalysisTarget, on_delete=models.CASCADE) crystallographic_bound = models.FileField(max_length=500) lig_mol_file = models.FileField(max_length=500) apo_pdb = models.FileField(max_length=500) @@ -435,128 +433,79 @@ class FragalysisLigand(models.Model): modification_date = models.BigIntegerField(blank=False, null=False) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' - db_table = 'FragalysisLigand' + db_table = 'fragalysis_ligand' class Ligand(models.Model): - fragalysis_ligand = models.ForeignKey(FragalysisLigand, on_delete=models.CASCADE) + fragalysis_ligand = models.ForeignKey( + FragalysisLigand, on_delete=models.CASCADE) crystal = models.ForeignKey(Crystal, on_delete=models.CASCADE) target = models.ForeignKey(Target, on_delete=models.CASCADE) - compound = models.ForeignKey(Compounds, on_delete=models.CASCADE) + #compound = models.ForeignKey(Compounds, on_delete=models.CASCADE) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'ligand' -# Old Review class ReviewResponses(models.Model): - crystal = models.ForeignKey(Crystal, on_delete=models.CASCADE) # This may not be correctly linked in psql... + # This may not be correctly linked in psql... + crystal = models.ForeignKey(Crystal, on_delete=models.CASCADE) # may need to be changed to ligand in the end. Depends on XCR - # Ligand_name = models.ForeignKey(Ligand) + ligand_name = models.ForeignKey(Ligand, on_delete=models.CASCADE) fedid = models.TextField(blank=False, null=False) decision_int = models.IntegerField(blank=False, null=False) decision_str = models.TextField(blank=False, null=False) reason = models.TextField(blank=False, null=False) time_submitted = models.IntegerField(blank=False, null=False) + comment = models.TextField(blank=True, null=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' db_table = 'review_responses' - -# New Class as the old one is STILL IN USE! -class ReviewResponses2(models.Model): - crystal = models.ForeignKey(Crystal, on_delete=models.CASCADE) # This may not be correctly linked in psql... - # may need to be changed to ligand in the end. Depends on XCR - Ligand_name = models.ForeignKey(Ligand, on_delete=models.CASCADE) - fedid = models.TextField(blank=False, null=False) - decision_int = models.IntegerField(blank=False, null=False) - decision_str = models.TextField(blank=False, null=False) - reason = models.TextField(blank=False, null=False) - time_submitted = models.IntegerField(blank=False, null=False) - - class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' - db_table = 'review_responses_new' - - class BadAtoms(models.Model): - Review = models.ForeignKey(ReviewResponses2, on_delete=models.CASCADE) - Ligand = models.ForeignKey(Ligand, on_delete=models.CASCADE) - atomid = models.IntegerField(blank=False, null=False) - comment = models.TextField(blank=False, null=False) + #review = models.ForeignKey(ReviewResponses, on_delete=models.CASCADE) # Removing review attachment - now solely limited to the Ligands (not fragalysis ligands)? + ligand = models.ForeignKey(Ligand, on_delete=models.CASCADE) + atomid = models.TextField(blank=False, null=False) # Will be now stored as a plain "0;1;2;3" string instead of each atom being an individual row. + comment = models.TextField(blank=False, null=False) # Same thing as above + atomname = models.TextField(blank=True, null=False) # Same thing as above class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' - db_table = 'BadAtoms' + db_table = 'bad_atoms' class MetaData(models.Model): - Ligand_name = models.ForeignKey(FragalysisLigand, on_delete=models.CASCADE) - Site_Label = models.CharField(blank=False, null=False, max_length=255) + ligand_name = models.ForeignKey(FragalysisLigand, on_delete=models.CASCADE) + site_Label = models.CharField(blank=False, null=False, max_length=255) new_smiles = models.TextField(blank=True) alternate_name = models.CharField(max_length=255, blank=True) pdb_id = models.CharField(max_length=255, blank=True) fragalysis_name = models.CharField(max_length=255, unique=True) original_name = models.CharField(max_length=255) + status = models.CharField(max_length=255, blank=True) + + class Meta: + db_table = 'meta_data' + + +class ProteinSite(models.Model): + fragalysis_ligand_reference = models.ForeignKey(FragalysisLigand, on_delete=models.CASCADE) # Crystal to be aligned to + site_name = models.CharField(max_length=50, blank=False, null=False) + site_chain = models.CharField(max_length=50, blank=False, null=False) + site_conformation = models.CharField(max_length=50, blank=False, null=False) + site_crystal_form = models.CharField(max_length=50, blank=False, null=False) + site_residue_names = ListTextField(base_field=models.CharField(max_length=255, blank=False, null=False), blank=False, null=False) + site_residue_indicies = ListTextField(base_field=models.IntegerField(blank=False, null=False),blank=False, null=False) + # Not sure we really need it but might be useful. + creator = models.CharField(max_length=255, blank=True) class Meta: - if os.getcwd() != '/dls/science/groups/i04-1/software/luigi_pipeline/pipelineDEV': - app_label = 'xchem_db' - db_table = 'MetaData' - -## CHAT TO ELLIOT - DO WE NEED THESE, OR CODE? -# class Occupancy(models.Model): -# -# crystal = models.ForeignKey(Crystal, on_delete=models.CASCADE) -# refinement = models.ForeignKey(Refinement, on_delete=models.CASCADE) -# refine_log = models.TextField(blank=True, null=True) -# all_occupancy = ArrayField(models.FloatField()) -# occupancy = models.FloatField(blank=True, null=True) -# occupancy_group = models.IntegerField(blank=True, null=True) -# complete_group = models.TextField(blank=True, null=True) -# resid = models.IntegerField(blank=True, null=True) -# alte = models.CharField(max_length=1, blank=True, null=True) -# state = models.CharField(max_length=7, blank=True, null=True) -# resname = models.CharField(max_length=3, blank=True, null=True) -# comment = models.TextField(blank=True, null=True) -# edited = models.DateTimeField(auto_now=True) -# added = models.DateTimeField(auto_now_add=True) -# -# -# class ConvergenceRefinement(Refinement): -# -# """ Refinement with more cycles to convergence -# -# Notes -# ------------------------------ -# -# Inheritance -# -# https://godjango.com/blog/django-abstract-base-class-multi-table-inheritance/""" -# -# orignal_refinement = models.ForeignKey(Refinement, on_delete=models.CASCADE, related_name='+') -# success = models.NullBooleanField(null=True) -# cycles = models.IntegerField(null=True, blank=True) -# error = models.TextField(blank=True, null=True) -# -# -# class ConvergenceOccupancy(Occupancy): -# -# convergence_refinement = models.ForeignKey(ConvergenceRefinement, on_delete=models.CASCADE, related_name='+') -# -# -# class NonSuperposedRefinement(Refinement): -# -# orignal_refinement = models.ForeignKey(Refinement, on_delete=models.CASCADE, related_name='+') -# -# -# class NonSuperposedOccupancy(Occupancy): -# -# nonsuper_refinement = models.ForeignKey(NonSuperposedRefinement, on_delete=models.CASCADE, related_name='+') + db_table = 'protein_sites' + + +class SiteMapping(models.Model): + site = models.ForeignKey(ProteinSite, on_delete=models.CASCADE) # The site + # The ligand which belongs in this site + ligand = models.ForeignKey(FragalysisLigand, on_delete=models.CASCADE) + + class Meta: + db_table = 'site_mapping' + diff --git a/xchem_db/xchem_db/routers.py b/xchem_db/xchem_db/routers.py new file mode 100644 index 00000000..8de6ecb9 --- /dev/null +++ b/xchem_db/xchem_db/routers.py @@ -0,0 +1,37 @@ +class AuthRouter: + """ + A router to control all database operations on models in the + auth application. + """ + def db_for_read(self, model, **hints): + """ + Attempts to read auth models go to auth_db. + """ + if model._meta.app_label == 'xchem_db': + return 'xchem_db' + return None + + def db_for_write(self, model, **hints): + """ + Attempts to write auth models go to auth_db. + """ + if model._meta.app_label == 'xchem_db': + return 'xchem_db' + return None + + def allow_relation(self, obj1, obj2, **hints): + """ + Allow relations if a model in the auth app is involved. + """ + if obj1._meta.app_label == 'xchem_db' or \ + obj2._meta.app_label == 'xchem_db': + return True + return None + + def allow_migrate(self, db, app_label, model_name=None, **hints): + """ + Make sure the auth app only appears in the 'auth_db' + database. + """ + if app_label == 'xchem_db': + return False diff --git a/settings_docker_django.py b/xchem_db/xchem_db/settings.py similarity index 61% rename from settings_docker_django.py rename to xchem_db/xchem_db/settings.py index 9e94692b..0f00d015 100644 --- a/settings_docker_django.py +++ b/xchem_db/xchem_db/settings.py @@ -1,42 +1,38 @@ """ -Django settings for test_xchem project. +Django settings for xchem_db project. -Generated by 'django-admin startproject' using Django 2.0.4. +Generated by 'django-admin startproject' using Django 3.1.5. For more information on this file, see -https://docs.djangoproject.com/en/2.0/topics/settings/ +https://docs.djangoproject.com/en/3.1/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/2.0/ref/settings/ +https://docs.djangoproject.com/en/3.1/ref/settings/ """ +from pathlib import Path 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__))) +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'u4mgin$vk3g!q%lq4vqp(u3g9=pyy5x95cosp)+%rfh%$p#z%y' +SECRET_KEY = '7!%=0w@rmjou1bo63u81$57u8^x%snfz&*11@l&3+&&824cm5e' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] -GRAPH_MODELS = {'all_applications': True, 'group_models': True, } - -# Application definition +SILENCED_SYSTEM_CHECKS = ['django_mysql.W003'] INSTALLED_APPS = [ - 'api', - 'overview', 'xchem_db', - 'rest_framework', - 'rest_framework_swagger', + 'django_mysql', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -44,7 +40,7 @@ 'django.contrib.messages', 'django.contrib.staticfiles', 'django_extensions', -# 'django_numpy' + ] MIDDLEWARE = [ @@ -57,7 +53,7 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] -ROOT_URLCONF = 'urls' +ROOT_URLCONF = 'xchem_db.urls' TEMPLATES = [ { @@ -75,7 +71,7 @@ }, ] -WSGI_APPLICATION = 'wsgi.application' +WSGI_APPLICATION = 'xchem_db.wsgi.application' # Database @@ -83,14 +79,36 @@ DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'test_xchem', - 'USER': 'postgres', - 'PASSWORD': '', - 'HOST': 'localhost', - 'PORT': 5432, + 'ENGINE': 'mysql.connector.django', + 'NAME': 'docker', + 'USER': 'docker', + 'PASSWORD': 'docker', + "DEFAULT-CHARACTER-SET": 'utf8', + 'HOST': 'db', + 'PORT': 3306, + 'OPTIONS': { + 'autocommit': True, + 'raise_on_warnings': True, + }, } -} + } + +if os.environ.get('GITHUB_WORKFLOW'): + DATABASES = { + 'default': { + 'ENGINE': 'mysql.connector.django', + 'NAME': 'docker', + 'USER': 'docker', + 'PASSWORD': 'docker', + "DEFAULT-CHARACTER-SET": 'utf8', + 'HOST': 'localhost', + 'PORT': 3306, + 'OPTIONS': { + 'autocommit': True, + 'raise_on_warnings': True, + }, + } + } # Password validation @@ -130,3 +148,8 @@ # https://docs.djangoproject.com/en/2.0/howto/static-files/ STATIC_URL = '/static/' + +GRAPH_MODELS = { + 'all_applications': True, + 'group_models': True, +} diff --git a/xchem_db/xchem_db/urls.py b/xchem_db/xchem_db/urls.py new file mode 100644 index 00000000..06c22aa3 --- /dev/null +++ b/xchem_db/xchem_db/urls.py @@ -0,0 +1,21 @@ +"""xchem_db URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/xchem_db/xchem_db/wsgi.py b/xchem_db/xchem_db/wsgi.py new file mode 100644 index 00000000..061bf2be --- /dev/null +++ b/xchem_db/xchem_db/wsgi.py @@ -0,0 +1,7 @@ +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xchem_db.settings") + +application = get_wsgi_application() \ No newline at end of file