Skip to content

Commit 862f266

Browse files
authored
Merge pull request #13 from haddocking/powerfit
Powerfit
2 parents f8c332c + 8bdc864 commit 862f266

32 files changed

+12349
-2189
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,19 @@ jobs:
4747
uses: astral-sh/setup-uv@v6
4848
- name: Install the project
4949
run: uv sync --locked --dev
50+
- name: Run type checkers
51+
run: uv run pyrefly check src tests
52+
typing-docs:
53+
name: typing-docs
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v4
57+
- name: Install uv
58+
uses: astral-sh/setup-uv@v6
59+
- name: Install the project
60+
run: uv sync --locked --group docs-type --group docs
5061
- name: Convert notebooks to Python scripts
5162
run: |
52-
uv run --group docs jupyter nbconvert --to python docs/*.ipynb
53-
sed -i 's/^get_ipython/# get_ipython/' docs/*.py
54-
uv run pyrefly check docs/*.py
55-
- name: Run type checkers
56-
run: uv run pyrefly check
63+
find docs/ -name "*.ipynb" -exec uv run --group docs-type marimo convert {} -o {}.py \;
64+
- name: Run type checkers on docs
65+
run: uv run --group docs-type pyrefly check docs/*.ipynb.py

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ venv.bak/
6868
*.swo
6969
*.orig
7070

71-
IDEAS.md
7271
/docs/session1/
7372
/docs/alphafold_files/
7473
/docs/pdb_files/
7574
/docs/density_filtered/
76-
/docs/cli.md
75+
/site
76+
/mysession/

CONTRIBUTING.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The sections below outline the steps in each case.
3737
1. add your own tests (if necessary);
3838
1. format your code with `uvx ruff format` and sort imports with `uvx ruff check --select I --fix`;
3939
1. lint your code with `uvx ruff check` (use `uvx ruff check --fix` to fix issues automatically);
40-
1. type check your code with `uv run pyrefly check`;
40+
1. type check your code with `uv run pyrefly check src tests`;
4141
1. update or expand the documentation (see [Contributing with documentation](#contributing-with-documentation) section below);
4242
1. [push](http://rogerdudler.github.io/git-guide/) your feature branch to (your fork of) the protein-detective repository on GitHub;
4343
1. create the pull request, e.g. following the instructions [here](https://help.github.com/articles/creating-a-pull-request/).
@@ -88,11 +88,9 @@ python3 -m http.server -d site
8888
[Pyrefly](https://pyrefly.org/) does not support notebooks yet, so we need to convert them to python scripts and then run pyrefly on them.
8989

9090
```shell
91-
uv run --group docs jupyter nbconvert --to python docs/*.ipynb
92-
# Comment out magic commands
93-
sed -i 's/^get_ipython/# get_ipython/' docs/*.py
94-
uv run pyrefly check docs/*.py
95-
rm docs/*.py
91+
find docs/ -name "*.ipynb" -exec uv run --group docs-type marimo convert {} -o {}.py \;
92+
uv run --group docs-type --group docs pyrefly check docs/*.ipynb.py
93+
rm docs/*.ipynb.py
9694
```
9795

9896
</details>

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ pip install git+https://github.com/haddocking/protein-detective.git
2121

2222
## Usage
2323

24+
The main entry point is the `protein-detective` command line tool which has multiple subcommands to perform actions.
25+
26+
To use programmaticly, see the [notebooks](docs/notebooks) and [API documentation](https://www.bonvinlab.org/protein-detective/autoapi/summary/).
27+
2428
### Search Uniprot for structures
2529

2630
```shell
@@ -43,7 +47,7 @@ In `./mysession` directory, you will find session.db file, which is a [DuckDB](h
4347
protein-detective retrieve ./mysession
4448
```
4549

46-
In `./mysession` directory, you will find PDB files from PDBe and AlphaFold DB.
50+
In `./mysession` directory, you will find mmCIF files from PDBe and PDB files and AlphaFold DB.
4751

4852
### To filter AlphaFold structures on confidence
4953

@@ -67,6 +71,41 @@ Make PDBe files smaller by only keeping first chain of found uniprot entry and r
6771
protein-detective prune-pdbs ./mysession
6872
```
6973

74+
### Powerfit
75+
76+
Generate the powerfit commands for the filtered and pruned structures.
77+
78+
```shell
79+
protein-detective powerfit commands ../powerfit-tutorial/ribosome-KsgA.map 13 docs/session1
80+
```
81+
This will print commands to the terminal, which you can then run in whatever way you prefer.
82+
Like just sequentially, or with [GNU parallel](https://www.gnu.org/software/parallel/) or as a [Slurm array job](https://slurm.schedmd.com/job_array.html).
83+
84+
Alternatively, you can use the `protein-detective powerfit run ...` command to run powerfit commands sequentially, which is useful for small datasets with rough options.
85+
86+
```shell
87+
88+
To print top 10 solutions to the terminal, you can use:
89+
90+
```shell
91+
protein-detective powerfit report docs/session1
92+
```
93+
94+
Outputs something like:
95+
96+
```
97+
powerfit_run_id,structure,rank,cc,fishz,relz,translation,rotation,density_filter_id,pdb_id,pdb_file,uniprot_acc
98+
10,A8MT69_pdb4e45.ent_B2A,1,0.432,0.463,10.091,227.18:242.53:211.83,0.0:1.0:1.0:0.0:0.0:1.0:1.0:0.0:0.0,,4E45,docs/session1/single_chain/A8MT69_pdb4e45.ent_B2A.pdb,A8MT69
99+
10,A8MT69_pdb4ne5.ent_B2A,1,0.423,0.452,10.053,227.18:242.53:214.9,0.0:-0.0:-0.0:-0.604:0.797:0.0:0.797:0.604:0.0,,4NE5,docs/session1/single_chain/A8MT69_pdb4ne5.ent_B2A.pdb,A8MT69
100+
...
101+
```
102+
103+
To generate model PDB files rotated/translated to PowerFit solutions, you can use:
104+
105+
```shell
106+
protein-detective powerfit fit-models docs/session1
107+
```
108+
70109
## Contributing
71110

72111
For development information and contribution guidelines, please see [CONTRIBUTING.md](CONTRIBUTING.md).

docs/cli_doc_hook.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"""MkDocs hooks for generating CLI documentation."""
2+
3+
import argparse
4+
import io
5+
import logging
6+
7+
from mkdocs.config.defaults import MkDocsConfig
8+
from mkdocs.structure.files import File, Files
9+
10+
from protein_detective.cli import make_parser
11+
12+
logger = logging.getLogger("mkdocs.plugins.argparse")
13+
14+
15+
def capture_help(parser: argparse.ArgumentParser) -> str:
16+
"""Capture the help text of an argparse parser."""
17+
with io.StringIO() as help_output:
18+
parser.print_help(help_output)
19+
return help_output.getvalue()
20+
21+
22+
def argparser_to_markdown(parser: argparse.ArgumentParser, heading="CLI Reference") -> str:
23+
prog = parser.prog
24+
25+
main_help = capture_help(parser)
26+
27+
lines = [
28+
f"# {heading}",
29+
f"Documentation for the `{prog}` script.",
30+
"```shell",
31+
f"$ {prog} --help",
32+
main_help,
33+
"```",
34+
]
35+
36+
subparsers_actions = [action for action in parser._actions if isinstance(action, argparse._SubParsersAction)]
37+
current_subparsers_action = subparsers_actions[0]
38+
39+
for sub_cmd_name, sub_cmd_parser in current_subparsers_action.choices.items():
40+
sub_cmd_help_text = capture_help(sub_cmd_parser)
41+
42+
lines.extend(
43+
[
44+
f"## {sub_cmd_name}",
45+
"```shell",
46+
f"$ {prog} {sub_cmd_name} --help",
47+
sub_cmd_help_text,
48+
"```",
49+
]
50+
)
51+
52+
# Check for sub-sub-commands
53+
sub_subparsers_actions = [
54+
action for action in sub_cmd_parser._actions if isinstance(action, argparse._SubParsersAction)
55+
]
56+
if sub_subparsers_actions:
57+
sub_current_subparsers_action = sub_subparsers_actions[0]
58+
for sub_sub_cmd_name, sub_sub_cmd_parser in sub_current_subparsers_action.choices.items():
59+
sub_sub_cmd_help_text = capture_help(sub_sub_cmd_parser)
60+
61+
lines.extend(
62+
[
63+
f"## {sub_cmd_name} {sub_sub_cmd_name}",
64+
"```shell",
65+
f"$ {prog} {sub_cmd_name} {sub_sub_cmd_name} --help",
66+
sub_sub_cmd_help_text,
67+
"```",
68+
]
69+
)
70+
71+
return "\n".join(lines)
72+
73+
74+
def generate_cli_docs() -> str:
75+
"""Generate CLI documentation markdown."""
76+
parser = make_parser()
77+
return argparser_to_markdown(parser)
78+
79+
80+
def on_files(files: Files, config: MkDocsConfig) -> Files:
81+
logger.info("Generating CLI documentation...")
82+
docs_content = generate_cli_docs()
83+
cli_md_file = File.generated(
84+
config=config,
85+
src_uri="cli.md",
86+
content=docs_content,
87+
)
88+
files.append(cli_md_file)
89+
return files

0 commit comments

Comments
 (0)