eqc-bio 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. eqc_bio-0.1.2/LICENSE.txt +202 -0
  2. eqc_bio-0.1.2/PKG-INFO +143 -0
  3. eqc_bio-0.1.2/README.md +117 -0
  4. eqc_bio-0.1.2/eqc_bio/protein_design/__init__.py +30 -0
  5. eqc_bio-0.1.2/eqc_bio/protein_design/base.py +168 -0
  6. eqc_bio-0.1.2/eqc_bio/protein_design/fixed_backbone.py +723 -0
  7. eqc_bio-0.1.2/eqc_bio/protein_design/rotamers.py +337 -0
  8. eqc_bio-0.1.2/eqc_bio/protein_design/sidechains.py +207 -0
  9. eqc_bio-0.1.2/eqc_bio/protein_design/viewer.py +281 -0
  10. eqc_bio-0.1.2/eqc_bio/radiotherapy/__init__.py +1 -0
  11. eqc_bio-0.1.2/eqc_bio/radiotherapy/proton_beam.py +638 -0
  12. eqc_bio-0.1.2/eqc_bio/utils/__init__.py +3 -0
  13. eqc_bio-0.1.2/eqc_bio/utils/general.py +23 -0
  14. eqc_bio-0.1.2/eqc_bio/utils/graph.py +41 -0
  15. eqc_bio-0.1.2/eqc_bio.egg-info/PKG-INFO +143 -0
  16. eqc_bio-0.1.2/eqc_bio.egg-info/SOURCES.txt +27 -0
  17. eqc_bio-0.1.2/eqc_bio.egg-info/dependency_links.txt +1 -0
  18. eqc_bio-0.1.2/eqc_bio.egg-info/requires.txt +15 -0
  19. eqc_bio-0.1.2/eqc_bio.egg-info/scm_file_list.json +24 -0
  20. eqc_bio-0.1.2/eqc_bio.egg-info/scm_version.json +8 -0
  21. eqc_bio-0.1.2/eqc_bio.egg-info/top_level.txt +1 -0
  22. eqc_bio-0.1.2/pyproject.toml +63 -0
  23. eqc_bio-0.1.2/scripts/config_files/config_file_1MJC.yml +23 -0
  24. eqc_bio-0.1.2/scripts/data/1MJC/1MJC.matrix.28p.17aa.usingEref.txt +102310 -0
  25. eqc_bio-0.1.2/scripts/data/1MJC/1MJC.pdb +853 -0
  26. eqc_bio-0.1.2/scripts/data/1MJC/optimal_solution.csv +29 -0
  27. eqc_bio-0.1.2/scripts/protein_design_expected_pdb.py +21 -0
  28. eqc_bio-0.1.2/scripts/protein_design_fixed_backbone.py +39 -0
  29. eqc_bio-0.1.2/setup.cfg +4 -0
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2021 Quantum Computing, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
eqc_bio-0.1.2/PKG-INFO ADDED
@@ -0,0 +1,143 @@
1
+ Metadata-Version: 2.4
2
+ Name: eqc-bio
3
+ Version: 0.1.2
4
+ Summary: Biological modeling package targeting EQC devices
5
+ Author-email: "Quantum Computing Inc." <support@quantumcomputinginc.com>
6
+ Project-URL: Homepage, https://quantumcomputinginc.com
7
+ Project-URL: Documentation, https://quantumcomputinginc.com/learn/support/software-packages/
8
+ Project-URL: Issues, https://support.quantumcomputinginc.com/
9
+ Requires-Python: <3.14,>=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE.txt
12
+ Requires-Dist: numpy<3,>=1.22.1
13
+ Requires-Dist: networkx<3,>=2.6.3
14
+ Requires-Dist: pandas<3,>=2.1.0
15
+ Requires-Dist: eqc-models>=0.22.2
16
+ Requires-Dist: pyyaml<7,>=6.0
17
+ Requires-Dist: pymetis>=2023.1
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest<8,>=7.1.0; extra == "dev"
20
+ Requires-Dist: pytest-cov; extra == "dev"
21
+ Requires-Dist: sphinx_rtd_theme<2,>=1.3.0; extra == "dev"
22
+ Provides-Extra: viewer
23
+ Requires-Dist: py3Dmol<3,>=2.0; extra == "viewer"
24
+ Requires-Dist: nglview<5,>=3.0; extra == "viewer"
25
+ Dynamic: license-file
26
+
27
+ # eqc_bio.protein_design
28
+
29
+ The `eqc_bio.protein_design` module provides tools for fixed-backbone protein design using quantum-inspired optimization on Dirac-3 solvers.
30
+
31
+ ## Overview
32
+
33
+ Fixed-backbone protein design (also known as rotamer optimization or side-chain packing) involves selecting optimal side-chain conformations (rotamers) for a given protein backbone structure to minimize the total energy of the system. The `eqc_bio.protein_design` package formulates this combinatorial problem as a quadratic binary optimization (QUBO) model that can be solved efficiently using Quantum Computing Inc.'s Dirac-3 solvers.
34
+
35
+ ## Key Components
36
+
37
+ ### ProteinDesignFixed
38
+
39
+ The main class `ProteinDesignFixed` (in `fixed_backbone.py`) handles:
40
+ - Loading problem configurations from YAML files
41
+ - Reading precomputed energy matrices (interaction energies between rotamers)
42
+ - Constructing the QUBO Hamiltonian with linear and quadratic terms
43
+ - Running optimization on Dirac-3 (cloud or direct) solvers
44
+ - Iterative batch solving for larger problems using METIS graph partitioning
45
+ - Post-processing solutions into rotamer selections and PDB structures
46
+
47
+ Configuration parameters include:
48
+ - `n_samples`, relaxation schedule, photon number, quantum fluctuation coefficient
49
+ - Energy thresholds and scaling factors (alpha, beta)
50
+ - Support for integer vs. continuous variables and iterative refinement
51
+
52
+ ### Supporting Modules
53
+
54
+ - `base.py`: Core `ProteinDesign` class with Dirac-3 execution logic and iterative batching
55
+ - `rotamers.py`: Rotamer library handling (Dunbrack, OSPREY formats), chi angle extraction, library parsing and validation
56
+ - `sidechains.py`: Side-chain heavy-atom construction from χ angles using ideal geometry
57
+ - `viewer.py`: PDB building (`build_designed_pdb`), visualization (`view_pdb`), backbone dihedrals and rotamer angle utilities
58
+
59
+ ## Usage
60
+
61
+ Typical workflow:
62
+ 1. Prepare a config YAML pointing to an energy matrix CSV and expected solution
63
+ 2. Instantiate `ProteinDesignFixed(config_file, solver)`
64
+ 3. Call `run()` to solve and obtain design DataFrame
65
+ 4. Use `get_rotamer_angles()` and `build_pdb()` to generate output structures
66
+
67
+ Example scripts are provided in `scripts/protein_design_fixed_backbone.py` and `scripts/protein_design_expected_pdb.py`.
68
+
69
+ ## Building and Viewing Designed Structures
70
+
71
+ A solution assigns a rotamer such as `MET-3` (the third MET rotamer) to each designed position. The structure tools turn that into a PDB in three steps:
72
+
73
+ 1. **Rotamer angles**: look up the χ angles of each selected rotamer in the rotamer library the energy matrix was generated with.
74
+ 2. **PDB building**: keep the template's backbone atoms (N, CA, C, O, OXT) at each designed position, rename the residue, and build its side-chain heavy atoms from the χ angles. Other residues are copied unchanged.
75
+ 3. **Viewing**: show the PDB in Jupyter with py3Dmol or nglview.
76
+
77
+ ### Configuration
78
+
79
+ The structure tools read these optional keys from the config YAML:
80
+
81
+ ```yaml
82
+ template_pdb: data/1MJC/1MJC.pdb # backbone the energy matrix was built on
83
+ rotamer_library: null # null = OSPREY Lovell default, or a path to a library file
84
+ rotamer_library_format: osprey # osprey (OSPREY .dat, e.g. Lovell) or dunbrack (Dunbrack bbdep file)
85
+ position_numbering: index # index (1-based residue order in the file) or resseq (PDB residue number)
86
+ ```
87
+
88
+ - `template_pdb` is needed to build or view a PDB, and also for a Dunbrack library.
89
+ - `rotamer_library` must be the library the energy matrix was generated with, because rotamer numbers index into it. The rotamer names in the matrix are checked against the library's rotamer counts. A name that exceeds the library's count raises an error, and a residue type that uses fewer rotamers than the library has gives a warning.
90
+ - `position_numbering: index` matches how OSPREY energy matrices number positions. Use `resseq` when positions are PDB residue numbers.
91
+
92
+ ### Rotamer Libraries
93
+
94
+ - **Lovell (default)**: the Lovell "Penultimate" library as distributed with OSPREY (`LovellRotamer.dat`). It is downloaded from a pinned OSPREY commit on first use and cached in `~/.eqc_bio/rotamers` (set `EQC_BIO_CACHE` to use another directory).
95
+ - **Dunbrack (backbone-dependent)**: set `rotamer_library_format: dunbrack` and give a local copy of the Dunbrack bbdep file by path, since the library is not redistributable. It is read the way OSPREY reads it (10° φ/ψ bins, 0.001 probability cutoff, no PRO rotamers), so rotamer numbers match OSPREY matrices. Each position's φ/ψ is measured from `template_pdb`. The energy matrix must use position-prefixed rotamer names such as `4-MET-3`.
96
+
97
+ ### With ProteinDesignFixed
98
+
99
+ ```python
100
+ from eqc_bio.protein_design import ProteinDesignFixed
101
+
102
+ obj = ProteinDesignFixed(config_file="config_files/config_file_1MJC.yml", solver=solver)
103
+ obj.run()
104
+
105
+ angles = obj.get_rotamer_angles() # position, residue, rotamer, chi_angles
106
+ pdb_str = obj.build_pdb(output_path="output/designed_1MJC.pdb")
107
+ obj.view() # in Jupyter; designed side chains drawn as sticks
108
+ ```
109
+
110
+ Each method uses the design from the last `run()`, or a design DataFrame (columns `position` and `selected_rotamer`) passed as `design_df`. `load_expected_design()` returns the expected solution in that form, so its structure can be built without running a solver:
111
+
112
+ ```bash
113
+ cd scripts
114
+ python protein_design_expected_pdb.py config_files/config_file_1MJC.yml # writes output/expected_1MJC.pdb
115
+ ```
116
+
117
+ `view(viewer="nglview")` uses nglview instead of py3Dmol. Neither viewer is a required dependency. Install both with the `viewer` extra (`pip install "eqc-bio[viewer]"`), or install the one you need (`pip install py3Dmol` or `pip install nglview`).
118
+
119
+ ### Standalone Functions
120
+
121
+ The same steps are available as functions that take plain data, so angles or structures from other sources can be used at any step:
122
+
123
+ ```python
124
+ from eqc_bio.protein_design import get_rotamer_angles, build_designed_pdb, view_pdb
125
+
126
+ angles = get_rotamer_angles(design_df) # default Lovell library
127
+ pdb_str = build_designed_pdb("data/1MJC/1MJC.pdb", angles, output_path="out.pdb")
128
+ view_pdb(pdb_str, highlight=[4, 6]) # PDB residue numbers to draw as sticks
129
+ ```
130
+
131
+ - `get_rotamer_angles(design, rotamer_library=None, template_pdb=None, position_numbering="index", library_format="osprey")`: χ angles for each selected rotamer. A Dunbrack library also needs `template_pdb`.
132
+ - `build_designed_pdb(template_pdb, rotamer_angles, output_path=None, position_numbering="index")`: returns the PDB as a string and writes it if `output_path` is given. A position missing from the template raises `ValueError`.
133
+ - `view_pdb(pdb_str, viewer="py3Dmol", highlight=None)`: returns a py3Dmol or nglview widget.
134
+ - `get_backbone_dihedrals(template_pdb, position_numbering="index")`: `{position: (phi, psi)}` in degrees, with NaN where an atom is missing, such as at chain ends.
135
+ - `resolve_rotamer_library`, `load_rotamer_library`, `download_rotamer_library`, `parse_dunbrack_library`, `check_rotamer_counts` and `get_chi_angles` give lower-level access to the rotamer libraries.
136
+
137
+ ## Applications
138
+
139
+ - Computational protein engineering
140
+ - Designing stable mutants or novel sequences on fixed backbones
141
+ - Benchmarking quantum-inspired solvers on NP-hard bioinformatics problems
142
+
143
+ (C) Quantum Computing Inc., 2026.
@@ -0,0 +1,117 @@
1
+ # eqc_bio.protein_design
2
+
3
+ The `eqc_bio.protein_design` module provides tools for fixed-backbone protein design using quantum-inspired optimization on Dirac-3 solvers.
4
+
5
+ ## Overview
6
+
7
+ Fixed-backbone protein design (also known as rotamer optimization or side-chain packing) involves selecting optimal side-chain conformations (rotamers) for a given protein backbone structure to minimize the total energy of the system. The `eqc_bio.protein_design` package formulates this combinatorial problem as a quadratic binary optimization (QUBO) model that can be solved efficiently using Quantum Computing Inc.'s Dirac-3 solvers.
8
+
9
+ ## Key Components
10
+
11
+ ### ProteinDesignFixed
12
+
13
+ The main class `ProteinDesignFixed` (in `fixed_backbone.py`) handles:
14
+ - Loading problem configurations from YAML files
15
+ - Reading precomputed energy matrices (interaction energies between rotamers)
16
+ - Constructing the QUBO Hamiltonian with linear and quadratic terms
17
+ - Running optimization on Dirac-3 (cloud or direct) solvers
18
+ - Iterative batch solving for larger problems using METIS graph partitioning
19
+ - Post-processing solutions into rotamer selections and PDB structures
20
+
21
+ Configuration parameters include:
22
+ - `n_samples`, relaxation schedule, photon number, quantum fluctuation coefficient
23
+ - Energy thresholds and scaling factors (alpha, beta)
24
+ - Support for integer vs. continuous variables and iterative refinement
25
+
26
+ ### Supporting Modules
27
+
28
+ - `base.py`: Core `ProteinDesign` class with Dirac-3 execution logic and iterative batching
29
+ - `rotamers.py`: Rotamer library handling (Dunbrack, OSPREY formats), chi angle extraction, library parsing and validation
30
+ - `sidechains.py`: Side-chain heavy-atom construction from χ angles using ideal geometry
31
+ - `viewer.py`: PDB building (`build_designed_pdb`), visualization (`view_pdb`), backbone dihedrals and rotamer angle utilities
32
+
33
+ ## Usage
34
+
35
+ Typical workflow:
36
+ 1. Prepare a config YAML pointing to an energy matrix CSV and expected solution
37
+ 2. Instantiate `ProteinDesignFixed(config_file, solver)`
38
+ 3. Call `run()` to solve and obtain design DataFrame
39
+ 4. Use `get_rotamer_angles()` and `build_pdb()` to generate output structures
40
+
41
+ Example scripts are provided in `scripts/protein_design_fixed_backbone.py` and `scripts/protein_design_expected_pdb.py`.
42
+
43
+ ## Building and Viewing Designed Structures
44
+
45
+ A solution assigns a rotamer such as `MET-3` (the third MET rotamer) to each designed position. The structure tools turn that into a PDB in three steps:
46
+
47
+ 1. **Rotamer angles**: look up the χ angles of each selected rotamer in the rotamer library the energy matrix was generated with.
48
+ 2. **PDB building**: keep the template's backbone atoms (N, CA, C, O, OXT) at each designed position, rename the residue, and build its side-chain heavy atoms from the χ angles. Other residues are copied unchanged.
49
+ 3. **Viewing**: show the PDB in Jupyter with py3Dmol or nglview.
50
+
51
+ ### Configuration
52
+
53
+ The structure tools read these optional keys from the config YAML:
54
+
55
+ ```yaml
56
+ template_pdb: data/1MJC/1MJC.pdb # backbone the energy matrix was built on
57
+ rotamer_library: null # null = OSPREY Lovell default, or a path to a library file
58
+ rotamer_library_format: osprey # osprey (OSPREY .dat, e.g. Lovell) or dunbrack (Dunbrack bbdep file)
59
+ position_numbering: index # index (1-based residue order in the file) or resseq (PDB residue number)
60
+ ```
61
+
62
+ - `template_pdb` is needed to build or view a PDB, and also for a Dunbrack library.
63
+ - `rotamer_library` must be the library the energy matrix was generated with, because rotamer numbers index into it. The rotamer names in the matrix are checked against the library's rotamer counts. A name that exceeds the library's count raises an error, and a residue type that uses fewer rotamers than the library has gives a warning.
64
+ - `position_numbering: index` matches how OSPREY energy matrices number positions. Use `resseq` when positions are PDB residue numbers.
65
+
66
+ ### Rotamer Libraries
67
+
68
+ - **Lovell (default)**: the Lovell "Penultimate" library as distributed with OSPREY (`LovellRotamer.dat`). It is downloaded from a pinned OSPREY commit on first use and cached in `~/.eqc_bio/rotamers` (set `EQC_BIO_CACHE` to use another directory).
69
+ - **Dunbrack (backbone-dependent)**: set `rotamer_library_format: dunbrack` and give a local copy of the Dunbrack bbdep file by path, since the library is not redistributable. It is read the way OSPREY reads it (10° φ/ψ bins, 0.001 probability cutoff, no PRO rotamers), so rotamer numbers match OSPREY matrices. Each position's φ/ψ is measured from `template_pdb`. The energy matrix must use position-prefixed rotamer names such as `4-MET-3`.
70
+
71
+ ### With ProteinDesignFixed
72
+
73
+ ```python
74
+ from eqc_bio.protein_design import ProteinDesignFixed
75
+
76
+ obj = ProteinDesignFixed(config_file="config_files/config_file_1MJC.yml", solver=solver)
77
+ obj.run()
78
+
79
+ angles = obj.get_rotamer_angles() # position, residue, rotamer, chi_angles
80
+ pdb_str = obj.build_pdb(output_path="output/designed_1MJC.pdb")
81
+ obj.view() # in Jupyter; designed side chains drawn as sticks
82
+ ```
83
+
84
+ Each method uses the design from the last `run()`, or a design DataFrame (columns `position` and `selected_rotamer`) passed as `design_df`. `load_expected_design()` returns the expected solution in that form, so its structure can be built without running a solver:
85
+
86
+ ```bash
87
+ cd scripts
88
+ python protein_design_expected_pdb.py config_files/config_file_1MJC.yml # writes output/expected_1MJC.pdb
89
+ ```
90
+
91
+ `view(viewer="nglview")` uses nglview instead of py3Dmol. Neither viewer is a required dependency. Install both with the `viewer` extra (`pip install "eqc-bio[viewer]"`), or install the one you need (`pip install py3Dmol` or `pip install nglview`).
92
+
93
+ ### Standalone Functions
94
+
95
+ The same steps are available as functions that take plain data, so angles or structures from other sources can be used at any step:
96
+
97
+ ```python
98
+ from eqc_bio.protein_design import get_rotamer_angles, build_designed_pdb, view_pdb
99
+
100
+ angles = get_rotamer_angles(design_df) # default Lovell library
101
+ pdb_str = build_designed_pdb("data/1MJC/1MJC.pdb", angles, output_path="out.pdb")
102
+ view_pdb(pdb_str, highlight=[4, 6]) # PDB residue numbers to draw as sticks
103
+ ```
104
+
105
+ - `get_rotamer_angles(design, rotamer_library=None, template_pdb=None, position_numbering="index", library_format="osprey")`: χ angles for each selected rotamer. A Dunbrack library also needs `template_pdb`.
106
+ - `build_designed_pdb(template_pdb, rotamer_angles, output_path=None, position_numbering="index")`: returns the PDB as a string and writes it if `output_path` is given. A position missing from the template raises `ValueError`.
107
+ - `view_pdb(pdb_str, viewer="py3Dmol", highlight=None)`: returns a py3Dmol or nglview widget.
108
+ - `get_backbone_dihedrals(template_pdb, position_numbering="index")`: `{position: (phi, psi)}` in degrees, with NaN where an atom is missing, such as at chain ends.
109
+ - `resolve_rotamer_library`, `load_rotamer_library`, `download_rotamer_library`, `parse_dunbrack_library`, `check_rotamer_counts` and `get_chi_angles` give lower-level access to the rotamer libraries.
110
+
111
+ ## Applications
112
+
113
+ - Computational protein engineering
114
+ - Designing stable mutants or novel sequences on fixed backbones
115
+ - Benchmarking quantum-inspired solvers on NP-hard bioinformatics problems
116
+
117
+ (C) Quantum Computing Inc., 2026.
@@ -0,0 +1,30 @@
1
+ # (C) Quantum Computing Inc., 2024.
2
+ from .fixed_backbone import ProteinDesignFixed
3
+ from .viewer import (
4
+ build_designed_pdb,
5
+ get_backbone_dihedrals,
6
+ get_rotamer_angles,
7
+ view_pdb,
8
+ )
9
+ from .rotamers import (
10
+ download_rotamer_library,
11
+ load_rotamer_library,
12
+ parse_dunbrack_library,
13
+ resolve_rotamer_library,
14
+ check_rotamer_counts,
15
+ get_chi_angles,
16
+ )
17
+
18
+ __all__ = [
19
+ "ProteinDesignFixed",
20
+ "build_designed_pdb",
21
+ "get_backbone_dihedrals",
22
+ "get_rotamer_angles",
23
+ "view_pdb",
24
+ "download_rotamer_library",
25
+ "load_rotamer_library",
26
+ "parse_dunbrack_library",
27
+ "resolve_rotamer_library",
28
+ "check_rotamer_counts",
29
+ "get_chi_angles",
30
+ ]
@@ -0,0 +1,168 @@
1
+ import os
2
+ import sys
3
+ import warnings
4
+ import logging
5
+ import numpy as np
6
+ import pandas as pd
7
+
8
+ from eqc_models.base import ModelSolver, SolutionResults
9
+ from eqc_models.solvers.qciclient import Dirac3CloudSolver
10
+ from eqc_models import QuadraticModel
11
+ from eqc_bio.utils import timer
12
+ from eqc_bio.utils import metis_partition
13
+
14
+ warnings.filterwarnings("ignore")
15
+ log = logging.getLogger(name=__name__)
16
+
17
+ # Seconds per unit for SolutionResults.time_units
18
+ TIME_UNIT_SECONDS = {"ns": 1e-9, "s": 1.0}
19
+
20
+
21
+ class ProteinDesign:
22
+ def __init__(self, solver: ModelSolver = None):
23
+ # Defaults to a cloud solver configured from QCI_API_URL/QCI_TOKEN
24
+ self.solver = solver
25
+
26
+ def get_dirac3_time(self, results: SolutionResults):
27
+ """Return the device time of a solve in seconds."""
28
+ device_time = results.device_time
29
+ if device_time is None:
30
+ log.warning("Device timing not available for this solve")
31
+ return 0.0
32
+
33
+ return np.sum(device_time) * TIME_UNIT_SECONDS[results.time_units]
34
+
35
+ def run_dirac3(self, J, C, sum_constraint, n_vars, num_samples):
36
+ model = QuadraticModel(C, J)
37
+ model.upper_bound = np.array([1] * n_vars)
38
+
39
+ solver = self.solver
40
+ if solver is None:
41
+ solver = Dirac3CloudSolver()
42
+
43
+ results = solver.solve(
44
+ model,
45
+ sum_constraint=sum_constraint,
46
+ relaxation_schedule=self.relaxation_schedule,
47
+ num_samples=num_samples,
48
+ mean_photon_number=self.mean_photon_number,
49
+ quantum_fluctuation_coefficient=self.quantum_fluctuation_coefficient,
50
+ )
51
+ log.info(results)
52
+
53
+ dirac3_time = self.get_dirac3_time(results)
54
+
55
+ return results, dirac3_time
56
+
57
+ def run_dirac3_iterative(
58
+ self,
59
+ J,
60
+ C,
61
+ sum_constraint,
62
+ n_vars,
63
+ positions,
64
+ position_graph,
65
+ position_index_hash,
66
+ ):
67
+ batch_count = int(round(n_vars / self.batch_size))
68
+
69
+ X = np.random.rand(n_vars)
70
+
71
+ if sum_constraint is not None:
72
+ X = X * (sum_constraint / np.sum(X))
73
+
74
+ tmp_group_list = metis_partition(position_graph, k=batch_count)
75
+ tmp_hash = dict(enumerate(positions))
76
+ position_groups = []
77
+ for tmp_group in tmp_group_list:
78
+ position_groups.append([tmp_hash[item] for item in tmp_group])
79
+
80
+ groups = []
81
+ for position_group in position_groups:
82
+ tmp_list = []
83
+ for position in position_group:
84
+ tmp_list += position_index_hash[position]
85
+ groups.append(tmp_list)
86
+
87
+ sols = []
88
+ energies = []
89
+ dirac3_time = 0.0
90
+ for epoch in range(self.n_epochs):
91
+ order = np.random.permutation(batch_count)
92
+ for i in order:
93
+ idx_p = groups[i]
94
+ idx_q = np.setdiff1d(np.arange(n_vars), idx_p)
95
+ Cp = C[idx_p]
96
+ Cq = C[idx_q]
97
+ Xq = X[idx_q]
98
+ Jpp = J[np.ix_(idx_p, idx_p)]
99
+ Jpq = J[np.ix_(idx_p, idx_q)]
100
+ Jqp = J[np.ix_(idx_q, idx_p)]
101
+ Jqq = J[np.ix_(idx_q, idx_q)]
102
+
103
+ tmp_v = 2 * Jpq @ Xq
104
+ tmp_v = tmp_v.reshape((tmp_v.shape[0], 1))
105
+ tmp_C = Cp + tmp_v
106
+ tmp_J = Jpp
107
+
108
+ if sum_constraint is not None:
109
+ tmp_sum_constraint = sum_constraint - np.sum(Xq)
110
+ else:
111
+ tmp_sum_constraint = None
112
+
113
+ sub_response, sub_dirac3_time = self.run_dirac3(
114
+ tmp_J,
115
+ tmp_C,
116
+ max(1.0, tmp_sum_constraint),
117
+ tmp_C.shape[0],
118
+ self.n_samples,
119
+ )
120
+ dirac3_time += sub_dirac3_time
121
+
122
+ sub_sols = sub_response.solutions
123
+
124
+ glob_loc_hash = {}
125
+ for loc_k, glob_k in enumerate(idx_p):
126
+ glob_loc_hash[glob_k] = loc_k
127
+
128
+ for sub_sol in sub_sols:
129
+ sub_sol = np.array(sub_sol)
130
+ feasible_flag = True
131
+ for position in position_groups[i]:
132
+ glob_indexes = position_index_hash[position]
133
+ loc_indexes = [
134
+ glob_loc_hash[item] for item in glob_indexes
135
+ ]
136
+ if np.sum(sub_sol[loc_indexes]) == 0:
137
+ feasible_flag = False
138
+ break
139
+
140
+ if feasible_flag:
141
+ break
142
+
143
+ Xp = sub_sol
144
+ fct = np.sum(Xp)
145
+ if fct != 0:
146
+ fct = tmp_sum_constraint / fct
147
+ Xp = fct * np.array(Xp)
148
+ X[idx_p] = Xp
149
+
150
+ sol = np.array(X)
151
+ energy = sol.T @ J @ sol + sol.T @ C
152
+ energy = energy[0]
153
+
154
+ sols.append(sol)
155
+ energies.append(energy)
156
+
157
+ # Device time is summed over the sub-solves and returned separately
158
+ results = SolutionResults(
159
+ solutions=np.array(sols),
160
+ energies=np.array(energies),
161
+ counts=np.ones(len(sols)),
162
+ objectives=None,
163
+ run_time=None,
164
+ preprocessing_time=None,
165
+ postprocessing_time=None,
166
+ )
167
+
168
+ return results, dirac3_time