Skip to content

Commit 6278c9d

Browse files
committed
Finishes by updating rasp
1 parent dd429aa commit 6278c9d

File tree

7 files changed

+30
-294
lines changed

7 files changed

+30
-294
lines changed
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.

docs/poli-docs/_build/html/_sources/using_poli/objective_repository/RaSP.md

Lines changed: 10 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -15,118 +15,27 @@ However, your life would be easier if you run this black box objective function
1515

1616
## How to run
1717

18-
You can either run this objective function in your current environment (assuming that you have the correct dependencies installed), or you can run it in an isolated environment.
19-
20-
::::{tab-set}
21-
22-
:::{tab-item} In the `poli__rasp` environment
23-
24-
To run this black box function directly (which is useful for debugging, or when you are interested in setting breakpoints and inspecting the objects directly), we recommend you run it from inside the `poli__rasp` environment, or make sure you satisfy all its requirements.
25-
26-
To create this environment, run
27-
28-
```bash
29-
# From the root of the `poli` repository
30-
conda env create --file src/poli/objective_repository/rasp/environment.yml
31-
```
32-
33-
Follow that with
34-
35-
```
36-
conda activate poli__rasp
37-
```
38-
3918
Assuming you have [`3ned.pdb`](https://www.rcsb.org/structure/3ned) in the same directory as this script:
4019

4120
```python
4221
from pathlib import Path
22+
from poli.objective_repository import RaspBlackBox, RaspProblemFactory
4323

44-
import numpy as np
45-
46-
from poli import objective_factory
47-
48-
THIS_DIR = Path(__file__).parent.resolve()
49-
50-
if __name__ == "__main__":
51-
wildtype_pdb_paths_for_rasp = [
52-
THIS_DIR / "3ned.pdb",
53-
# You could have more if you want.
54-
]
55-
56-
f_rasp, x0, y0 = objective_factory.create(
57-
name="rasp",
58-
wildtype_pdb_path=wildtype_pdb_paths_for_rasp,
24+
wildtype_pdb_path = (
25+
Path(__file__).parent.parent / "static_files_for_tests" / "3ned.pdb"
5926
)
6027

61-
# Getting the wildtype string
62-
wildtype_string = "".join(x0[0])
63-
64-
# Mutating the first position three times:
65-
three_mutations = [
66-
"A" + wildtype_sequence[1:],
67-
"R" + wildtype_sequence[1:],
68-
"N" + wildtype_sequence[1:],
69-
]
70-
71-
# Computing the ddG for these three mutations:
72-
x = np.array([list(mutation) for mutation in three_mutations])
73-
74-
# y is approx [[0.03, -0.07, -0.28]]
75-
y = f(x)
76-
```
77-
78-
:::
28+
# Creating the black box
29+
f = RaspBlackBox(wildtype_pdb_path=[wildtype_pdb_path])
7930

80-
:::{tab-item} In isolation
81-
82-
Assuming you have [`3ned.pdb`](https://www.rcsb.org/structure/3ned) in the same directory as this script:
83-
84-
```python
85-
from pathlib import Path
86-
87-
import numpy as np
88-
89-
from poli import objective_factory
90-
91-
THIS_DIR = Path(__file__).parent.resolve()
92-
93-
if __name__ == "__main__":
94-
wildtype_pdb_paths_for_rasp = [
95-
THIS_DIR / "3ned.pdb",
96-
# You could have more if you want.
97-
]
98-
99-
f_rasp, x0, y0 = objective_factory.create(
100-
name="rasp",
101-
wildtype_pdb_path=wildtype_pdb_paths_for_rasp,
102-
)
103-
104-
# Getting the wildtype string
105-
wildtype_string = "".join(x0[0])
106-
107-
# Mutating the first position three times:
108-
three_mutations = [
109-
"A" + wildtype_sequence[1:],
110-
"R" + wildtype_sequence[1:],
111-
"N" + wildtype_sequence[1:],
112-
]
113-
114-
# Computing the ddG for these three mutations:
115-
x = np.array([list(mutation) for mutation in three_mutations])
116-
117-
# y is approx [[0.03, -0.07, -0.28]]
118-
y = f(x)
119-
```
120-
121-
```{warning}
122-
Registering the objective function in this way will create a `conda` environment called `poli__rasp` with the relevant dependencies. You can find the exact environment description in the following file: `src/poli/objective_repository/rasp/environment.yml`
31+
# Creating a problem
32+
problem = RaspProblemFactory().create(wildtype_pdb_path=[wildtype_pdb_path])
33+
f, x0 = problem.black_box, problem.x0
12334

35+
# Querying:
36+
print(f(x0))
12437
```
12538

126-
:::
127-
128-
::::
129-
13039
## Warnings
13140

13241
:::{warning}

docs/poli-docs/_build/html/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/poli-docs/_build/html/using_poli/objective_repository/RaSP.html

Lines changed: 10 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -600,105 +600,25 @@ <h2>Prerequisites<a class="headerlink" href="#prerequisites" title="Permalink to
600600
</section>
601601
<section id="how-to-run">
602602
<h2>How to run<a class="headerlink" href="#how-to-run" title="Permalink to this heading">#</a></h2>
603-
<p>You can either run this objective function in your current environment (assuming that you have the correct dependencies installed), or you can run it in an isolated environment.</p>
604-
<div class="sd-tab-set docutils">
605-
<input checked="checked" id="sd-tab-item-0" name="sd-tab-set-0" type="radio">
606-
</input><label class="sd-tab-label" for="sd-tab-item-0">
607-
In the <code class="docutils literal notranslate"><span class="pre">poli__rasp</span></code> environment</label><div class="sd-tab-content docutils">
608-
<p>To run this black box function directly (which is useful for debugging, or when you are interested in setting breakpoints and inspecting the objects directly), we recommend you run it from inside the <code class="docutils literal notranslate"><span class="pre">poli__rasp</span></code> environment, or make sure you satisfy all its requirements.</p>
609-
<p>To create this environment, run</p>
610-
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># From the root of the `poli` repository</span>
611-
conda<span class="w"> </span>env<span class="w"> </span>create<span class="w"> </span>--file<span class="w"> </span>src/poli/objective_repository/rasp/environment.yml
612-
</pre></div>
613-
</div>
614-
<p>Follow that with</p>
615-
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">conda</span> <span class="n">activate</span> <span class="n">poli__rasp</span>
616-
</pre></div>
617-
</div>
618603
<p>Assuming you have <a class="reference external" href="https://www.rcsb.org/structure/3ned"><code class="docutils literal notranslate"><span class="pre">3ned.pdb</span></code></a> in the same directory as this script:</p>
619604
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
605+
<span class="kn">from</span> <span class="nn">poli.objective_repository</span> <span class="kn">import</span> <span class="n">RaspBlackBox</span><span class="p">,</span> <span class="n">RaspProblemFactory</span>
620606

621-
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
622-
623-
<span class="kn">from</span> <span class="nn">poli</span> <span class="kn">import</span> <span class="n">objective_factory</span>
624-
625-
<span class="n">THIS_DIR</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">resolve</span><span class="p">()</span>
626-
627-
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
628-
<span class="n">wildtype_pdb_paths_for_rasp</span> <span class="o">=</span> <span class="p">[</span>
629-
<span class="n">THIS_DIR</span> <span class="o">/</span> <span class="s2">&quot;3ned.pdb&quot;</span><span class="p">,</span>
630-
<span class="c1"># You could have more if you want.</span>
631-
<span class="p">]</span>
632-
633-
<span class="n">f_rasp</span><span class="p">,</span> <span class="n">x0</span><span class="p">,</span> <span class="n">y0</span> <span class="o">=</span> <span class="n">objective_factory</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
634-
<span class="n">name</span><span class="o">=</span><span class="s2">&quot;rasp&quot;</span><span class="p">,</span>
635-
<span class="n">wildtype_pdb_path</span><span class="o">=</span><span class="n">wildtype_pdb_paths_for_rasp</span><span class="p">,</span>
607+
<span class="n">wildtype_pdb_path</span> <span class="o">=</span> <span class="p">(</span>
608+
<span class="n">Path</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">parent</span> <span class="o">/</span> <span class="s2">&quot;static_files_for_tests&quot;</span> <span class="o">/</span> <span class="s2">&quot;3ned.pdb&quot;</span>
636609
<span class="p">)</span>
637610

638-
<span class="c1"># Getting the wildtype string</span>
639-
<span class="n">wildtype_string</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">x0</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
611+
<span class="c1"># Creating the black box</span>
612+
<span class="n">f</span> <span class="o">=</span> <span class="n">RaspBlackBox</span><span class="p">(</span><span class="n">wildtype_pdb_path</span><span class="o">=</span><span class="p">[</span><span class="n">wildtype_pdb_path</span><span class="p">])</span>
640613

641-
<span class="c1"># Mutating the first position three times:</span>
642-
<span class="n">three_mutations</span> <span class="o">=</span> <span class="p">[</span>
643-
<span class="s2">&quot;A&quot;</span> <span class="o">+</span> <span class="n">wildtype_sequence</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span>
644-
<span class="s2">&quot;R&quot;</span> <span class="o">+</span> <span class="n">wildtype_sequence</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span>
645-
<span class="s2">&quot;N&quot;</span> <span class="o">+</span> <span class="n">wildtype_sequence</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span>
646-
<span class="p">]</span>
614+
<span class="c1"># Creating a problem</span>
615+
<span class="n">problem</span> <span class="o">=</span> <span class="n">RaspProblemFactory</span><span class="p">()</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">wildtype_pdb_path</span><span class="o">=</span><span class="p">[</span><span class="n">wildtype_pdb_path</span><span class="p">])</span>
616+
<span class="n">f</span><span class="p">,</span> <span class="n">x0</span> <span class="o">=</span> <span class="n">problem</span><span class="o">.</span><span class="n">black_box</span><span class="p">,</span> <span class="n">problem</span><span class="o">.</span><span class="n">x0</span>
647617

648-
<span class="c1"># Computing the ddG for these three mutations:</span>
649-
<span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">list</span><span class="p">(</span><span class="n">mutation</span><span class="p">)</span> <span class="k">for</span> <span class="n">mutation</span> <span class="ow">in</span> <span class="n">three_mutations</span><span class="p">])</span>
650-
651-
<span class="c1"># y is approx [[0.03, -0.07, -0.28]]</span>
652-
<span class="n">y</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
618+
<span class="c1"># Querying:</span>
619+
<span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x0</span><span class="p">))</span>
653620
</pre></div>
654621
</div>
655-
</div>
656-
<input id="sd-tab-item-1" name="sd-tab-set-0" type="radio">
657-
</input><label class="sd-tab-label" for="sd-tab-item-1">
658-
In isolation</label><div class="sd-tab-content docutils">
659-
<p>Assuming you have <a class="reference external" href="https://www.rcsb.org/structure/3ned"><code class="docutils literal notranslate"><span class="pre">3ned.pdb</span></code></a> in the same directory as this script:</p>
660-
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
661-
662-
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
663-
664-
<span class="kn">from</span> <span class="nn">poli</span> <span class="kn">import</span> <span class="n">objective_factory</span>
665-
666-
<span class="n">THIS_DIR</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">resolve</span><span class="p">()</span>
667-
668-
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
669-
<span class="n">wildtype_pdb_paths_for_rasp</span> <span class="o">=</span> <span class="p">[</span>
670-
<span class="n">THIS_DIR</span> <span class="o">/</span> <span class="s2">&quot;3ned.pdb&quot;</span><span class="p">,</span>
671-
<span class="c1"># You could have more if you want.</span>
672-
<span class="p">]</span>
673-
674-
<span class="n">f_rasp</span><span class="p">,</span> <span class="n">x0</span><span class="p">,</span> <span class="n">y0</span> <span class="o">=</span> <span class="n">objective_factory</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
675-
<span class="n">name</span><span class="o">=</span><span class="s2">&quot;rasp&quot;</span><span class="p">,</span>
676-
<span class="n">wildtype_pdb_path</span><span class="o">=</span><span class="n">wildtype_pdb_paths_for_rasp</span><span class="p">,</span>
677-
<span class="p">)</span>
678-
679-
<span class="c1"># Getting the wildtype string</span>
680-
<span class="n">wildtype_string</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">x0</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
681-
682-
<span class="c1"># Mutating the first position three times:</span>
683-
<span class="n">three_mutations</span> <span class="o">=</span> <span class="p">[</span>
684-
<span class="s2">&quot;A&quot;</span> <span class="o">+</span> <span class="n">wildtype_sequence</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span>
685-
<span class="s2">&quot;R&quot;</span> <span class="o">+</span> <span class="n">wildtype_sequence</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span>
686-
<span class="s2">&quot;N&quot;</span> <span class="o">+</span> <span class="n">wildtype_sequence</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span>
687-
<span class="p">]</span>
688-
689-
<span class="c1"># Computing the ddG for these three mutations:</span>
690-
<span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">list</span><span class="p">(</span><span class="n">mutation</span><span class="p">)</span> <span class="k">for</span> <span class="n">mutation</span> <span class="ow">in</span> <span class="n">three_mutations</span><span class="p">])</span>
691-
692-
<span class="c1"># y is approx [[0.03, -0.07, -0.28]]</span>
693-
<span class="n">y</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
694-
</pre></div>
695-
</div>
696-
<div class="admonition warning">
697-
<p class="admonition-title">Warning</p>
698-
<p>Registering the objective function in this way will create a <code class="docutils literal notranslate"><span class="pre">conda</span></code> environment called <code class="docutils literal notranslate"><span class="pre">poli__rasp</span></code> with the relevant dependencies. You can find the exact environment description in the following file: <code class="docutils literal notranslate"><span class="pre">src/poli/objective_repository/rasp/environment.yml</span></code></p>
699-
</div>
700-
</div>
701-
</div>
702622
</section>
703623
<section id="warnings">
704624
<h2>Warnings<a class="headerlink" href="#warnings" title="Permalink to this heading">#</a></h2>

docs/poli-docs/using_poli/objective_repository/RaSP.md

Lines changed: 9 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -15,118 +15,25 @@ However, your life would be easier if you run this black box objective function
1515

1616
## How to run
1717

18-
You can either run this objective function in your current environment (assuming that you have the correct dependencies installed), or you can run it in an isolated environment.
19-
20-
::::{tab-set}
21-
22-
:::{tab-item} In the `poli__rasp` environment
23-
24-
To run this black box function directly (which is useful for debugging, or when you are interested in setting breakpoints and inspecting the objects directly), we recommend you run it from inside the `poli__rasp` environment, or make sure you satisfy all its requirements.
25-
26-
To create this environment, run
27-
28-
```bash
29-
# From the root of the `poli` repository
30-
conda env create --file src/poli/objective_repository/rasp/environment.yml
31-
```
32-
33-
Follow that with
34-
35-
```
36-
conda activate poli__rasp
37-
```
38-
39-
Assuming you have [`3ned.pdb`](https://www.rcsb.org/structure/3ned) in the same directory as this script:
40-
41-
```python
42-
from pathlib import Path
43-
44-
import numpy as np
45-
46-
from poli import objective_factory
47-
48-
THIS_DIR = Path(__file__).parent.resolve()
49-
50-
if __name__ == "__main__":
51-
wildtype_pdb_paths_for_rasp = [
52-
THIS_DIR / "3ned.pdb",
53-
# You could have more if you want.
54-
]
55-
56-
f_rasp, x0, y0 = objective_factory.create(
57-
name="rasp",
58-
wildtype_pdb_path=wildtype_pdb_paths_for_rasp,
59-
)
60-
61-
# Getting the wildtype string
62-
wildtype_string = "".join(x0[0])
63-
64-
# Mutating the first position three times:
65-
three_mutations = [
66-
"A" + wildtype_sequence[1:],
67-
"R" + wildtype_sequence[1:],
68-
"N" + wildtype_sequence[1:],
69-
]
70-
71-
# Computing the ddG for these three mutations:
72-
x = np.array([list(mutation) for mutation in three_mutations])
73-
74-
# y is approx [[0.03, -0.07, -0.28]]
75-
y = f(x)
76-
```
77-
78-
:::
79-
80-
:::{tab-item} In isolation
81-
8218
Assuming you have [`3ned.pdb`](https://www.rcsb.org/structure/3ned) in the same directory as this script:
8319

8420
```python
8521
from pathlib import Path
22+
from poli.objective_repository import RaspBlackBox, RaspProblemFactory
8623

87-
import numpy as np
88-
89-
from poli import objective_factory
24+
wildtype_pdb_path = Path(__file__).parent / "3ned.pdb"
9025

91-
THIS_DIR = Path(__file__).parent.resolve()
26+
# Creating the black box
27+
f = RaspBlackBox(wildtype_pdb_path=[wildtype_pdb_path])
9228

93-
if __name__ == "__main__":
94-
wildtype_pdb_paths_for_rasp = [
95-
THIS_DIR / "3ned.pdb",
96-
# You could have more if you want.
97-
]
29+
# Creating a problem
30+
problem = RaspProblemFactory().create(wildtype_pdb_path=[wildtype_pdb_path])
31+
f, x0 = problem.black_box, problem.x0
9832

99-
f_rasp, x0, y0 = objective_factory.create(
100-
name="rasp",
101-
wildtype_pdb_path=wildtype_pdb_paths_for_rasp,
102-
)
103-
104-
# Getting the wildtype string
105-
wildtype_string = "".join(x0[0])
106-
107-
# Mutating the first position three times:
108-
three_mutations = [
109-
"A" + wildtype_sequence[1:],
110-
"R" + wildtype_sequence[1:],
111-
"N" + wildtype_sequence[1:],
112-
]
113-
114-
# Computing the ddG for these three mutations:
115-
x = np.array([list(mutation) for mutation in three_mutations])
116-
117-
# y is approx [[0.03, -0.07, -0.28]]
118-
y = f(x)
33+
# Querying:
34+
print(f(x0))
11935
```
12036

121-
```{warning}
122-
Registering the objective function in this way will create a `conda` environment called `poli__rasp` with the relevant dependencies. You can find the exact environment description in the following file: `src/poli/objective_repository/rasp/environment.yml`
123-
124-
```
125-
126-
:::
127-
128-
::::
129-
13037
## Warnings
13138

13239
:::{warning}

0 commit comments

Comments
 (0)