# Homology Modeling

The pipeline creates homology models using the alignment generated by [HHpred](https://toolkit.tuebingen.mpg.de/tools/hhpred) and uses [MODELLER](https://salilab.org/modeller/) to generate the models.


## Contents

`input_data` contains the PDB files, FASTA files, alignment files (using [HHPRED](https://www.google.com/search?q=hhpred)) for [MODELLER](https://www.google.com/search?q=modeller). `output_data` contains the MODELLER Alignement files (`modeller_alignment_files`), MODELLER logs (`modeller_run_logs`) and the final homology models (`models_selected`) used in the main modeling runs (and PKP2 models that are not used).

The main set of commands needed to reproduce the whole pipeline is documented in the `script_debug.bat` file followed by the `post_processing.bat` file (for Windows; the individual commands can be sequentially run on Linux too. Alternatively, one can change the `.bat` file to `.sh` with an appropriate header and remove all comments as well as change the line endings from CRLF to LF).

The `log` files (`stdout` from the script) and summary of the MODELLER models (`model_summary.txt`) from the runs are kept in the run-specific folders in `output_data/modeller_run_logs` but all the generated models are not kept here due to size constraints. The final selected models used for IMP are to be found in the `output_data/models_selected` (PKP2 models are not used).

The query sequences for all HHpred searches are the full uniprot sequences of the respective molecules.

## Scripts

The code is commented at most places to explain the working. Here is a short summary:

1. `hhr_extract_alignment`: Input a `.hhr` file (output of an HHpred run) and an appropriate PDB (required to know what residues have structure available) and it outputs a MODELLER-ready alignment file. Internally imports from the file `hhr_reader_modified`.  Currently has `hetatm=True`
2. `pdb_info_extract`: Input a PDB and outputs data on the residues corresponding to SEQRES and ATOM records (along with missing residues) -> provides only a summary, not directly used.
3. `collate_alignments`: Join different MODELLER-ready sequences from different `.ali` files into a single `.ali` file as chains to model with a multi-chain PDB template
4. `run_modeller_automodel`, `run_modeller_automodel_selective`, `run_modeller_loopmodel`: variants of running MODELLER with different run parameters
5. `pdb_postprocessing`: Add a chain name to a modeller outputted PDB and allow for selectively (chain-wise/residue wise) adding an offset to the residue numbering to match the FASTA sequence. Also deletes >n residue long contiguous sequences of the model not having a corresponding template structure to create gaps in the PDB allowing for IMP to use Beads for these sections.

**NOTE**: Since PG has been modelled on 3IFQ_A/B using the PDB SEQRES records instead of the FASTA sequence directly, the resultant MODELLER-outputted PDB (`pg-x-pg-x.pdb`) contains contiguously numbered segments where there are missing residues in the PDB. The final few commands of the `post_processing.bat` fix this such that the `pg-x-pg-x_modified.pdb` contains the correct numbering of residues for all the chains.

All the remaining scripts are auxiliary/helper scripts and not directly used in the pipeline (see in-file comments for their functions)

## Model selection

Based on the models outputted by MODELLER for each template-target case, the best performing model (based on `normalized DOPE` score; see the last section in the MODELLER run logs for the best performing model) is selected and tranferred to the `output_data/models_selected` and named according to the protein/complex without any additional name-tags. The script file `post_processing.bat` is then run to get the final models with a valid chain name and appropriate residue-offsets and long unmodeled contiguous segments removed (with the `_modified` suffix in the name)