# Instructions for running the trRosettaX-Single standalone package.


Overview
====

This package is a part of trRosettaX-Single, a single-sequence based protein structure prediction protocol. 


Requirements
====

* [Python (>= 3.8)](https://www.python.org/downloads)
* [pytorch (>=1.10)](https://pytorch.org/)
* [einops](https://github.com/arogozhnikov/einops)
* [PyRosetta (>=3))](http://www.pyrosetta.org/dow/pyrosetta3-download) 
* [pytorch pre-trained models (available at our website)](https://yanglab.nankai.edu.cn/trRosetta/benchmark_single/)

Installation
====
1. Environment installation

	It is recommended to use conda to manage the Python dependencies, which can be installed following https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html#regular-installation.

	Once the conda is installed, a new environment can be created and activated depended on your cuda version (can be seen by `nvidia-smi` or `nvcc -V`)
	```
	# create conda environment for trRosettaX-Single
	#   If your NVIDIA driver compatible with cuda11
	conda env create -f linux.yml
	#   If not (but compatible with cuda10)
	conda env create -f linux-cu102.yml

	# acitvate the installed environment
	conda activate tRS
	```

	Before install pyRosetta, the user should obtain the PyRosetta license from (https://els2.comotion.uw.edu/product/pyrosetta).
	And the RosettaCommons conda channel (depend on the license information) can be added to the channel lists (see [RosettaCommons Conda Channel](https://www.pyrosetta.org/downloads#h.c0px19b8kvuw)).
	Then run
	```
	conda install -y pyrosetta
	```


2. Download the network weights.
	```
	wget https://yanglab.nankai.edu.cn/trRosetta/benchmark_single/model_seq.tar.bz2
	tar -jxvf model_seq.tar.bz2
	```


Usage
====

1. Predict the distance and orientations using single sequence (in FASTA format). 
  
	```
	python predict.py -i example/seq.fasta -o example/seq.npz -mdir ./model_seq
	```

	args of `predict.py`:

		> -i		  input multiple sequence alignment in A3M/FASTA format (*required*)
		> -o		  output npz file containing predicted distograms and anglegrams (*required*)
		> -mdir	      path to pretrained models (optional, default to `./model_seq`)
		> -CONT       output csv file containing predicted CB-CB contacts (optional, default not to predict)
		> -gpu	      use which gpu (optional, default to "-1", i.e., use cpu only)
			note: 
				The GPU codes used here are consistent with the information obtained by the command `nvidia-smi`.
				One should make sure that there is enough memory on the GPU card to use. 
				E.g., one can assign `--gpu 0` if he wants to use the 1st GPU card listed by `nvidia-smi`.
		> -cpu	      number of cpus to use (optional, default to 2)


2. Generate structure models using the predicted inter-residue geometries.

	```
	python trRosetta.py -NPZ example/seq.npz -FASTA example/seq.fasta -OUT example/model.pdb
	```

	args of `trRosetta.py`:

		> -NPZ		   input distograms and anglegrams (*required*,inter-residue geometry predictions)
		> -FASTA	   input query sequence (*required*,in FASTA format)
		> -OUT		   output model (*required*,in PDB format)
		> -pd		   PCUT, min probability of distance restraints (default: 0.05)
		> -m		   {0,1,2}, 0: sh+m+l, 1: (sh+m)+l, 2: (sh+m+l) (default: 2)
		> -n	       STEPS, number of minimization steps (default: 1000)
		> --orient     use orientations (default: True)
		> --no-orient
		> --fastrelax  perform FastRelax (default: True)
		> --no-fastrelax
		> --gpu 	   use which gpu for predict lDDT (optional, default to "-1", i.e., use cpu only)

	The confidence estimation for the top-predicted model is stored in the file "cscore.txt".
	The predicted local and global lDDT scores for the top-predicted model are stored in the file "model.plddt.npz".

###(optional) scripts for predictions in batch

As the energy minimization performed by pyRosetta does not support parallel-processing in single task, we provided a script to fold multiple targets in parallel via `concurrent`.

Three text files respectively storing the list of input fasta files, predicted npz files and the pdb files you want to output should be prepared first. 
Example:
```
python trRosetta_multi.py example/fa.lst example/npz.lst example/out.lst -cpu 8
```
Notes that the order of targets listed in the above 3 files should be consistent, i.e., the same line of the 3 files should correspond to the same target.
