├── .gitignore ├── .readthedocs.yaml ├── CHANGELOG.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── afusion.egg-info ├── PKG-INFO ├── SOURCES.txt ├── dependency_links.txt ├── entry_points.txt ├── requires.txt └── top_level.txt ├── afusion ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-310.pyc │ └── cli.cpython-310.pyc ├── api.py ├── app.py ├── bonds.py ├── cli.py ├── execution.py ├── install.py ├── sequence_input.py ├── utils.py └── visualization.py ├── app.py ├── docs ├── Makefile ├── make.bat ├── requirements.txt └── source │ ├── .conf.py.swp │ ├── api.md │ ├── conf.py │ ├── index.md │ ├── index.rst │ ├── installation.md │ ├── release.md │ └── tutorial.md ├── requirements.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 110 | .pdm.toml 111 | .pdm-python 112 | .pdm-build/ 113 | 114 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 115 | __pypackages__/ 116 | 117 | # Celery stuff 118 | celerybeat-schedule 119 | celerybeat.pid 120 | 121 | # SageMath parsed files 122 | *.sage.py 123 | 124 | # Environments 125 | .env 126 | .venv 127 | env/ 128 | venv/ 129 | ENV/ 130 | env.bak/ 131 | venv.bak/ 132 | 133 | # Spyder project settings 134 | .spyderproject 135 | .spyproject 136 | 137 | # Rope project settings 138 | .ropeproject 139 | 140 | # mkdocs documentation 141 | /site 142 | 143 | # mypy 144 | .mypy_cache/ 145 | .dmypy.json 146 | dmypy.json 147 | 148 | # Pyre type checker 149 | .pyre/ 150 | 151 | # pytype static type analyzer 152 | .pytype/ 153 | 154 | # Cython debug symbols 155 | cython_debug/ 156 | 157 | # PyCharm 158 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 159 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 160 | # and can be added to the global gitignore or merged into this file. For a more nuclear 161 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 162 | #.idea/ 163 | 164 | afusion/app_t.py 165 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | 3 | version: 2 4 | 5 | build: 6 | os: ubuntu-22.04 7 | tools: 8 | python: "3.10" 9 | sphinx: 10 | configuration: docs/source/conf.py 11 | 12 | python: 13 | install: 14 | - method: pip 15 | path: . 16 | - requirements: docs/requirements.txt 17 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | > Fork of [Hanziwww/AlphaFold3-GUI](https://github.com/Hanziwww/AlphaFold3-GUI) 4 | 5 | ## [2.0.0] - 2024-02-12 6 | 7 | ### Added 8 | - Advanced 3D visualization controls 9 | - Multiple visualization styles (cartoon, stick, line, sphere) 10 | - Different coloring schemes (confidence, chain, secondary structure, rainbow, custom) 11 | - Residue selection and highlighting functionality 12 | - Chain sequence viewer in sidebar 13 | - Export capabilities 14 | - Added support for multiple 3D file formats (CIF, PDB, STL) 15 | - New CAD/3D printing export functionality with customizable resolution 16 | - Improved mesh generation for 3D models 17 | - Enhanced error handling 18 | - Robust CSV parsing with improved error messages 19 | - Better handling of different PAE data formats 20 | - Comprehensive logging system 21 | 22 | ### Changed 23 | - Improved UI/UX 24 | - Added sidebar navigation 25 | - Reorganized visualization controls 26 | - Enhanced layout with better column ratios 27 | - Added interactive sequence selection 28 | - Enhanced visualization performance 29 | - Optimized memory usage for large structures 30 | - Improved rendering efficiency 31 | - Updated documentation and code structure 32 | - Better function organization 33 | - Improved code comments 34 | - Added type hints and error handling 35 | 36 | ### Fixed 37 | - Various bug fixes in PAE matrix visualization 38 | - Improved handling of missing or malformed data 39 | - Fixed issues with chain boundary visualization 40 | - Resolved memory leaks in 3D visualization 41 | 42 | ## [1.0.0] - Original Release 43 | 44 | - Initial release with basic visualization features 45 | - Basic structure visualization 46 | - PAE matrix display 47 | - Confidence metrics visualization 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md 2 | include LICENSE 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |

3 |

4 |

5 |

6 |

7 |

8 |

9 |

10 |

11 |

12 |

13 | 14 |

AFusion: AlphaFold3 GUI(Graphical User Interface)

15 | 16 |

17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Documentation Status 25 | 26 |

27 | 28 | ![image](https://github.com/user-attachments/assets/d1d894c7-c0cc-4218-9677-1917c1ad7b88) 29 | 30 |

31 | Transform your protein structure prediction workflow with AFusion - a sleek, intuitive graphical interface that makes AlphaFold3 accessible to everyone. No more command-line hassles - just point, click, and predict. 32 |

33 | 34 | **[Demo site](https://af3gui.streamlit.app/)** *(generate input JSON files ONLY)* 35 | 36 | [**Usable visualization site**](https://af3vis.streamlit.app/) *(fully usable)* 37 | 38 | ## Table of Contents 39 | 40 | - [Features](#features) 41 | - [Prerequisites](#prerequisites) 42 | - [Installation and Running](#installation-and-running) 43 | - [Usage](#usage) 44 | - [Launching AFusion](#launching-afusion) 45 | - [Using the GUI](#using-the-gui) 46 | - [Enhanced Visualization Features](#enhanced-visualization-features) 47 | - [Documentation](#documentation) 48 | - [ToDo](#todo) 49 | - [Screenshots](#screenshots) 50 | - [License](#license) 51 | - [Acknowledgements](#acknowledgements) 52 | 53 | ## ✨ Key Features 54 | 55 | ### Installation & Setup 56 | - **GUI Installer**: Step-by-step visual installation wizard 57 | - **Auto-Configuration**: Handles environment setup and dependencies 58 | 59 | ### Core Functionality 60 | - **Visual Workflow**: Clean, modern interface for job configuration 61 | - **Multi-Entity Support**: Process proteins, RNA, DNA, and ligands 62 | - **Advanced Options**: Customize MSA, templates, and modifications 63 | 64 | ### Execution & Control 65 | - **🚀 Integrated Pipeline**: Direct AlphaFold3 execution from GUI 66 | - **🖥️ Live Monitoring**: Real-time process tracking and console output 67 | - **🧩 Batch Processing**: Python API for automated predictions 68 | 69 | ### **🌟 New Features!** 70 | - **AlphaFold 3 Output Analysis System**: Automatically analyze and visualize results with customizable visualizations and generate detailed PDF reports for streamlined insights. 71 | - **Enhanced Visualization Features** (New in this fork): 72 | - Multiple visualization styles (cartoon, stick, line, sphere) 73 | - Flexible coloring schemes (confidence, chain, secondary structure, rainbow) 74 | - Interactive residue selection and chain sequence viewer 75 | - Advanced export capabilities for scientific and 3D printing formats 76 | - Improved PAE matrix visualization and confidence metrics display 77 | 78 | ## Prerequisites 79 | 80 | Before using AFusion, ensure that you have the following: 81 | 82 | 1. **🐳 Docker Installed**: Docker is required to run AlphaFold 3. Install Docker from the [official website](https://www.docker.com/get-started/). 83 | 84 | 2. **🧬 AlphaFold 3 Installed**: AFusion requires AlphaFold 3 to be installed and set up on your system. Follow the installation instructions provided in the [AlphaFold 3 GitHub Repository](https://github.com/google-deepmind/alphafold3) to deploy AlphaFold 3. **Or you can run step-by-step GUI by**: 85 | 86 | ```bash 87 | afusion install 88 | ``` 89 | 90 | 3. **🐍 Python 3.10 or Higher**: AFusion is built with Python and requires Python 3.10 or higher. 91 | 92 | ## Installation and Running 93 | 94 | 1. **Install AFusion** 95 | 96 | Run the following command in your terminal to install AFusion: 97 | 98 | ```bash 99 | pip install afusion 100 | ``` 101 | 102 | 2. **Run AFusion GUI** 103 | 104 | After installation, you can start AFusion by running: 105 | 106 | ```bash 107 | afusion run 108 | ``` 109 | 110 | This will launch the AFusion graphical user interface (GUI) in your default web browser. 111 | 112 | **Please Note:** 113 | 114 | - **🧬 AlphaFold 3 Installation**: Ensure you have correctly installed AlphaFold 3, including model parameters and required databases, following the [AlphaFold 3 Installation Guide](https://github.com/google-deepmind/alphafold3/blob/main/docs/installation.md). 115 | 116 | - **⚙️ Docker Configuration**: After installing Docker, make sure it is running properly and that your user has permission to execute Docker commands. 117 | 118 | - **📦 Streamlit is Included in Dependencies**: AFusion's installation will automatically install all required dependencies, including Streamlit. There's no need to install it separately. 119 | 120 | ## Usage 121 | 122 | ### Launching AFusion 123 | 124 | 1. **🚀 Start the Streamlit App** 125 | 126 | From the project directory, run: 127 | 128 | ```bash 129 | afusion run 130 | ``` 131 | 132 | 2. **🌐 Access the Application** 133 | 134 | - The application will launch, and Streamlit will provide a local URL (e.g., `http://localhost:8501`). 135 | - Open the provided URL in your web browser to access AFusion. 136 | 137 | ### Using the GUI 138 | 139 | **Find more about input in [here](https://github.com/google-deepmind/alphafold3/blob/main/docs/input.md)**. 140 | 141 | #### 1. Welcome Page 142 | 143 | - **👋 Logo and Introduction**: You'll see the AFusion logo and a brief description. 144 | - **📑 Navigation Sidebar**: Use the sidebar on the left to navigate to different sections of the app. 145 | 146 | #### 2. Job Settings 147 | 148 | - **🏷️ Job Name**: Enter a descriptive name for your job. 149 | - **🔢 Model Seeds**: Provide integer seeds separated by commas (e.g., `1,2,3`). 150 | 151 | #### 3. Sequences 152 | 153 | - **🔬 Number of Entities**: Select how many entities you want to add (Proteins, RNA, DNA, Ligand). 154 | - **📋 Entity Details**: For each entity: 155 | - **⚛️ Entity Type**: Select the type (Protein, RNA, DNA, Ligand). 156 | - **🆔 Entity ID**: Provide an identifier for the entity. 157 | - **🧬 Sequence Input**: Enter the sequence information. 158 | - **✏️ Modifications**: Optionally add modifications with their types and positions. 159 | - **📂 MSA Options**: Choose MSA generation options and provide MSA data if applicable. 160 | - **📜 Templates**: Optionally add template data with mmCIF content and indices. 161 | 162 | #### 4. Bonded Atom Pairs (Optional) 163 | 164 | - **🔗 Add Bonds**: Check the box to add bonded atom pairs. 165 | - **⚛️ Define Bonds**: For each bond, provide details for the first and second atoms, including entity IDs, residue IDs, and atom names. 166 | 167 | #### 5. User Provided CCD (Optional) 168 | 169 | - **📜 User CCD Input**: Paste or enter custom CCD data in mmCIF format. 170 | 171 | #### 6. Generated JSON 172 | 173 | - **📄 Review JSON Content**: The application generates the JSON input file based on your entries. You can review it here. 174 | 175 | #### 7. AlphaFold 3 Execution Settings 176 | 177 | - **🗂️ Paths Configuration**: 178 | - **📁 AF Input Path**: Specify the path to the AlphaFold input directory (e.g., `/home/user/af_input`). 179 | - **📂 AF Output Path**: Specify the path to the output directory (e.g., `/home/user/af_output`). 180 | - **📂 Model Parameters Directory**: Provide the path to the model parameters directory. 181 | - **📂 Databases Directory**: Provide the path to the databases directory. 182 | 183 | - **⚙️ Execution Options**: 184 | - **🏗️ Run Data Pipeline**: Choose whether to run the data pipeline (CPU-intensive). 185 | - **💻 Run Inference**: Choose whether to run inference (requires GPU). 186 | 187 | #### 8. Run AlphaFold 3 188 | 189 | - **💾 Save JSON File**: Click the "Save JSON File" button to save the generated JSON to the specified input path. 190 | - **▶️ Run AlphaFold 3 Now**: Click the "Run AlphaFold 3 Now ▶️" button to execute the AlphaFold 3 prediction using the Docker command. 191 | - **🔧 Docker Command**: The exact Docker command used is displayed for your reference. 192 | - **📊 Command Output**: Execution output is displayed within the app for monitoring. 193 | 194 | 195 | ## Documentation 196 | - Full Documentation in [here](https://alphafold3-gui.readthedocs.io) 197 | 198 | ## ToDo 199 | 200 | - [X] ~~📄 **Bulid Documentation:** Tutorial for using the AFusion API in Python scripts for batch predictions.~~ 201 | - [X] ~~♻️ **Refactor Code and Publish to PyPI**: Refactor the project code for improved modularity and maintainability, and publish the latest version to PyPI for easy installation.~~ 202 | - [X] ~~🔗 **Develop AlphaFold result analysis system**: Design and implement a comprehensive analysis pipeline for AlphaFold prediction results.~~ 203 | - [X] ~~Update the system.~~ 204 | - [ ] ⚛️ **Preset Common Small Molecules & Metal Ions**: Add a dedicated section for quick access to commonly used small molecules and metal ions. 205 | - [ ] 🛠️ **New Tool for Chemical Small Molecules**: Develop a new tool to handle and model chemical small molecules, supporting seamless integration into the prediction pipeline. 206 | - [X] ~~🖥️ **Add Console Output**: Implement a backend console for output to track processes and debug more effectively.~~ 207 | - [X] ~~🧩 **Create API for Batch Predictions**: Develop a standalone function API to allow users to perform batch predictions with afusion in Python scripts.~~ 208 | - [X] ~~**🧭 Create Guided Installation GUI**: To simplify the installation process.~~ 209 | - [X] ~~**🎨 Enhanced Visualization Features**: Implement advanced visualization capabilities with multiple styles and export options.~~ 210 | 211 | ## Screenshots 212 | 213 | ### Visualization GUI Interface 214 | 215 |
216 | Click to view screenshot 217 | 218 | image 219 | 220 |
221 | 222 | ### Installation GUI Interface 223 |
224 | Click to view screenshot 225 | 226 | ![image](https://github.com/user-attachments/assets/f083aad7-c3b0-4d1d-b670-7de91804c9b0) 227 |
228 | 229 | ### CLI Output 230 |
231 | Click to view screenshot 232 | 233 | ![image](https://github.com/user-attachments/assets/66bb3789-c2d5-4be2-894b-a779136e8d83) 234 |
235 | 236 | 237 | ## License 238 | 239 | This project is licensed under the GPL3 License - see the [LICENSE](LICENSE) file for details. 240 | 241 | ## Acknowledgements 242 | 243 | - **Original Project**: Created by [Hanziwww](https://github.com/Hanziwww) 244 | - **Visualization Enhancements**: This fork includes additional visualization features while maintaining the core functionality of the original project 245 | - **Enhanced Version**: Maintained by [Shivp1413](https://github.com/Shivp1413) 246 | - **AlphaFold 3**: This GUI is designed to work with [AlphaFold 3](https://github.com/google-deepmind/alphafold3) by DeepMind 247 | - **Streamlit**: AFusion is built using [Streamlit](https://streamlit.io/) 248 | - **Contributors**: Thanks to all contributors to the original project! 249 | 250 | --- 251 | 252 | If you encounter any issues or have suggestions for improvements, please open an [issue](https://github.com/Hanziwww/AlphaFold3-GUI/issues) or submit a [pull request](https://github.com/Hanziwww/AlphaFold3-GUI/pulls). 253 | 254 | Happy Folding! 🧬 255 | -------------------------------------------------------------------------------- /afusion.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: afusion 3 | Version: 1.2.2.2 4 | Summary: AFusion: AlphaFold 3 GUI & Toolkit with Visualization 5 | Home-page: https://github.com/Hanziwww/AlphaFold3-GUI 6 | Author: Han Wang 7 | Author-email: marspenman@gmail.com 8 | Classifier: Programming Language :: Python :: 3 9 | Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) 10 | Classifier: Operating System :: POSIX :: Linux 11 | Requires-Python: >=3.10 12 | Description-Content-Type: text/markdown 13 | License-File: LICENSE 14 | Requires-Dist: streamlit 15 | Requires-Dist: pandas 16 | Requires-Dist: loguru 17 | Requires-Dist: numpy 18 | Requires-Dist: py3Dmol 19 | Requires-Dist: biopython 20 | Requires-Dist: plotly 21 | 22 |

23 |

24 |

25 |

26 |

27 |

28 |

29 |

30 |

31 |

32 |

33 |

34 | 35 |

🔬 AFusion: AlphaFold 3 GUI & Toolkit

36 | 37 |

38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | Documentation Status 46 | 47 |

48 | 49 | ![image](https://github.com/user-attachments/assets/d1d894c7-c0cc-4218-9677-1917c1ad7b88) 50 | 51 |

52 | AFusion is a user-friendly graphical interface designed to simplify the process of AlphaFold 3 installation, prediction and visualization, making it accessible to users who prefer a GUI over command-line interactions. 53 |

54 | 55 | **[Demo site](https://af3gui.streamlit.app/)** *(generate input JSON files ONLY)* 56 | 57 | [**Usable visualization site**](https://af3vis.streamlit.app/) *(fully usable)* 58 | 59 | ## Table of Contents 60 | 61 | - [Features](#features) 62 | - [Prerequisites](#prerequisites) 63 | - [Installation and Running](#installation-and-running) 64 | - [Usage](#usage) 65 | - [Launching AFusion](#launching-afusion) 66 | - [Using the GUI](#using-the-gui) 67 | - [Documentation](#documentation) 68 | - [ToDo](#todo) 69 | - [Screenshots](#screenshots) 70 | - [License](#license) 71 | - [Acknowledgements](#acknowledgements) 72 | 73 | ## Features 74 | - **🧭 Guided Installation**: GUI-based installer to simplify the installation process, easily set up the application step-by-step. 75 | - **✨ Intuitive Interface**: Easily configure job settings, sequences, and execution parameters through a clean and modern GUI. 76 | - **📋 Entity Management**: Add multiple entities (Protein, RNA, DNA, Ligand) with support for modifications, MSA options, and templates. 77 | - **⚙️ Dynamic JSON Generation**: Automatically generates the required JSON input file for AlphaFold 3 based on user inputs. 78 | - **🚀 Integrated Execution**: Run AlphaFold 3 directly from the GUI with customizable Docker execution settings. 79 | - **🖥️ Visual Feedback**: Provides command output within the interface for monitoring and debugging. 80 | - **🖥️ Console Output**: Track processes and debug more effectively with backend console output. 81 | - **🧩 API for Batch Predictions**: Perform batch predictions using the AFusion API in Python scripts. 82 | 83 | ### **🌟 New Feature!** 84 | - **AlphaFold 3 Output Analysis System**: Automatically analyze and visualize results with customizable visualizations and generate detailed PDF reports for streamlined insights. 85 | 86 | ## Prerequisites 87 | 88 | Before using AFusion, ensure that you have the following: 89 | 90 | 1. **🐳 Docker Installed**: Docker is required to run AlphaFold 3. Install Docker from the [official website](https://www.docker.com/get-started/). 91 | 92 | 2. **🧬 AlphaFold 3 Installed**: AFusion requires AlphaFold 3 to be installed and set up on your system. Follow the installation instructions provided in the [AlphaFold 3 GitHub Repository](https://github.com/google-deepmind/alphafold3) to deploy AlphaFold 3. **Or you can run step-by-step GUI by**: 93 | 94 | ```bash 95 | afusion install 96 | ``` 97 | 98 | 3. **🐍 Python 3.10 or Higher**: AFusion is built with Python and requires Python 3.10 or higher. 99 | 100 | ## Installation and Running 101 | 102 | 1. **Install AFusion** 103 | 104 | Run the following command in your terminal to install AFusion: 105 | 106 | ```bash 107 | pip install afusion 108 | ``` 109 | 110 | 2. **Run AFusion GUI** 111 | 112 | After installation, you can start AFusion by running: 113 | 114 | ```bash 115 | afusion run 116 | ``` 117 | 118 | This will launch the AFusion graphical user interface (GUI) in your default web browser. 119 | 120 | **Please Note:** 121 | 122 | - **🧬 AlphaFold 3 Installation**: Ensure you have correctly installed AlphaFold 3, including model parameters and required databases, following the [AlphaFold 3 Installation Guide](https://github.com/google-deepmind/alphafold3/blob/main/docs/installation.md). 123 | 124 | - **⚙️ Docker Configuration**: After installing Docker, make sure it is running properly and that your user has permission to execute Docker commands. 125 | 126 | - **📦 Streamlit is Included in Dependencies**: AFusion's installation will automatically install all required dependencies, including Streamlit. There's no need to install it separately. 127 | 128 | If you encounter any issues during installation or usage, please refer to the relevant official documentation or contact us for support. 129 | 130 | ## Usage 131 | 132 | ### Launching AFusion 133 | 134 | 1. **🚀 Start the Streamlit App** 135 | 136 | From the project directory, run: 137 | 138 | ```bash 139 | afusion run 140 | ``` 141 | 142 | 2. **🌐 Access the Application** 143 | 144 | - The application will launch, and Streamlit will provide a local URL (e.g., `http://localhost:8501`). 145 | - Open the provided URL in your web browser to access AFusion. 146 | 147 | ### Using the GUI 148 | 149 | **Find more about input in [here](https://github.com/google-deepmind/alphafold3/blob/main/docs/input.md)**. 150 | 151 | #### 1. Welcome Page 152 | 153 | - **👋 Logo and Introduction**: You'll see the AFusion logo and a brief description. 154 | - **📑 Navigation Sidebar**: Use the sidebar on the left to navigate to different sections of the app. 155 | 156 | #### 2. Job Settings 157 | 158 | - **🏷️ Job Name**: Enter a descriptive name for your job. 159 | - **🔢 Model Seeds**: Provide integer seeds separated by commas (e.g., `1,2,3`). 160 | 161 | #### 3. Sequences 162 | 163 | - **🔬 Number of Entities**: Select how many entities you want to add (Proteins, RNA, DNA, Ligand). 164 | - **📋 Entity Details**: For each entity: 165 | - **⚛️ Entity Type**: Select the type (Protein, RNA, DNA, Ligand). 166 | - **🆔 Entity ID**: Provide an identifier for the entity. 167 | - **🧬 Sequence Input**: Enter the sequence information. 168 | - **✏️ Modifications**: Optionally add modifications with their types and positions. 169 | - **📂 MSA Options**: Choose MSA generation options and provide MSA data if applicable. 170 | - **📜 Templates**: Optionally add template data with mmCIF content and indices. 171 | 172 | #### 4. Bonded Atom Pairs (Optional) 173 | 174 | - **🔗 Add Bonds**: Check the box to add bonded atom pairs. 175 | - **⚛️ Define Bonds**: For each bond, provide details for the first and second atoms, including entity IDs, residue IDs, and atom names. 176 | 177 | #### 5. User Provided CCD (Optional) 178 | 179 | - **📜 User CCD Input**: Paste or enter custom CCD data in mmCIF format. 180 | 181 | #### 6. Generated JSON 182 | 183 | - **📄 Review JSON Content**: The application generates the JSON input file based on your entries. You can review it here. 184 | 185 | #### 7. AlphaFold 3 Execution Settings 186 | 187 | - **🗂️ Paths Configuration**: 188 | - **📁 AF Input Path**: Specify the path to the AlphaFold input directory (e.g., `/home/user/af_input`). 189 | - **📂 AF Output Path**: Specify the path to the output directory (e.g., `/home/user/af_output`). 190 | - **📂 Model Parameters Directory**: Provide the path to the model parameters directory. 191 | - **📂 Databases Directory**: Provide the path to the databases directory. 192 | 193 | - **⚙️ Execution Options**: 194 | - **🏗️ Run Data Pipeline**: Choose whether to run the data pipeline (CPU-intensive). 195 | - **💻 Run Inference**: Choose whether to run inference (requires GPU). 196 | 197 | #### 8. Run AlphaFold 3 198 | 199 | - **💾 Save JSON File**: Click the "Save JSON File" button to save the generated JSON to the specified input path. 200 | - **▶️ Run AlphaFold 3 Now**: Click the "Run AlphaFold 3 Now ▶️" button to execute the AlphaFold 3 prediction using the Docker command. 201 | - **🔧 Docker Command**: The exact Docker command used is displayed for your reference. 202 | - **📊 Command Output**: Execution output is displayed within the app for monitoring. 203 | 204 | ### Visualization Module 🎨📊 205 | 206 | 1. **🚀 Launch Visualization Interface** 207 | 208 | To start the visualization module, run: 209 | 210 | ```bash 211 | afusion visualization 212 | ``` 213 | 214 | 2. **📂 Upload and Analyze Results** 215 | 216 | - **📤 Upload Files**: Upload AlphaFold 3 output files (e.g., `.cif`, `.json`) directly in the visualization interface. 217 | - **🔬 Visual Analysis**: Perform visual analysis for each prediction, with detailed structure displays and customizable plots. 218 | - **📄 Web Reports**: Generate web reports like Alphafold3 Server for the analysis on demand. 219 | 220 | 3. **🔗 Integrated with Prediction GUI** 221 | 222 | - **🎛️ Seamless Integration**: The visualization tools are also integrated into the prediction GUI. Once predictions are complete, you can switch seamlessly to the visualization tab for analysis. 223 | 224 | ## Documentation 225 | - Full Documentation in [here](https://alphafold3-gui.readthedocs.io) 226 | 227 | ## ToDo 228 | 229 | - [X] ~~📄 **Bulid Documentation:** Tutorial for using the AFusion API in Python scripts for batch predictions.~~ 230 | - [X] ~~♻️ **Refactor Code and Publish to PyPI**: Refactor the project code for improved modularity and maintainability, and publish the latest version to PyPI for easy installation.~~ 231 | - [X] ~~🔗 **Develop AlphaFold result analysis system**: Design and implement a comprehensive analysis pipeline for AlphaFold prediction results.~~ 232 | - [X] ~~Update the system.~~ 233 | - [ ] ⚛️ **Preset Common Small Molecules & Metal Ions**: Add a dedicated section for quick access to commonly used small molecules and metal ions. 234 | - [ ] 🛠️ **New Tool for Chemical Small Molecules**: Develop a new tool to handle and model chemical small molecules, supporting seamless integration into the prediction pipeline. 235 | - [X] ~~🖥️ **Add Console Output**: Implement a backend console for output to track processes and debug more effectively.~~ 236 | - [X] ~~🧩 **Create API for Batch Predictions**: Develop a standalone function API to allow users to perform batch predictions with afusion in Python scripts.~~ 237 | - [X] ~~**🧭 Create Guided Installation GUI**: To simplify the installation process.~~ 238 | 239 | # Screenshots 240 | 241 | ### Prediction GUI Interface 242 |
243 | Click to view screenshot 244 | 245 | ![image](https://github.com/user-attachments/assets/fbeef0c7-b913-4b4a-bd92-4bfe86f12383) 246 | --- 247 | #### Visualization Module 248 | ![5d669cae7b5ff498e456719cfc1fa7ef](https://github.com/user-attachments/assets/c15f7c3a-a8fc-4120-9b9c-dd4fd5bf3697) 249 |
250 | 251 | ### Visualization GUI Interface 252 | 253 |
254 | Click to view screenshot 255 | 256 | ![ba57fe831626ca0184510abd2069a4aa](https://github.com/user-attachments/assets/269cc9be-9145-481f-a819-e5af2bf59788) 257 | 258 |
259 | 260 | ### Installation GUI Interface 261 |
262 | Click to view screenshot 263 | 264 | ![image](https://github.com/user-attachments/assets/f083aad7-c3b0-4d1d-b670-7de91804c9b0) 265 |
266 | 267 | ### CLI Output 268 |
269 | Click to view screenshot 270 | 271 | ![image](https://github.com/user-attachments/assets/66bb3789-c2d5-4be2-894b-a779136e8d83) 272 |
273 | 274 | ## License 275 | 276 | This project is licensed under the GPL3 License - see the [LICENSE](LICENSE) file for details. 277 | 278 | ## Acknowledgements 279 | 280 | - **AlphaFold 3**: This GUI is designed to work with [AlphaFold 3](https://github.com/google-deepmind/alphafold3) by DeepMind. 281 | - **Streamlit**: AFusion is built using [Streamlit](https://streamlit.io/), an open-source app framework for machine learning and data science teams. 282 | - **Contributors**: Waiting for more! 283 | 284 | --- 285 | 286 | If you encounter any issues or have suggestions for improvements, please open an [issue](https://github.com/Hanziwww/AlphaFold3-GUI/issues) or submit a [pull request](https://github.com/Hanziwww/AlphaFold3-GUI/pulls). 287 | 288 | Happy Folding! 🧬 289 | 290 | -------------------------------------------------------------------------------- /afusion.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | .gitignore 2 | .readthedocs.yaml 3 | LICENSE 4 | MANIFEST.in 5 | README.md 6 | app.py 7 | requirements.txt 8 | setup.py 9 | afusion/__init__.py 10 | afusion/api.py 11 | afusion/app.py 12 | afusion/bonds.py 13 | afusion/cli.py 14 | afusion/execution.py 15 | afusion/install.py 16 | afusion/sequence_input.py 17 | afusion/utils.py 18 | afusion/visualization.py 19 | afusion.egg-info/PKG-INFO 20 | afusion.egg-info/SOURCES.txt 21 | afusion.egg-info/dependency_links.txt 22 | afusion.egg-info/entry_points.txt 23 | afusion.egg-info/requires.txt 24 | afusion.egg-info/top_level.txt 25 | afusion/__pycache__/__init__.cpython-310.pyc 26 | afusion/__pycache__/cli.cpython-310.pyc 27 | docs/Makefile 28 | docs/make.bat 29 | docs/requirements.txt 30 | docs/source/.conf.py.swp 31 | docs/source/api.md 32 | docs/source/conf.py 33 | docs/source/index.md 34 | docs/source/index.rst 35 | docs/source/installation.md 36 | docs/source/release.md 37 | docs/source/tutorial.md -------------------------------------------------------------------------------- /afusion.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /afusion.egg-info/entry_points.txt: -------------------------------------------------------------------------------- 1 | [console_scripts] 2 | afusion = afusion.cli:main 3 | -------------------------------------------------------------------------------- /afusion.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | streamlit 2 | pandas 3 | loguru 4 | numpy 5 | py3Dmol 6 | biopython 7 | plotly 8 | -------------------------------------------------------------------------------- /afusion.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | afusion 2 | -------------------------------------------------------------------------------- /afusion/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hanziwww/AlphaFold3-GUI/b18760506a53e8799af2d1d285e36c37544768b6/afusion/__init__.py -------------------------------------------------------------------------------- /afusion/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hanziwww/AlphaFold3-GUI/b18760506a53e8799af2d1d285e36c37544768b6/afusion/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /afusion/__pycache__/cli.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hanziwww/AlphaFold3-GUI/b18760506a53e8799af2d1d285e36c37544768b6/afusion/__pycache__/cli.cpython-310.pyc -------------------------------------------------------------------------------- /afusion/api.py: -------------------------------------------------------------------------------- 1 | # afusion/api.py 2 | 3 | import os 4 | import json 5 | import re 6 | import uuid 7 | import pandas as pd 8 | from afusion.execution import run_alphafold 9 | from afusion.utils import compress_output_folder 10 | from loguru import logger 11 | 12 | 13 | def create_batch_task(job_name, entities, model_seeds, bonded_atom_pairs=None, user_ccd=None): 14 | """ 15 | Creates a batch task dictionary for a single prediction. 16 | 17 | :param job_name: Name of the job. 18 | :type job_name: str 19 | :param entities: List of dictionaries, each representing an Entity. 20 | Each entity dict should have keys: 21 | - 'type': 'protein', 'rna', 'dna', or 'ligand' 22 | - 'id': str or list 23 | - 'sequence_data': dict with sequence information 24 | :type entities: list 25 | :param model_seeds: List of integers. 26 | :type model_seeds: list of int 27 | :param bonded_atom_pairs: Optional list of bonded atom pairs. 28 | :type bonded_atom_pairs: list, optional 29 | :param user_ccd: Optional user CCD. 30 | :type user_ccd: str, optional 31 | :return: Dictionary representing the AlphaFold input JSON structure. 32 | :rtype: dict 33 | """ 34 | sequences = [] 35 | for entity in entities: 36 | entity_type = entity['type'] 37 | sequence_data = entity['sequence_data'] 38 | entity_id = entity['id'] 39 | 40 | sequence_entry = sequence_data.copy() 41 | sequence_entry['id'] = entity_id 42 | 43 | if entity_type == 'protein': 44 | sequences.append({'protein': sequence_entry}) 45 | elif entity_type == 'rna': 46 | sequences.append({'rna': sequence_entry}) 47 | elif entity_type == 'dna': 48 | sequences.append({'dna': sequence_entry}) 49 | elif entity_type == 'ligand': 50 | sequences.append({'ligand': sequence_entry}) 51 | else: 52 | logger.error(f"Unknown entity type: {entity_type}") 53 | continue 54 | 55 | alphafold_input = { 56 | "name": job_name, 57 | "modelSeeds": model_seeds, 58 | "sequences": sequences, 59 | "dialect": "alphafold3", 60 | "version": 1 61 | } 62 | 63 | if bonded_atom_pairs: 64 | alphafold_input["bondedAtomPairs"] = bonded_atom_pairs 65 | 66 | if user_ccd: 67 | alphafold_input["userCCD"] = user_ccd 68 | 69 | logger.debug(f"Created task for job: {job_name}") 70 | return alphafold_input 71 | 72 | 73 | def run_batch_predictions( 74 | tasks, 75 | af_input_base_path, 76 | af_output_base_path, 77 | model_parameters_dir, 78 | databases_dir, 79 | run_data_pipeline=True, 80 | run_inference=True, 81 | bucket_sizes=None, 82 | ): 83 | """ 84 | Runs batch predictions for the given tasks. 85 | 86 | :param tasks: List of task dicts, as generated by create_batch_task. 87 | :type tasks: list of dict 88 | :param af_input_base_path: Base path for AlphaFold input. 89 | :type af_input_base_path: str 90 | :param af_output_base_path: Base path for AlphaFold output. 91 | :type af_output_base_path: str 92 | :param model_parameters_dir: Path to model parameters directory. 93 | :type model_parameters_dir: str 94 | :param databases_dir: Path to databases directory. 95 | :type databases_dir: str 96 | :param run_data_pipeline: Whether to run data pipeline. 97 | :type run_data_pipeline: bool 98 | :param run_inference: Whether to run inference. 99 | :type run_inference: bool 100 | :param bucket_sizes: Optional list of bucket sizes. 101 | :type bucket_sizes: list of int, optional 102 | :return: List of dicts with keys 'job_name', 'output_folder', 'status'. 103 | :rtype: list of dict 104 | """ 105 | results = [] 106 | for task in tasks: 107 | job_name = task['name'] 108 | job_folder_name = job_name 109 | 110 | input_path = os.path.join(af_input_base_path, job_folder_name) 111 | output_path = af_output_base_path 112 | 113 | os.makedirs(input_path, exist_ok=True) 114 | os.makedirs(output_path, exist_ok=True) 115 | 116 | json_save_path = os.path.join(input_path, "fold_input.json") 117 | try: 118 | with open(json_save_path, "w") as json_file: 119 | json.dump(task, json_file, indent=2) 120 | logger.info(f"JSON file saved for job '{job_name}' at {json_save_path}") 121 | except Exception as e: 122 | logger.error(f"Error saving JSON file for job '{job_name}': {e}") 123 | results.append({ 124 | 'job_name': job_name, 125 | 'output_folder': output_path, 126 | 'status': f'Failed to save JSON: {e}' 127 | }) 128 | continue 129 | 130 | # Build the Docker command 131 | docker_command = ( 132 | f"docker run --rm " 133 | f"--volume {input_path}:/root/af_input " 134 | f"--volume {output_path}:/root/af_output " 135 | f"--volume {model_parameters_dir}:/root/models " 136 | f"--volume {databases_dir}:/root/public_databases " 137 | f"--gpus all " 138 | f"alphafold3 " 139 | f"python run_alphafold.py " 140 | f"--json_path=/root/af_input/fold_input.json " 141 | f"--model_dir=/root/models " 142 | f"--output_dir=/root/af_output " 143 | f"{'--run_data_pipeline' if run_data_pipeline else ''} " 144 | f"{'--run_inference' if run_inference else ''} " 145 | f"{'--buckets ' + ','.join(map(str, bucket_sizes)) if bucket_sizes else ''}" 146 | ) 147 | 148 | logger.debug(f"Running Docker command for job '{job_name}': {docker_command}") 149 | 150 | # Run AlphaFold 151 | try: 152 | output = run_alphafold(docker_command) 153 | logger.info(f"AlphaFold execution completed for job '{job_name}'.") 154 | 155 | # Check if the output directory exists 156 | expected_output_folder = os.path.join(af_output_base_path, job_folder_name) 157 | if os.path.exists(expected_output_folder): 158 | logger.info(f"Results saved in: {expected_output_folder}") 159 | status = 'Success' 160 | else: 161 | logger.error(f"Output folder '{expected_output_folder}' not found for job '{job_name}'.") 162 | status = 'Failed' 163 | except Exception as e: 164 | logger.error(f"Error running AlphaFold for job '{job_name}': {e}") 165 | status = f'Failed to run AlphaFold: {e}' 166 | 167 | results.append({ 168 | 'job_name': job_name, 169 | 'output_folder': output_path, 170 | 'status': status 171 | }) 172 | 173 | return results 174 | 175 | 176 | def create_protein_sequence_data(sequence, modifications=None, msa_option='auto', unpaired_msa=None, paired_msa=None, templates=None): 177 | """ 178 | Creates sequence data for a protein entity. 179 | 180 | :param sequence: The protein sequence. 181 | :type sequence: str 182 | :param modifications: Optional list of modifications, each with keys 'ptmType' and 'ptmPosition'. 183 | :type modifications: list of dict, optional 184 | :param msa_option: MSA option, 'auto', 'upload', or 'none'. 185 | :type msa_option: str 186 | :param unpaired_msa: Unpaired MSA (if msa_option is 'upload'). 187 | :type unpaired_msa: str, optional 188 | :param paired_msa: Paired MSA (if msa_option is 'upload'). 189 | :type paired_msa: str, optional 190 | :param templates: Optional list of template dicts. 191 | :type templates: list of dict, optional 192 | :return: Sequence data dictionary. 193 | :rtype: dict 194 | """ 195 | protein_entry = { 196 | "sequence": sequence 197 | } 198 | if modifications: 199 | protein_entry["modifications"] = modifications 200 | if msa_option == 'auto': 201 | protein_entry["unpairedMsa"] = None 202 | protein_entry["pairedMsa"] = None 203 | protein_entry["templates"] = [] 204 | elif msa_option == 'none': 205 | protein_entry["unpairedMsa"] = "" 206 | protein_entry["pairedMsa"] = "" 207 | protein_entry["templates"] = [] 208 | elif msa_option == 'upload': 209 | protein_entry["unpairedMsa"] = unpaired_msa or "" 210 | protein_entry["pairedMsa"] = paired_msa or "" 211 | protein_entry["templates"] = templates or [] 212 | else: 213 | logger.error(f"Invalid msa_option: {msa_option}") 214 | return protein_entry 215 | 216 | 217 | def create_rna_sequence_data(sequence, modifications=None, msa_option='auto', unpaired_msa=None): 218 | """ 219 | Creates sequence data for an RNA entity. 220 | 221 | :param sequence: The RNA sequence. 222 | :type sequence: str 223 | :param modifications: Optional list of modifications. 224 | :type modifications: list of dict, optional 225 | :param msa_option: MSA option, 'auto', 'upload', or 'none'. 226 | :type msa_option: str 227 | :param unpaired_msa: Unpaired MSA (if msa_option is 'upload'). 228 | :type unpaired_msa: str, optional 229 | :return: Sequence data dictionary. 230 | :rtype: dict 231 | """ 232 | rna_entry = { 233 | "sequence": sequence 234 | } 235 | if modifications: 236 | rna_entry["modifications"] = modifications 237 | if msa_option == 'auto': 238 | rna_entry["unpairedMsa"] = None 239 | elif msa_option == 'none': 240 | rna_entry["unpairedMsa"] = "" 241 | elif msa_option == 'upload': 242 | rna_entry["unpairedMsa"] = unpaired_msa or "" 243 | else: 244 | logger.error(f"Invalid msa_option: {msa_option}") 245 | return rna_entry 246 | 247 | 248 | def create_dna_sequence_data(sequence, modifications=None): 249 | """ 250 | Creates sequence data for a DNA entity. 251 | 252 | :param sequence: The DNA sequence. 253 | :type sequence: str 254 | :param modifications: Optional list of modifications. 255 | :type modifications: list of dict, optional 256 | :return: Sequence data dictionary. 257 | :rtype: dict 258 | """ 259 | dna_entry = { 260 | "sequence": sequence 261 | } 262 | if modifications: 263 | dna_entry["modifications"] = modifications 264 | return dna_entry 265 | 266 | 267 | def create_ligand_sequence_data(ccd_codes=None, smiles=None): 268 | """ 269 | Creates sequence data for a ligand entity. 270 | 271 | :param ccd_codes: List of CCD codes. 272 | :type ccd_codes: list of str, optional 273 | :param smiles: SMILES string. 274 | :type smiles: str, optional 275 | :return: Sequence data dictionary. 276 | :rtype: dict 277 | """ 278 | if ccd_codes and smiles: 279 | logger.error("Please provide only one of CCD Codes or SMILES String.") 280 | return {} 281 | elif ccd_codes: 282 | ligand_entry = { 283 | "ccdCodes": ccd_codes 284 | } 285 | return ligand_entry 286 | elif smiles: 287 | ligand_entry = { 288 | "smiles": smiles 289 | } 290 | return ligand_entry 291 | else: 292 | logger.error("Ligand requires either CCD Codes or SMILES String.") 293 | return {} 294 | 295 | 296 | def create_tasks_from_dataframe(df): 297 | """ 298 | Creates batch tasks from a DataFrame. 299 | 300 | :param df: DataFrame with columns representing parameters: 301 | - 'job_name': str 302 | - 'type': 'protein', 'rna', 'dna', or 'ligand' 303 | - 'id': str or list 304 | - 'sequence': str 305 | - Other optional parameters: 306 | - 'modifications': list of dicts (as JSON string) 307 | - 'msa_option': 'auto', 'upload', or 'none' 308 | - 'unpaired_msa': str 309 | - 'paired_msa': str 310 | - 'templates': list of dicts (as JSON string) 311 | - 'model_seeds': list of integers (as string) 312 | - 'bonded_atom_pairs': list (as JSON string) 313 | - 'user_ccd': str 314 | :type df: pandas.DataFrame 315 | :return: List of task dictionaries. 316 | :rtype: list of dict 317 | """ 318 | tasks = [] 319 | grouped = df.groupby('job_name') 320 | for job_name, group in grouped: 321 | entities = [] 322 | model_seeds = None 323 | bonded_atom_pairs = None 324 | user_ccd = None 325 | 326 | for _, row in group.iterrows(): 327 | entity_type = row['type'] 328 | entity_id = row['id'] 329 | sequence = row.get('sequence', '') 330 | 331 | # Parse optional fields 332 | modifications = parse_json_field(row.get('modifications')) 333 | msa_option = row.get('msa_option', 'auto') 334 | unpaired_msa = row.get('unpaired_msa') 335 | paired_msa = row.get('paired_msa') 336 | templates = parse_json_field(row.get('templates')) 337 | 338 | # Create sequence data based on entity type 339 | if entity_type == 'protein': 340 | sequence_data = create_protein_sequence_data( 341 | sequence=sequence, 342 | modifications=modifications, 343 | msa_option=msa_option, 344 | unpaired_msa=unpaired_msa, 345 | paired_msa=paired_msa, 346 | templates=templates 347 | ) 348 | elif entity_type == 'rna': 349 | sequence_data = create_rna_sequence_data( 350 | sequence=sequence, 351 | modifications=modifications, 352 | msa_option=msa_option, 353 | unpaired_msa=unpaired_msa 354 | ) 355 | elif entity_type == 'dna': 356 | sequence_data = create_dna_sequence_data( 357 | sequence=sequence, 358 | modifications=modifications 359 | ) 360 | elif entity_type == 'ligand': 361 | ccd_codes = parse_list_field(row.get('ccd_codes')) 362 | smiles = row.get('smiles') 363 | sequence_data = create_ligand_sequence_data( 364 | ccd_codes=ccd_codes, 365 | smiles=smiles 366 | ) 367 | else: 368 | logger.error(f"Unknown entity type: {entity_type}") 369 | continue 370 | 371 | entities.append({ 372 | 'type': entity_type, 373 | 'id': entity_id, 374 | 'sequence_data': sequence_data 375 | }) 376 | 377 | # Get job-level parameters (assuming they are the same for all entities in the group) 378 | if model_seeds is None and pd.notna(row.get('model_seeds')): 379 | model_seeds = parse_list_field(row.get('model_seeds'), data_type=int) 380 | if bonded_atom_pairs is None and pd.notna(row.get('bonded_atom_pairs')): 381 | bonded_atom_pairs = parse_json_field(row.get('bonded_atom_pairs')) 382 | if user_ccd is None and pd.notna(row.get('user_ccd')): 383 | user_ccd = row.get('user_ccd') 384 | 385 | if model_seeds is None: 386 | model_seeds = [1] # Default seed if not provided 387 | 388 | task = create_batch_task( 389 | job_name=job_name, 390 | entities=entities, 391 | model_seeds=model_seeds, 392 | bonded_atom_pairs=bonded_atom_pairs, 393 | user_ccd=user_ccd 394 | ) 395 | tasks.append(task) 396 | return tasks 397 | 398 | 399 | def parse_json_field(value): 400 | """ 401 | Parses a JSON string field into a Python object. 402 | 403 | Returns None if the value is NaN or empty. 404 | 405 | :param value: JSON string to parse. 406 | :type value: str 407 | :return: Parsed Python object or None. 408 | :rtype: object or None 409 | """ 410 | if pd.isna(value) or value == '': 411 | return None 412 | try: 413 | return json.loads(value) 414 | except json.JSONDecodeError as e: 415 | logger.error(f"JSON decode error: {e}") 416 | return None 417 | 418 | def parse_list_field(value, data_type=str): 419 | """ 420 | Parses a comma-separated string field into a list. 421 | 422 | Returns None if the value is NaN or empty. 423 | 424 | :param value: Comma-separated string to parse. 425 | :type value: str 426 | :param data_type: Data type to convert list items to. 427 | :type data_type: type 428 | :return: List of items converted to data_type, or None. 429 | :rtype: list or None 430 | """ 431 | if pd.isna(value) or value == '': 432 | return None 433 | return [data_type(item.strip()) for item in value.split(',') if item.strip()] 434 | 435 | -------------------------------------------------------------------------------- /afusion/app.py: -------------------------------------------------------------------------------- 1 | # app.py 2 | 3 | import streamlit as st 4 | import json 5 | import re 6 | import os 7 | import sys 8 | from loguru import logger 9 | import pandas as pd 10 | import numpy as np 11 | import plotly.express as px 12 | import io 13 | import py3Dmol 14 | from Bio import PDB 15 | 16 | # Import your modules (make sure they are correctly installed in your environment) 17 | from afusion.execution import run_alphafold 18 | from afusion.sequence_input import ( 19 | collect_protein_sequence_data, 20 | collect_rna_sequence_data, 21 | collect_dna_sequence_data, 22 | collect_ligand_sequence_data 23 | ) 24 | from afusion.bonds import handle_bond 25 | from afusion.utils import log_to_ga, compress_output_folder 26 | 27 | # Import visualization functions 28 | from afusion.visualization import ( 29 | read_cif_file, 30 | extract_residue_bfactors, 31 | extract_pae_from_json, 32 | extract_summary_confidences, 33 | display_visualization_header, 34 | visualize_pae, 35 | display_summary_data 36 | ) 37 | 38 | # Configure the logger 39 | logger.add("afusion.log", rotation="1 MB", level="DEBUG") 40 | 41 | # Redefine the visualize_structure function to change the background color to black 42 | def visualize_structure(residue_bfactors, ligands, cif_content): 43 | # Make the viewer responsive by setting width to '100%' 44 | view = py3Dmol.view(width='100%', height=600) 45 | view.addModel(cif_content, 'cif') 46 | 47 | # Set default style for protein as cartoon with grey color 48 | view.setStyle({'model': -1}, {'cartoon': {'color': 'grey'}}) 49 | 50 | # Color each residue based on average B-factor 51 | for (chain_id, resseq), info in residue_bfactors.items(): 52 | avg_bfactor = info['avg_bfactor'] 53 | color = get_color_from_bfactor(avg_bfactor) 54 | selection = {'chain': chain_id, 'resi': resseq} 55 | style = {'cartoon': {'color': color}} 56 | view.addStyle(selection, style) 57 | 58 | # Color ligand atoms based on B-factor 59 | for ligand in ligands: 60 | bfactor = ligand['bfactor'] 61 | color = get_color_from_bfactor(bfactor) 62 | selection = { 63 | 'chain': ligand['chain_id'], 64 | 'resi': ligand['resseq'], 65 | 'atom': ligand['atom_name'] 66 | } 67 | style = {'stick': {'color': color}} 68 | view.addStyle(selection, style) 69 | 70 | # Set background color to black 71 | view.setBackgroundColor('#000000') 72 | 73 | # Generate HTML content 74 | view_html = view._make_html() 75 | return view_html 76 | 77 | # Also redefine get_color_from_bfactor function if it's not imported 78 | def get_color_from_bfactor(bfactor): 79 | # Define color mapping 80 | color_mapping = [ 81 | {'range': [90, 100], 'color': '#106dff'}, # Very high (pLDDT > 90) 82 | {'range': [70, 90], 'color': '#10cff1'}, # Confident (90 > pLDDT > 70) 83 | {'range': [50, 70], 'color': '#f6ed12'}, # Low (70 > pLDDT > 50) 84 | {'range': [0, 50], 'color': '#ef821e'} # Very low (pLDDT < 50) 85 | ] 86 | for mapping in color_mapping: 87 | b_min, b_max = mapping['range'] 88 | if b_min <= bfactor < b_max: 89 | return mapping['color'] 90 | return 'grey' # Default color 91 | 92 | def main(): 93 | 94 | # Log to Google Analytics when the app starts 95 | log_to_ga() 96 | 97 | # Set page configuration and theme 98 | st.set_page_config( 99 | page_title="AFusion: AlphaFold 3 GUI", 100 | page_icon="🧬", 101 | layout="wide", 102 | initial_sidebar_state="expanded", 103 | ) 104 | 105 | # Custom CSS styling 106 | st.markdown(""" 107 | 139 | """, unsafe_allow_html=True) 140 | 141 | # Title and subtitle 142 | st.markdown("

🔬 AFusion: AlphaFold 3 GUI

", unsafe_allow_html=True) 143 | st.markdown("

A convenient GUI for running AlphaFold 3 predictions

", unsafe_allow_html=True) 144 | st.markdown("

If this project helps you, please ⭐️ my project!

", unsafe_allow_html=True) 145 | 146 | #### Sidebar Navigation #### 147 | with st.sidebar: 148 | st.header("Navigation") 149 | st.sidebar.markdown("---") 150 | sections = { 151 | "Job Settings": "job_settings", 152 | "Sequences": "sequences", 153 | "Bonded Atom Pairs": "bonded_atom_pairs", 154 | "User Provided CCD": "user_ccd", 155 | "Generated JSON": "json_content", 156 | "Execution Settings": "execution_settings", 157 | "Run AlphaFold 3": "run_alphafold", 158 | } 159 | for section_name, section_id in sections.items(): 160 | st.markdown(f"{section_name}", unsafe_allow_html=True) 161 | st.markdown("---") 162 | st.markdown("Created by Hanzi 2024.", unsafe_allow_html=True) 163 | 164 | # Main Content 165 | st.markdown('
', unsafe_allow_html=True) 166 | st.markdown("### Welcome to AFusion!") 167 | st.markdown("Use this GUI to generate input JSON files and run AlphaFold 3 predictions with ease. Please [install AlphaFold 3](https://github.com/google-deepmind/alphafold3/blob/main/docs/installation.md) before using.") 168 | 169 | st.markdown('
', unsafe_allow_html=True) 170 | st.header("📝 Job Settings") 171 | with st.expander("Configure Job Settings", expanded=True): 172 | job_name = st.text_input("Job Name", value="My AlphaFold Job", help="Enter a descriptive name for your job.") 173 | logger.info(f"Job name set to: {job_name}") 174 | model_seeds = st.text_input("Model Seeds (comma-separated)", value="1,2,3", help="Provide integer seeds separated by commas.") 175 | logger.debug(f"Model seeds input: {model_seeds}") 176 | model_seeds_list = [int(seed.strip()) for seed in model_seeds.split(",") if seed.strip().isdigit()] 177 | if not model_seeds_list: 178 | st.error("Please provide at least one valid model seed.") 179 | logger.error("No valid model seeds provided.") 180 | st.stop() 181 | logger.info(f"Model seeds list: {model_seeds_list}") 182 | 183 | st.markdown('
', unsafe_allow_html=True) 184 | st.header("📄 Sequences") 185 | sequences = [] 186 | num_entities = st.number_input("Number of Entities", min_value=1, step=1, value=1, help="Select the number of entities you want to add.") 187 | logger.info(f"Number of entities set to: {num_entities}") 188 | 189 | for i in range(int(num_entities)): 190 | st.markdown(f"### Entity {i+1}") 191 | with st.expander(f"Entity {i+1} Details", expanded=True): 192 | entity_type = st.selectbox(f"Select Entity Type", ["Protein 🧬", "RNA 🧫", "DNA 🧬", "Ligand 💊"], key=f"entity_type_{i}") 193 | logger.info(f"Entity {i+1} type: {entity_type}") 194 | 195 | copy_number = st.number_input(f"Copy Number", min_value=1, step=1, value=1, key=f"copy_number_{i}", help="Specify the number of copies of this sequence.") 196 | logger.info(f"Entity {i+1} copy number: {copy_number}") 197 | 198 | # Collect sequence data 199 | if entity_type.startswith("Protein"): 200 | sequence_data = collect_protein_sequence_data(i) 201 | elif entity_type.startswith("RNA"): 202 | sequence_data = collect_rna_sequence_data(i) 203 | elif entity_type.startswith("DNA"): 204 | sequence_data = collect_dna_sequence_data(i) 205 | elif entity_type.startswith("Ligand"): 206 | sequence_data = collect_ligand_sequence_data(i) 207 | else: 208 | st.error(f"Unknown entity type: {entity_type}") 209 | logger.error(f"Unknown entity type: {entity_type}") 210 | continue # Skip to next entity 211 | 212 | # Handle IDs based on copy number 213 | entity_ids = [] 214 | if copy_number >= 1: 215 | # Allow user to input multiple IDs 216 | entity_id = st.text_input(f"Entity ID(s) (comma-separated)", key=f"entity_id_{i}", help="Provide entity ID(s), separated by commas if multiple.") 217 | if not entity_id.strip(): 218 | st.error("Entity ID is required.") 219 | logger.error("Entity ID missing.") 220 | continue 221 | entity_ids = re.split(r"\s*,\s*", entity_id) 222 | if len(entity_ids) != copy_number: 223 | st.error(f"Please provide {copy_number} ID(s) separated by commas.") 224 | logger.error(f"Number of IDs provided does not match copy number for Entity {i+1}.") 225 | continue 226 | logger.debug(f"Entity {i+1} IDs: {entity_ids}") 227 | 228 | for copy_id in entity_ids: 229 | # Clone the sequence data and set the ID 230 | sequence_entry = sequence_data.copy() 231 | sequence_entry['id'] = copy_id 232 | # Wrap the entry appropriately 233 | if entity_type.startswith("Protein"): 234 | sequences.append({"protein": sequence_entry}) 235 | elif entity_type.startswith("RNA"): 236 | sequences.append({"rna": sequence_entry}) 237 | elif entity_type.startswith("DNA"): 238 | sequences.append({"dna": sequence_entry}) 239 | elif entity_type.startswith("Ligand"): 240 | sequences.append({"ligand": sequence_entry}) 241 | else: 242 | st.error("Copy number must be at least 1.") 243 | logger.error("Invalid copy number.") 244 | continue 245 | 246 | st.markdown('
', unsafe_allow_html=True) 247 | st.header("🔗 Bonded Atom Pairs (Optional)") 248 | bonded_atom_pairs = [] 249 | add_bonds = st.checkbox("Add Bonded Atom Pairs") 250 | if add_bonds: 251 | num_bonds = st.number_input("Number of Bonds", min_value=1, step=1, key="num_bonds") 252 | for b in range(int(num_bonds)): 253 | st.markdown(f"**Bond {b+1}**") 254 | bond = handle_bond(b) 255 | if bond: 256 | bonded_atom_pairs.append(bond) 257 | logger.debug(f"Added bond: {bond}") 258 | 259 | st.markdown('
', unsafe_allow_html=True) 260 | st.header("🧩 User Provided CCD (Optional)") 261 | user_ccd = st.text_area("User CCD (mmCIF format)") 262 | if user_ccd: 263 | logger.debug("User provided CCD data.") 264 | 265 | # Generate JSON Data 266 | alphafold_input = { 267 | "name": job_name, 268 | "modelSeeds": model_seeds_list, 269 | "sequences": sequences, 270 | "dialect": "alphafold3", 271 | "version": 1 272 | } 273 | 274 | if bonded_atom_pairs: 275 | alphafold_input["bondedAtomPairs"] = bonded_atom_pairs 276 | 277 | if user_ccd: 278 | alphafold_input["userCCD"] = user_ccd 279 | 280 | # Convert JSON to string 281 | json_output = json.dumps(alphafold_input, indent=2) 282 | logger.debug(f"Generated JSON:\n{json_output}") 283 | 284 | st.markdown('
', unsafe_allow_html=True) 285 | st.header("📄 Generated JSON Content") 286 | st.code(json_output, language="json") 287 | 288 | st.markdown('
', unsafe_allow_html=True) 289 | st.header("⚙️ AlphaFold 3 Execution Settings") 290 | with st.expander("Configure Execution Settings", expanded=True): 291 | # Paths for execution 292 | af_input_path = st.text_input("AF Input Path", value=os.path.expanduser("~/af_input"), help="Path to AlphaFold input directory.") 293 | af_output_path = st.text_input("AF Output Path", value=os.path.expanduser("~/af_output"), help="Path to AlphaFold output directory.") 294 | model_parameters_dir = st.text_input("Model Parameters Directory", value="/path/to/models", help="Path to model parameters directory.") 295 | databases_dir = st.text_input("Databases Directory", value="/path/to/databases", help="Path to databases directory.") 296 | 297 | logger.debug(f"Execution settings: af_input_path={af_input_path}, af_output_path={af_output_path}, model_parameters_dir={model_parameters_dir}, databases_dir={databases_dir}") 298 | 299 | # Additional options 300 | run_data_pipeline = st.checkbox("Run Data Pipeline (CPU only, time-consuming)", value=True) 301 | run_inference = st.checkbox("Run Inference (requires GPU)", value=True) 302 | 303 | logger.info(f"Run data pipeline: {run_data_pipeline}, Run inference: {run_inference}") 304 | 305 | # Bucket Sizes Configuration 306 | use_custom_buckets = st.checkbox("Specify Custom Compilation Buckets", value=False) 307 | if use_custom_buckets: 308 | buckets_input = st.text_input( 309 | "Bucket Sizes (comma-separated)", 310 | value="256,512,768,1024,1280,1536,2048,2560,3072,3584,4096,4608,5120", 311 | help="Specify bucket sizes separated by commas. Example: 256,512,768,..." 312 | ) 313 | # Parse buckets 314 | bucket_sizes = [int(size.strip()) for size in buckets_input.split(",") if size.strip().isdigit()] 315 | if not bucket_sizes: 316 | st.error("Please provide at least one valid bucket size.") 317 | logger.error("No valid bucket sizes provided.") 318 | st.stop() 319 | logger.debug(f"Custom bucket sizes: {bucket_sizes}") 320 | else: 321 | bucket_sizes = [] # Empty list indicates default buckets 322 | 323 | st.markdown('
', unsafe_allow_html=True) 324 | st.header("🚀 Run AlphaFold 3") 325 | # Save JSON to file 326 | json_save_path = os.path.join(af_input_path, "fold_input.json") 327 | try: 328 | os.makedirs(af_input_path, exist_ok=True) 329 | with open(json_save_path, "w") as json_file: 330 | json.dump(alphafold_input, json_file, indent=2) 331 | st.success(f"JSON file saved to {json_save_path}") 332 | logger.info(f"JSON file saved to {json_save_path}") 333 | except Exception as e: 334 | st.error(f"Error saving JSON file: {e}") 335 | logger.error(f"Error saving JSON file: {e}") 336 | 337 | # Run AlphaFold 3 338 | if st.button("Run AlphaFold 3 Now ▶️"): 339 | # Build the Docker command 340 | docker_command = ( 341 | f"docker run --rm " 342 | f"--volume {af_input_path}:/root/af_input " 343 | f"--volume {af_output_path}:/root/af_output " 344 | f"--volume {model_parameters_dir}:/root/models " 345 | f"--volume {databases_dir}:/root/public_databases " 346 | f"--gpus all " 347 | f"alphafold3 " 348 | f"python run_alphafold.py " 349 | f"--json_path=/root/af_input/fold_input.json " 350 | f"--model_dir=/root/models " 351 | f"--output_dir=/root/af_output " 352 | f"{'--run_data_pipeline' if run_data_pipeline else ''} " 353 | f"{'--run_inference' if run_inference else ''} " 354 | f"{'--buckets ' + ','.join(map(str, bucket_sizes)) if bucket_sizes else ''}" 355 | ) 356 | 357 | st.markdown("#### Docker Command:") 358 | st.code(docker_command, language="bash") 359 | logger.debug(f"Docker command: {docker_command}") 360 | 361 | # Run the command and display output in a box 362 | with st.spinner('AlphaFold 3 is running...'): 363 | output_placeholder = st.empty() 364 | output = run_alphafold(docker_command, placeholder=output_placeholder) 365 | 366 | # Display the output in an expander box 367 | st.markdown("#### Command Output:") 368 | with st.expander("Show Command Output 📄", expanded=False): 369 | st.text_area("Command Output", value=output, height=400) 370 | 371 | logger.info("AlphaFold 3 execution completed.") 372 | 373 | # Check if the output directory exists 374 | job_output_folder_name = job_name.lower().replace(' ', '_') 375 | output_folder_path = os.path.join(af_output_path, job_output_folder_name) 376 | 377 | if os.path.exists(output_folder_path): 378 | st.success("AlphaFold 3 execution completed successfully.") 379 | st.info(f"Results are saved in: {output_folder_path}") 380 | logger.info(f"Results saved in: {output_folder_path}") 381 | 382 | # Provide download option 383 | st.markdown("### Download Results 📥") 384 | zip_data = compress_output_folder(output_folder_path, job_output_folder_name) 385 | st.download_button( 386 | label="Download ZIP", 387 | data=zip_data, 388 | file_name=f"{job_output_folder_name}.zip", 389 | mime="application/zip" 390 | ) 391 | logger.info("User downloaded the results ZIP file.") 392 | 393 | # Visualize the results directly on the same page 394 | st.markdown("### Visualize Your Results") 395 | st.write("The prediction results are visualized below.") 396 | 397 | # Get the paths to the necessary files 398 | def find_file_by_suffix(directory_path, suffix): 399 | for root, dirs, files in os.walk(directory_path): 400 | for file_name in files: 401 | if file_name.endswith(suffix): 402 | return os.path.join(root, file_name) 403 | return None 404 | 405 | def find_file_by_suffix_exclude_summary(directory_path, suffix, exclude_name): 406 | for root, dirs, files in os.walk(directory_path): 407 | for file_name in files: 408 | if file_name.endswith(suffix) and exclude_name not in file_name: 409 | return os.path.join(root, file_name) 410 | return None 411 | 412 | required_files = { 413 | "model.cif": find_file_by_suffix(output_folder_path, 'model.cif'), 414 | "confidences.json": find_file_by_suffix_exclude_summary(output_folder_path, 'confidences.json', 'summary_confidences.json'), 415 | "summary_confidences.json": find_file_by_suffix(output_folder_path, 'summary_confidences.json') 416 | } 417 | 418 | missing_files = [fname for fname, fpath in required_files.items() if fpath is None] 419 | if missing_files: 420 | st.error(f"Missing files: {', '.join(missing_files)} in the output directory or its subdirectories.") 421 | logger.error(f"Missing files: {', '.join(missing_files)}") 422 | else: 423 | st.success("All required files are found.") 424 | logger.info(f"Required files found: {required_files}") 425 | 426 | # Load the data 427 | structure, cif_content = read_cif_file(required_files["model.cif"]) 428 | residue_bfactors, ligands = extract_residue_bfactors(structure) 429 | pae_matrix, token_chain_ids = extract_pae_from_json(required_files["confidences.json"]) 430 | summary_data = extract_summary_confidences(required_files["summary_confidences.json"]) 431 | 432 | chain_ids = list(set(token_chain_ids)) 433 | chain_ids.sort() # Sort for consistency 434 | 435 | logger.debug("Successfully loaded data from output folder.") 436 | 437 | # Display the visualizations 438 | display_visualization_header() 439 | 440 | # Create two columns with width ratio 3:2 441 | col1, col2 = st.columns([3, 2]) 442 | 443 | with col1: 444 | st.write("### 3D Model Visualization") 445 | if residue_bfactors or ligands: 446 | view_html = visualize_structure(residue_bfactors, ligands, cif_content) 447 | st.components.v1.html(view_html, height=600, scrolling=False) 448 | else: 449 | st.error("Failed to extract atom data.") 450 | logger.error("Failed to extract atom data.") 451 | 452 | with col2: 453 | # Visualize the PAE matrix 454 | visualize_pae(pae_matrix, token_chain_ids) 455 | 456 | # Display summary data 457 | display_summary_data(summary_data, chain_ids) 458 | else: 459 | st.error("AlphaFold 3 execution did not complete successfully. Please check the logs.") 460 | logger.error("AlphaFold 3 execution did not complete successfully.") 461 | else: 462 | st.info("Click the 'Run AlphaFold 3 Now ▶️' button to execute the command.") 463 | 464 | st.markdown("---") 465 | 466 | # Provide access to the log file 467 | st.markdown("### Download Log File 📥") 468 | with open('afusion.log', 'r') as log_file: 469 | log_content = log_file.read() 470 | st.download_button( 471 | label="Download Log File", 472 | data=log_content, 473 | file_name='afusion.log', 474 | mime='text/plain' 475 | ) 476 | 477 | # Display log content in the app 478 | with st.expander("Show Log Content 📄", expanded=False): 479 | st.text_area("Log Content", value=log_content, height=200) 480 | 481 | st.markdown("---") 482 | # Add footer 483 | st.markdown("

© 2024 Hanzi. All rights reserved.

", unsafe_allow_html=True) 484 | 485 | if __name__ == "__main__": 486 | main() 487 | -------------------------------------------------------------------------------- /afusion/bonds.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | from loguru import logger 3 | 4 | def handle_bond(b): 5 | bond_col1, bond_col2 = st.columns(2) 6 | with bond_col1: 7 | st.markdown("**First Atom**") 8 | entity_id1 = st.text_input(f"Entity ID 1", key=f"bond_entity1_{b}") 9 | residue_id1 = st.number_input(f"Residue ID 1", min_value=1, step=1, key=f"bond_residue1_{b}") 10 | atom_name1 = st.text_input(f"Atom Name 1", key=f"bond_atom1_{b}") 11 | with bond_col2: 12 | st.markdown("**Second Atom**") 13 | entity_id2 = st.text_input(f"Entity ID 2", key=f"bond_entity2_{b}") 14 | residue_id2 = st.number_input(f"Residue ID 2", min_value=1, step=1, key=f"bond_residue2_{b}") 15 | atom_name2 = st.text_input(f"Atom Name 2", key=f"bond_atom2_{b}") 16 | 17 | if not (entity_id1 and atom_name1 and entity_id2 and atom_name2): 18 | st.error("All fields are required for defining a bond.") 19 | logger.error(f"Fields missing for bond {b+1}.") 20 | return None 21 | 22 | bond = [ 23 | [entity_id1, residue_id1, atom_name1], 24 | [entity_id2, residue_id2, atom_name2] 25 | ] 26 | logger.debug(f"Bond {b+1} defined as: {bond}") 27 | return bond 28 | -------------------------------------------------------------------------------- /afusion/cli.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import sys 5 | import argparse 6 | 7 | def main(): 8 | parser = argparse.ArgumentParser( 9 | prog='afusion', 10 | description='Afusion command line tool' 11 | ) 12 | subparsers = parser.add_subparsers( 13 | dest='command', 14 | help='Sub-commands' 15 | ) 16 | 17 | # 'install' sub-command 18 | install_parser = subparsers.add_parser( 19 | 'install', 20 | help='Launch the installation GUI' 21 | ) 22 | 23 | # 'run' sub-command 24 | run_parser = subparsers.add_parser( 25 | 'run', 26 | help='Run the main application (Alphafold3 GUI)' 27 | ) 28 | 29 | # 'visualization' sub-command 30 | visualization_parser = subparsers.add_parser( 31 | 'visualization', 32 | help='Launch the Visualization App' 33 | ) 34 | visualization_parser.add_argument( 35 | '--output_folder_path', 36 | type=str, 37 | default='', 38 | help='Path to the AlphaFold 3 output directory for visualization' 39 | ) 40 | 41 | # Parse the command-line arguments 42 | args = parser.parse_args() 43 | 44 | if args.command == 'install': 45 | current_dir = os.path.dirname(os.path.abspath(__file__)) 46 | root_dir = os.path.abspath(os.path.join(current_dir, '..')) 47 | if root_dir not in sys.path: 48 | sys.path.insert(0, root_dir) 49 | 50 | app_path = os.path.join(root_dir, 'afusion/install.py') 51 | 52 | streamlit_command = [ 53 | 'streamlit', 'run', app_path, 54 | '--server.fileWatcherType=none' 55 | ] + sys.argv[2:] # Skip the first two arguments ('afusion', 'install') 56 | os.execvp('streamlit', streamlit_command) 57 | 58 | elif args.command == 'run': 59 | # Run the main application (Alphafold3 GUI) 60 | current_dir = os.path.dirname(os.path.abspath(__file__)) 61 | root_dir = os.path.abspath(os.path.join(current_dir, '..')) 62 | if root_dir not in sys.path: 63 | sys.path.insert(0, root_dir) 64 | 65 | app_path = os.path.join(root_dir, 'afusion/app.py') 66 | 67 | streamlit_command = [ 68 | 'streamlit', 'run', app_path, 69 | '--server.fileWatcherType=none' 70 | ] + sys.argv[2:] # Skip the first two arguments ('afusion', 'run') 71 | os.execvp('streamlit', streamlit_command) 72 | 73 | elif args.command == 'visualization': 74 | # Run the Visualization App 75 | current_dir = os.path.dirname(os.path.abspath(__file__)) 76 | root_dir = os.path.abspath(os.path.join(current_dir, '..')) 77 | if root_dir not in sys.path: 78 | sys.path.insert(0, root_dir) 79 | 80 | app_path = os.path.join(root_dir, 'afusion/visualization.py') 81 | 82 | streamlit_command = [ 83 | 'streamlit', 'run', app_path, 84 | '--server.port', '8502', 85 | '--server.fileWatcherType=none' 86 | ] 87 | 88 | # Pass the output_folder_path as command-line argument 89 | if args.output_folder_path: 90 | streamlit_command += ['--', f'--output_folder_path={args.output_folder_path}'] 91 | 92 | os.execvp('streamlit', streamlit_command) 93 | 94 | else: 95 | # Handle other commands or display help information 96 | parser.print_help() 97 | 98 | if __name__ == '__main__': 99 | main() 100 | -------------------------------------------------------------------------------- /afusion/execution.py: -------------------------------------------------------------------------------- 1 | # afusion/execution.py 2 | 3 | import subprocess 4 | from loguru import logger 5 | 6 | def run_alphafold(command, placeholder=None): 7 | """ 8 | Runs the AlphaFold Docker command and captures output. 9 | Uses placeholder to update output in real-time if provided. 10 | """ 11 | process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, shell=True) 12 | output_lines = [] 13 | for line in iter(process.stdout.readline, ''): 14 | if line: 15 | output_lines.append(line) 16 | logger.debug(line.strip()) 17 | # Update placeholder if provided 18 | if placeholder is not None: 19 | placeholder.markdown(f"```\n{''.join(output_lines)}\n```") 20 | process.stdout.close() 21 | process.wait() 22 | return ''.join(output_lines) 23 | -------------------------------------------------------------------------------- /afusion/install.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import subprocess 3 | import os 4 | import sys 5 | import time 6 | 7 | # Import logging library 8 | from loguru import logger 9 | 10 | # Configure the logger 11 | logger.add("install.log", rotation="1 MB", level="DEBUG") 12 | 13 | # Set page configuration and theme 14 | st.set_page_config( 15 | page_title="AlphaFold 3 Installation Guide", 16 | page_icon="🧬", 17 | layout="wide", 18 | initial_sidebar_state="expanded", 19 | ) 20 | 21 | # Custom CSS styling 22 | st.markdown(""" 23 | 41 | """, unsafe_allow_html=True) 42 | 43 | # Title and subtitle 44 | st.markdown("

🧬 AlphaFold 3 Installation Guide

", unsafe_allow_html=True) 45 | st.markdown("

Please follow the steps below to install AlphaFold 3

", unsafe_allow_html=True) 46 | st.markdown("

If this project helps you, please ⭐️ my project!

", unsafe_allow_html=True) 47 | 48 | # Sidebar navigation 49 | st.sidebar.title("Navigation") 50 | st.sidebar.markdown("---") 51 | steps = { 52 | "1️⃣ Environment Preparation": "env_prep", 53 | "2️⃣ Install Docker": "install_docker", 54 | "3️⃣ Install NVIDIA Drivers": "install_nvidia", 55 | "4️⃣ Download AlphaFold 3 Source Code": "download_code", 56 | "5️⃣ Obtain Genetic Databases": "download_db", 57 | "6️⃣ Obtain Model Parameters": "obtain_models", 58 | "7️⃣ Build Docker Container": "build_docker", 59 | "8️⃣ Run Test": "run_test", 60 | } 61 | for step_name, step_id in steps.items(): 62 | st.sidebar.markdown(f"{step_name}", unsafe_allow_html=True) 63 | st.sidebar.markdown("---") 64 | st.sidebar.markdown("© 2024 Your Name. All rights reserved.", unsafe_allow_html=True) 65 | 66 | # Main content 67 | st.markdown("## 1️⃣ Environment Preparation", unsafe_allow_html=True) 68 | st.markdown('
', unsafe_allow_html=True) 69 | 70 | st.markdown("Before getting started, please ensure that your system meets the following requirements:") 71 | st.markdown(""" 72 | - Running **Linux** operating system (Ubuntu 22.04 LTS is recommended) 73 | - **NVIDIA GPU** installed with Compute Capability **8.0** or higher 74 | - At least **64GB** of RAM 75 | - At least **1TB** of disk space (**SSD** is recommended) 76 | """) 77 | 78 | with st.expander("Check System Environment", expanded=False): 79 | st.markdown("Click the button below to check your system environment.") 80 | if st.button("Check Environment", key="env_check"): 81 | # Check Operating System 82 | logger.info("Checking Operating System...") 83 | os_info = subprocess.getoutput("lsb_release -a") 84 | st.markdown("#### Operating System Info:") 85 | st.code(os_info, language="bash") 86 | logger.debug(f"Operating System Info:\n{os_info}") 87 | 88 | # Check GPU 89 | logger.info("Checking GPU...") 90 | gpu_info = subprocess.getoutput("nvidia-smi") 91 | st.markdown("#### GPU Info:") 92 | st.code(gpu_info, language="bash") 93 | logger.debug(f"GPU Info:\n{gpu_info}") 94 | 95 | # Check Memory 96 | logger.info("Checking Memory...") 97 | mem_info = subprocess.getoutput("free -h") 98 | st.markdown("#### Memory Info:") 99 | st.code(mem_info, language="bash") 100 | logger.debug(f"Memory Info:\n{mem_info}") 101 | 102 | # Check Disk Space 103 | logger.info("Checking Disk Space...") 104 | disk_info = subprocess.getoutput("df -h") 105 | st.markdown("#### Disk Space Info:") 106 | st.code(disk_info, language="bash") 107 | logger.debug(f"Disk Space Info:\n{disk_info}") 108 | 109 | st.markdown("## 2️⃣ Install Docker", unsafe_allow_html=True) 110 | st.markdown('
', unsafe_allow_html=True) 111 | 112 | st.markdown("AlphaFold 3 depends on Docker for execution. Next, we'll install and configure Docker.") 113 | 114 | with st.expander("Install Docker", expanded=False): 115 | st.markdown("Click the button below to begin installing Docker.") 116 | st.warning("**Note:** Some commands require `sudo` privileges. Please run these commands in your terminal when prompted.") 117 | if st.button("Install Docker", key="install_docker"): 118 | st.info("Please run the following commands in your terminal:") 119 | docker_commands = """ 120 | sudo apt-get update 121 | sudo apt-get install -y ca-certificates curl 122 | sudo install -m 0755 -d /etc/apt/keyrings 123 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg 124 | sudo chmod a+r /etc/apt/keyrings/docker.gpg 125 | echo \\ 126 | "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \\ 127 | https://download.docker.com/linux/ubuntu \\ 128 | $(lsb_release -cs) stable" | \\ 129 | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null 130 | sudo apt-get update 131 | sudo apt-get install -y docker-ce docker-ce-cli containerd.io 132 | """ 133 | st.code(docker_commands, language="bash") 134 | st.info("After running the above commands, click the 'Verify Docker Installation' button below.") 135 | if st.button("Verify Docker Installation", key="verify_docker"): 136 | try: 137 | docker_version = subprocess.getoutput("docker --version") 138 | st.success(f"Docker installed successfully! {docker_version}") 139 | logger.info(f"Docker installed successfully! {docker_version}") 140 | except Exception as e: 141 | st.error("Docker is not installed correctly. Please ensure you've run the commands above.") 142 | logger.error(f"Docker installation verification error: {e}") 143 | 144 | st.markdown("## 3️⃣ Install NVIDIA Drivers", unsafe_allow_html=True) 145 | st.markdown('
', unsafe_allow_html=True) 146 | 147 | st.markdown("Next, we'll install the appropriate NVIDIA drivers for your GPU.") 148 | 149 | with st.expander("Install NVIDIA Drivers", expanded=False): 150 | st.markdown("Click the button below to begin installing NVIDIA drivers.") 151 | st.warning("**Note:** This step requires `sudo` privileges. Please run the commands in your terminal when prompted.") 152 | if st.button("Install NVIDIA Drivers", key="install_nvidia"): 153 | st.info("Please run the following commands in your terminal:") 154 | nvidia_commands = """ 155 | sudo apt-get update 156 | sudo apt-get install -y ubuntu-drivers-common 157 | sudo ubuntu-drivers install 158 | """ 159 | st.code(nvidia_commands, language="bash") 160 | st.info("After running the above commands, reboot your system and then click the 'Verify NVIDIA Installation' button below.") 161 | if st.button("Verify NVIDIA Installation", key="verify_nvidia"): 162 | try: 163 | nvidia_info = subprocess.getoutput("nvidia-smi") 164 | if "NVIDIA-SMI" in nvidia_info: 165 | st.success("NVIDIA drivers installed successfully!") 166 | st.code(nvidia_info, language="bash") 167 | logger.info("NVIDIA drivers installed successfully!") 168 | else: 169 | st.error("NVIDIA drivers are not installed correctly. Please ensure you've run the commands above and rebooted your system.") 170 | logger.error("NVIDIA drivers verification failed.") 171 | except Exception as e: 172 | st.error(f"An error occurred while verifying NVIDIA drivers: {e}") 173 | logger.error(f"NVIDIA drivers verification error: {e}") 174 | 175 | st.markdown("## 4️⃣ Download AlphaFold 3 Source Code", unsafe_allow_html=True) 176 | st.markdown('
', unsafe_allow_html=True) 177 | 178 | st.markdown("Now, we'll clone the AlphaFold 3 source code from GitHub.") 179 | 180 | with st.expander("Download Source Code", expanded=False): 181 | st.markdown("Click the button below to begin downloading the AlphaFold 3 source code.") 182 | st.warning("**Note:** Some commands may require `sudo` privileges. Please run these commands in your terminal when prompted.") 183 | if st.button("Download Source Code", key="clone_code"): 184 | st.info("Please run the following commands in your terminal:") 185 | git_commands = """ 186 | sudo apt-get install -y git 187 | git clone https://github.com/google-deepmind/alphafold3.git 188 | """ 189 | st.code(git_commands, language="bash") 190 | st.info("After running the above commands, ensure the 'alphafold3' directory has been created.") 191 | 192 | st.markdown("## 5️⃣ Obtain Genetic Databases", unsafe_allow_html=True) 193 | st.markdown('
', unsafe_allow_html=True) 194 | 195 | st.markdown("AlphaFold 3 requires multiple genetic databases to run. Downloading and setting up these databases may take some time.") 196 | 197 | with st.expander("Download Genetic Databases", expanded=False): 198 | st.markdown("Click the button below to begin downloading the genetic databases.") 199 | db_dir = st.text_input("Please enter the database download directory (absolute path):", value=f"{os.path.expanduser('~')}/alphafold3_databases") 200 | st.warning("**Note:** This step requires `sudo` privileges. Please run the commands in your terminal when prompted.") 201 | if st.button("Download Databases", key="download_db"): 202 | st.info("Please run the following commands in your terminal:") 203 | db_commands = f""" 204 | sudo apt-get install -y wget zstd 205 | cd alphafold3 # Navigate to the AlphaFold 3 directory 206 | ./fetch_databases.sh {db_dir} 207 | """ 208 | st.code(db_commands, language="bash") 209 | st.info("This process may take a long time. Please be patient and ensure you have sufficient disk space.") 210 | 211 | st.markdown("## 6️⃣ Obtain Model Parameters", unsafe_allow_html=True) 212 | st.markdown('
', unsafe_allow_html=True) 213 | 214 | st.markdown("The AlphaFold 3 model parameters require requesting access.") 215 | 216 | with st.expander("Request Access to Model Parameters", expanded=False): 217 | st.markdown("Please [**click here**](https://forms.gle/svvpY4u2jsHEwWYS6) to fill out the form to request access to AlphaFold 3 model parameters.") 218 | st.markdown("Once you have obtained the model parameters, please place them in an appropriate directory.") 219 | 220 | st.markdown("## 7️⃣ Build Docker Container", unsafe_allow_html=True) 221 | st.markdown('
', unsafe_allow_html=True) 222 | 223 | st.markdown("Now, we'll build the Docker container for AlphaFold 3.") 224 | 225 | with st.expander("Build Docker Container", expanded=False): 226 | st.markdown("Click the button below to begin building the Docker container. This may take some time. Please be patient.") 227 | st.warning("**Note:** This step may require `sudo` privileges. Please run the commands in your terminal when prompted.") 228 | if st.button("Build Docker Container", key="build_docker"): 229 | st.info("Please run the following commands in your terminal:") 230 | build_commands = """ 231 | cd alphafold3 # Navigate to the AlphaFold 3 directory 232 | sudo docker build -t alphafold3 -f docker/Dockerfile . 233 | """ 234 | st.code(build_commands, language="bash") 235 | st.info("After running the above commands, the Docker container should be built successfully.") 236 | 237 | st.markdown("## 8️⃣ Run Test", unsafe_allow_html=True) 238 | st.markdown('
', unsafe_allow_html=True) 239 | 240 | st.markdown("Finally, we'll run a simple test to verify that AlphaFold 3 has been installed successfully.") 241 | 242 | with st.expander("Run Test", expanded=False): 243 | st.markdown("Click the button below to begin the test.") 244 | input_dir = st.text_input("Please enter the input directory (absolute path):", value=f"{os.path.expanduser('~')}/af_input") 245 | output_dir = st.text_input("Please enter the output directory (absolute path):", value=f"{os.path.expanduser('~')}/af_output") 246 | model_dir = st.text_input("Please enter the model parameters directory (absolute path):", value=f"{os.path.expanduser('~')}/alphafold3_models") 247 | db_dir = st.text_input("Please enter the database directory (absolute path):", value=f"{os.path.expanduser('~')}/alphafold3_databases") 248 | st.warning("**Note:** This step may require `sudo` privileges. Please run the commands in your terminal when prompted.") 249 | if st.button("Run Test", key="run_test"): 250 | st.info("Please ensure that you have prepared an appropriate input JSON file in the input directory.") 251 | st.info("Please run the following command in your terminal:") 252 | test_command = f""" 253 | sudo docker run -it \\ 254 | --volume {input_dir}:/root/af_input \\ 255 | --volume {output_dir}:/root/af_output \\ 256 | --volume {model_dir}:/root/models \\ 257 | --volume {db_dir}:/root/public_databases \\ 258 | --gpus all \\ 259 | alphafold3 \\ 260 | python run_alphafold.py \\ 261 | --json_path=/root/af_input/fold_input.json \\ 262 | --model_dir=/root/models \\ 263 | --output_dir=/root/af_output 264 | """ 265 | st.code(test_command, language="bash") 266 | st.info("After running the above command, the test should execute. Please check the output directory for results.") 267 | 268 | st.markdown("

🎉 Congratulations, AlphaFold 3 has been successfully installed!

", unsafe_allow_html=True) 269 | st.markdown("---") 270 | 271 | # Provide access to the log file 272 | st.markdown("### Download Log File 📥") 273 | if os.path.exists('install.log'): 274 | with open('install.log', 'r') as log_file: 275 | log_content = log_file.read() 276 | st.download_button( 277 | label="Download Log File", 278 | data=log_content, 279 | file_name='install.log', 280 | mime='text/plain' 281 | ) 282 | 283 | # Display log content in the app 284 | with st.expander("Show Log Content 📄", expanded=False): 285 | st.text_area("Log Content", value=log_content, height=200) 286 | else: 287 | st.info("Log file not found. It will be created after you run some steps in the installation.") 288 | st.markdown("---") 289 | # Add footer 290 | st.markdown("

© 2024 Your Name. All rights reserved.

", unsafe_allow_html=True) 291 | -------------------------------------------------------------------------------- /afusion/sequence_input.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import re 3 | from loguru import logger 4 | 5 | def collect_protein_sequence_data(i): 6 | sequence = st.text_area(f"Protein Sequence (Entity {i+1})", key=f"sequence_{i}", help="Enter the protein sequence.") 7 | logger.debug(f"Protein sequence input for Entity {i+1}.") 8 | 9 | # Modifications 10 | modifications_list = [] 11 | add_modifications = st.checkbox(f"Add Modifications", key=f"add_modifications_{i}") 12 | if add_modifications: 13 | num_modifications = st.number_input(f"Number of Modifications", min_value=1, step=1, key=f"num_modifications_{i}") 14 | for j in range(int(num_modifications)): 15 | st.markdown(f"**Modification {j+1}**") 16 | mod_col1, mod_col2 = st.columns(2) 17 | with mod_col1: 18 | mod_type = st.text_input(f"Modification Type (ptmType)", key=f"mod_type_{i}_{j}") 19 | with mod_col2: 20 | mod_position = st.number_input(f"Modification Position (ptmPosition)", min_value=1, step=1, key=f"mod_position_{i}_{j}") 21 | modifications_list.append({"ptmType": mod_type, "ptmPosition": mod_position}) 22 | logger.debug(f"Added modification: {modifications_list[-1]}") 23 | 24 | # MSA Options 25 | msa_option = st.selectbox(f"MSA Option", ["Auto-generate 🛠️", "Don't use MSA 🚫", "Upload MSA 📄"], key=f"msa_option_{i}") 26 | 27 | unpaired_msa = "" 28 | paired_msa = "" 29 | if msa_option == "Upload MSA 📄": 30 | unpaired_msa = st.text_area(f"Unpaired MSA", key=f"unpaired_msa_{i}") 31 | paired_msa = st.text_area(f"Paired MSA", key=f"paired_msa_{i}") 32 | logger.debug(f"Entity {i+1} uploaded MSA.") 33 | elif msa_option == "Don't use MSA 🚫": 34 | unpaired_msa = "" 35 | paired_msa = "" 36 | logger.debug(f"Entity {i+1} chose not to use MSA.") 37 | elif msa_option == "Auto-generate 🛠️": 38 | unpaired_msa = None 39 | paired_msa = None 40 | logger.debug(f"Entity {i+1} chose to auto-generate MSA.") 41 | 42 | # Templates 43 | templates_list = [] 44 | add_templates = st.checkbox(f"Add Templates", key=f"add_templates_{i}") 45 | if add_templates: 46 | num_templates = st.number_input(f"Number of Templates", min_value=1, step=1, key=f"num_templates_{i}") 47 | for k in range(int(num_templates)): 48 | st.markdown(f"**Template {k+1}**") 49 | mmcif_content = st.text_area(f"mmCIF Content", key=f"mmcif_{i}_{k}") 50 | query_indices = st.text_input(f"Query Indices List (comma-separated)", key=f"query_indices_{i}_{k}") 51 | template_indices = st.text_input(f"Template Indices List (comma-separated)", key=f"template_indices_{i}_{k}") 52 | try: 53 | query_indices_list = [int(idx.strip()) for idx in query_indices.split(",") if idx.strip()] 54 | template_indices_list = [int(idx.strip()) for idx in template_indices.split(",") if idx.strip()] 55 | except ValueError: 56 | st.error("Indices lists should be integers separated by commas.") 57 | logger.error("Error parsing indices lists.") 58 | query_indices_list = [] 59 | template_indices_list = [] 60 | templates_list.append({ 61 | "mmcif": mmcif_content, 62 | "queryIndices": query_indices_list, 63 | "templateIndices": template_indices_list 64 | }) 65 | logger.debug(f"Added template: {templates_list[-1]}") 66 | 67 | protein_entry = { 68 | "sequence": sequence 69 | } 70 | if modifications_list: 71 | protein_entry["modifications"] = modifications_list 72 | if unpaired_msa is not None: 73 | protein_entry["unpairedMsa"] = unpaired_msa 74 | if paired_msa is not None: 75 | protein_entry["pairedMsa"] = paired_msa 76 | if templates_list or (unpaired_msa is not None) or (paired_msa is not None): 77 | if "unpairedMsa" not in protein_entry: 78 | protein_entry["unpairedMsa"] = "" 79 | if "pairedMsa" not in protein_entry: 80 | protein_entry["pairedMsa"] = "" 81 | if templates_list: 82 | protein_entry["templates"] = templates_list 83 | else: 84 | protein_entry["templates"] = [] 85 | elif msa_option == "Don't use MSA 🚫": 86 | protein_entry["unpairedMsa"] = "" 87 | protein_entry["pairedMsa"] = "" 88 | protein_entry["templates"] = [] 89 | return protein_entry 90 | 91 | def collect_rna_sequence_data(i): 92 | sequence = st.text_area(f"RNA Sequence (Entity {i+1})", key=f"sequence_{i}", help="Enter the RNA sequence.") 93 | logger.debug(f"RNA sequence input for Entity {i+1}.") 94 | 95 | # Modifications 96 | modifications_list = [] 97 | add_modifications = st.checkbox(f"Add Modifications", key=f"add_modifications_{i}") 98 | if add_modifications: 99 | num_modifications = st.number_input(f"Number of Modifications", min_value=1, step=1, key=f"num_modifications_{i}") 100 | for j in range(int(num_modifications)): 101 | st.markdown(f"**Modification {j+1}**") 102 | mod_col1, mod_col2 = st.columns(2) 103 | with mod_col1: 104 | mod_type = st.text_input(f"Modification Type (modificationType)", key=f"mod_type_{i}_{j}") 105 | with mod_col2: 106 | mod_position = st.number_input(f"Modification Position (basePosition)", min_value=1, step=1, key=f"mod_position_{i}_{j}") 107 | modifications_list.append({"modificationType": mod_type, "basePosition": mod_position}) 108 | logger.debug(f"Added modification: {modifications_list[-1]}") 109 | 110 | # MSA Options 111 | msa_option = st.selectbox(f"MSA Option", ["Auto-generate 🛠️", "Don't use MSA 🚫", "Upload MSA 📄"], key=f"msa_option_{i}") 112 | 113 | unpaired_msa = "" 114 | if msa_option == "Upload MSA 📄": 115 | unpaired_msa = st.text_area(f"Unpaired MSA", key=f"unpaired_msa_{i}") 116 | logger.debug(f"Entity {i+1} uploaded MSA.") 117 | elif msa_option == "Don't use MSA 🚫": 118 | unpaired_msa = "" 119 | logger.debug(f"Entity {i+1} chose not to use MSA.") 120 | elif msa_option == "Auto-generate 🛠️": 121 | unpaired_msa = None 122 | logger.debug(f"Entity {i+1} chose to auto-generate MSA.") 123 | 124 | rna_entry = { 125 | "sequence": sequence 126 | } 127 | if modifications_list: 128 | rna_entry["modifications"] = modifications_list 129 | if unpaired_msa is not None: 130 | rna_entry["unpairedMsa"] = unpaired_msa 131 | return rna_entry 132 | 133 | def collect_dna_sequence_data(i): 134 | sequence = st.text_area(f"DNA Sequence (Entity {i+1})", key=f"sequence_{i}", help="Enter the DNA sequence.") 135 | logger.debug(f"DNA sequence input for Entity {i+1}.") 136 | 137 | # Modifications 138 | modifications_list = [] 139 | add_modifications = st.checkbox(f"Add Modifications", key=f"add_modifications_{i}") 140 | if add_modifications: 141 | num_modifications = st.number_input(f"Number of Modifications", min_value=1, step=1, key=f"num_modifications_{i}") 142 | for j in range(int(num_modifications)): 143 | st.markdown(f"**Modification {j+1}**") 144 | mod_col1, mod_col2 = st.columns(2) 145 | with mod_col1: 146 | mod_type = st.text_input(f"Modification Type (modificationType)", key=f"mod_type_{i}_{j}") 147 | with mod_col2: 148 | mod_position = st.number_input(f"Modification Position (basePosition)", min_value=1, step=1, key=f"mod_position_{i}_{j}") 149 | modifications_list.append({"modificationType": mod_type, "basePosition": mod_position}) 150 | logger.debug(f"Added modification: {modifications_list[-1]}") 151 | 152 | dna_entry = { 153 | "sequence": sequence 154 | } 155 | if modifications_list: 156 | dna_entry["modifications"] = modifications_list 157 | 158 | return dna_entry 159 | 160 | def collect_ligand_sequence_data(i): 161 | ccd_codes = st.text_input(f"CCD Codes (comma-separated)", key=f"ccd_codes_{i}", help="Provide CCD Codes, separated by commas. Ions can be specified as ligands with ccdCodes (e.g., MG).") 162 | smiles = st.text_input(f"SMILES String", key=f"smiles_{i}", help="Provide SMILES string of the ligand.") 163 | if ccd_codes and smiles: 164 | st.error("Please provide only one of CCD Codes or SMILES String.") 165 | logger.error("Ligand provided both CCD Codes and SMILES String.") 166 | return {} 167 | elif ccd_codes: 168 | ccd_codes_list = re.split(r"\s*,\s*", ccd_codes) 169 | ligand_entry = { 170 | "ccdCodes": ccd_codes_list 171 | } 172 | logger.debug(f"Ligand CCD Codes: {ccd_codes_list}") 173 | return ligand_entry 174 | elif smiles: 175 | ligand_entry = { 176 | "smiles": smiles 177 | } 178 | logger.debug(f"Ligand SMILES: {smiles}") 179 | return ligand_entry 180 | else: 181 | st.error("Ligand requires either CCD Codes or SMILES String.") 182 | logger.error("Ligand missing CCD Codes or SMILES String.") 183 | return {} 184 | -------------------------------------------------------------------------------- /afusion/utils.py: -------------------------------------------------------------------------------- 1 | # utils.py 2 | 3 | import os 4 | import uuid 5 | import json 6 | import requests 7 | from loguru import logger 8 | import streamlit as st 9 | 10 | def log_to_ga(): 11 | # Replace with your Measurement ID 12 | measurement_id = "G-42P6TDX7LH" 13 | # Get API secret from environment variable 14 | api_secret = "Z-CSzz9hSsK3MSaxJjB8sQ" 15 | 16 | if not api_secret: 17 | logger.error("API secret for Google Analytics not found. Please set the GA_API_SECRET environment variable.") 18 | return 19 | 20 | url = f"https://www.google-analytics.com/mp/collect?measurement_id={measurement_id}&api_secret={api_secret}" 21 | 22 | # Generate or retrieve a unique client ID for each user session 23 | if 'client_id' not in st.session_state: 24 | st.session_state['client_id'] = str(uuid.uuid4()) 25 | 26 | client_id = st.session_state['client_id'] 27 | logger.debug(f"Client ID: {client_id}") 28 | 29 | payload = { 30 | "client_id": client_id, 31 | "events": [{ 32 | "name": "app_start", 33 | "params": {} 34 | }] 35 | } 36 | 37 | headers = { 38 | 'Content-Type': 'application/json' 39 | } 40 | 41 | try: 42 | response = requests.post(url, json=payload, headers=headers) 43 | if response.status_code != 204: 44 | logger.error(f"Failed to log to Google Analytics: {response.content}") 45 | else: 46 | logger.info("Successfully logged to Google Analytics") 47 | except Exception as e: 48 | logger.error(f"Exception occurred while logging to Google Analytics: {e}") 49 | 50 | def compress_output_folder(output_folder_path, job_output_folder_name): 51 | import os 52 | import zipfile 53 | import io 54 | from loguru import logger 55 | 56 | # Create a ZIP file in memory 57 | zip_buffer = io.BytesIO() 58 | with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zipf: 59 | for root, dirs, files in os.walk(output_folder_path): 60 | for file in files: 61 | file_path = os.path.join(root, file) 62 | arcname = os.path.relpath(file_path, start=output_folder_path) 63 | zipf.write(file_path, arcname) 64 | zip_buffer.seek(0) 65 | logger.debug(f"Compressed output folder: {output_folder_path}") 66 | return zip_buffer.getvalue() 67 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | # simplified app.py for streamlit cloud 2 | 3 | import streamlit as st 4 | import json 5 | import re 6 | import os 7 | import sys 8 | from loguru import logger 9 | 10 | # Import your modules (make sure they are correctly installed in your environment) 11 | from afusion.execution import run_alphafold 12 | from afusion.sequence_input import ( 13 | collect_protein_sequence_data, 14 | collect_rna_sequence_data, 15 | collect_dna_sequence_data, 16 | collect_ligand_sequence_data 17 | ) 18 | from afusion.bonds import handle_bond 19 | from afusion.utils import compress_output_folder 20 | 21 | # Configure the logger 22 | logger.add("afusion.log", rotation="1 MB", level="DEBUG") 23 | 24 | def main(): 25 | # Set page configuration and theme 26 | st.set_page_config( 27 | page_title="AFusion: AlphaFold 3 GUI", 28 | page_icon="🧬", 29 | layout="wide", 30 | initial_sidebar_state="expanded", 31 | ) 32 | 33 | # Custom CSS styling 34 | st.markdown(""" 35 | 67 | """, unsafe_allow_html=True) 68 | 69 | # Title and subtitle 70 | st.markdown("

🔬 AFusion: AlphaFold 3 GUI

", unsafe_allow_html=True) 71 | st.markdown("

A convenient GUI for running AlphaFold 3 predictions

", unsafe_allow_html=True) 72 | st.markdown("

If this project helps you, please ⭐️ my project!

", unsafe_allow_html=True) 73 | 74 | #### Sidebar Navigation #### 75 | with st.sidebar: 76 | st.header("Navigation") 77 | st.sidebar.markdown("---") 78 | sections = { 79 | "Job Settings": "job_settings", 80 | "Sequences": "sequences", 81 | "Bonded Atom Pairs": "bonded_atom_pairs", 82 | "User Provided CCD": "user_ccd", 83 | "Generated JSON": "json_content", 84 | "Execution Settings": "execution_settings", 85 | "Run AlphaFold 3": "run_alphafold", 86 | } 87 | for section_name, section_id in sections.items(): 88 | st.markdown(f"{section_name}", unsafe_allow_html=True) 89 | st.markdown("---") 90 | st.markdown("Created by Hanzi 2024.", unsafe_allow_html=True) 91 | 92 | # Main Content 93 | st.markdown('
', unsafe_allow_html=True) 94 | st.markdown("### Welcome to AFusion!") 95 | st.markdown("Use this GUI to generate input JSON files and run AlphaFold 3 predictions with ease. Please [install AlphaFold 3](https://github.com/google-deepmind/alphafold3/blob/main/docs/installation.md) before using.") 96 | 97 | st.markdown('
', unsafe_allow_html=True) 98 | st.header("📝 Job Settings") 99 | with st.expander("Configure Job Settings", expanded=True): 100 | job_name = st.text_input("Job Name", value="My AlphaFold Job", help="Enter a descriptive name for your job.") 101 | logger.info(f"Job name set to: {job_name}") 102 | model_seeds = st.text_input("Model Seeds (comma-separated)", value="1,2,3", help="Provide integer seeds separated by commas.") 103 | logger.debug(f"Model seeds input: {model_seeds}") 104 | model_seeds_list = [int(seed.strip()) for seed in model_seeds.split(",") if seed.strip().isdigit()] 105 | if not model_seeds_list: 106 | st.error("Please provide at least one valid model seed.") 107 | logger.error("No valid model seeds provided.") 108 | st.stop() 109 | logger.info(f"Model seeds list: {model_seeds_list}") 110 | 111 | st.markdown('
', unsafe_allow_html=True) 112 | st.header("📄 Sequences") 113 | sequences = [] 114 | num_entities = st.number_input("Number of Entities", min_value=1, step=1, value=1, help="Select the number of entities you want to add.") 115 | logger.info(f"Number of entities set to: {num_entities}") 116 | 117 | for i in range(int(num_entities)): 118 | st.markdown(f"### Entity {i+1}") 119 | with st.expander(f"Entity {i+1} Details", expanded=True): 120 | entity_type = st.selectbox(f"Select Entity Type", ["Protein 🧬", "RNA 🧫", "DNA 🧬", "Ligand 💊"], key=f"entity_type_{i}") 121 | logger.info(f"Entity {i+1} type: {entity_type}") 122 | 123 | copy_number = st.number_input(f"Copy Number", min_value=1, step=1, value=1, key=f"copy_number_{i}", help="Specify the number of copies of this sequence.") 124 | logger.info(f"Entity {i+1} copy number: {copy_number}") 125 | 126 | # Collect sequence data 127 | if entity_type.startswith("Protein"): 128 | sequence_data = collect_protein_sequence_data(i) 129 | elif entity_type.startswith("RNA"): 130 | sequence_data = collect_rna_sequence_data(i) 131 | elif entity_type.startswith("DNA"): 132 | sequence_data = collect_dna_sequence_data(i) 133 | elif entity_type.startswith("Ligand"): 134 | sequence_data = collect_ligand_sequence_data(i) 135 | else: 136 | st.error(f"Unknown entity type: {entity_type}") 137 | logger.error(f"Unknown entity type: {entity_type}") 138 | continue # Skip to next entity 139 | 140 | # Handle IDs based on copy number 141 | entity_ids = [] 142 | if copy_number >= 1: 143 | # Allow user to input multiple IDs 144 | entity_id = st.text_input(f"Entity ID(s) (comma-separated)", key=f"entity_id_{i}", help="Provide entity ID(s), separated by commas if multiple.") 145 | if not entity_id.strip(): 146 | st.error("Entity ID is required.") 147 | logger.error("Entity ID missing.") 148 | continue 149 | entity_ids = re.split(r"\s*,\s*", entity_id) 150 | if len(entity_ids) != copy_number: 151 | st.error(f"Please provide {copy_number} ID(s) separated by commas.") 152 | logger.error(f"Number of IDs provided does not match copy number for Entity {i+1}.") 153 | continue 154 | logger.debug(f"Entity {i+1} IDs: {entity_ids}") 155 | 156 | for copy_id in entity_ids: 157 | # Clone the sequence data and set the ID 158 | sequence_entry = sequence_data.copy() 159 | sequence_entry['id'] = copy_id 160 | # Wrap the entry appropriately 161 | if entity_type.startswith("Protein"): 162 | sequences.append({"protein": sequence_entry}) 163 | elif entity_type.startswith("RNA"): 164 | sequences.append({"rna": sequence_entry}) 165 | elif entity_type.startswith("DNA"): 166 | sequences.append({"dna": sequence_entry}) 167 | elif entity_type.startswith("Ligand"): 168 | sequences.append({"ligand": sequence_entry}) 169 | else: 170 | st.error("Copy number must be at least 1.") 171 | logger.error("Invalid copy number.") 172 | continue 173 | 174 | st.markdown('
', unsafe_allow_html=True) 175 | st.header("🔗 Bonded Atom Pairs (Optional)") 176 | bonded_atom_pairs = [] 177 | add_bonds = st.checkbox("Add Bonded Atom Pairs") 178 | if add_bonds: 179 | num_bonds = st.number_input("Number of Bonds", min_value=1, step=1, key="num_bonds") 180 | for b in range(int(num_bonds)): 181 | st.markdown(f"**Bond {b+1}**") 182 | bond = handle_bond(b) 183 | if bond: 184 | bonded_atom_pairs.append(bond) 185 | logger.debug(f"Added bond: {bond}") 186 | 187 | st.markdown('
', unsafe_allow_html=True) 188 | st.header("🧩 User Provided CCD (Optional)") 189 | user_ccd = st.text_area("User CCD (mmCIF format)") 190 | if user_ccd: 191 | logger.debug("User provided CCD data.") 192 | 193 | # Generate JSON Data 194 | alphafold_input = { 195 | "name": job_name, 196 | "modelSeeds": model_seeds_list, 197 | "sequences": sequences, 198 | "dialect": "alphafold3", 199 | "version": 1 200 | } 201 | 202 | if bonded_atom_pairs: 203 | alphafold_input["bondedAtomPairs"] = bonded_atom_pairs 204 | 205 | if user_ccd: 206 | alphafold_input["userCCD"] = user_ccd 207 | 208 | # Convert JSON to string 209 | json_output = json.dumps(alphafold_input, indent=2) 210 | logger.debug(f"Generated JSON:\n{json_output}") 211 | 212 | st.markdown('
', unsafe_allow_html=True) 213 | st.header("📄 Generated JSON Content") 214 | st.code(json_output, language="json") 215 | 216 | st.markdown('
', unsafe_allow_html=True) 217 | st.header("⚙️ AlphaFold 3 Execution Settings") 218 | with st.expander("Configure Execution Settings", expanded=True): 219 | # Paths for execution 220 | af_input_path = st.text_input("AF Input Path", value=os.path.expanduser("~/af_input"), help="Path to AlphaFold input directory.") 221 | af_output_path = st.text_input("AF Output Path", value=os.path.expanduser("~/af_output"), help="Path to AlphaFold output directory.") 222 | model_parameters_dir = st.text_input("Model Parameters Directory", value="/path/to/models", help="Path to model parameters directory.") 223 | databases_dir = st.text_input("Databases Directory", value="/path/to/databases", help="Path to databases directory.") 224 | 225 | logger.debug(f"Execution settings: af_input_path={af_input_path}, af_output_path={af_output_path}, model_parameters_dir={model_parameters_dir}, databases_dir={databases_dir}") 226 | 227 | # Additional options 228 | run_data_pipeline = st.checkbox("Run Data Pipeline (CPU only, time-consuming)", value=True) 229 | run_inference = st.checkbox("Run Inference (requires GPU)", value=True) 230 | 231 | logger.info(f"Run data pipeline: {run_data_pipeline}, Run inference: {run_inference}") 232 | 233 | # Bucket Sizes Configuration 234 | use_custom_buckets = st.checkbox("Specify Custom Compilation Buckets", value=False) 235 | if use_custom_buckets: 236 | buckets_input = st.text_input( 237 | "Bucket Sizes (comma-separated)", 238 | value="256,512,768,1024,1280,1536,2048,2560,3072,3584,4096,4608,5120", 239 | help="Specify bucket sizes separated by commas. Example: 256,512,768,..." 240 | ) 241 | # Parse buckets 242 | bucket_sizes = [int(size.strip()) for size in buckets_input.split(",") if size.strip().isdigit()] 243 | if not bucket_sizes: 244 | st.error("Please provide at least one valid bucket size.") 245 | logger.error("No valid bucket sizes provided.") 246 | st.stop() 247 | logger.debug(f"Custom bucket sizes: {bucket_sizes}") 248 | else: 249 | bucket_sizes = [] # Empty list indicates default buckets 250 | 251 | st.markdown('
', unsafe_allow_html=True) 252 | st.header("🚀 Run AlphaFold 3") 253 | # Save JSON to file 254 | json_save_path = os.path.join(af_input_path, "fold_input.json") 255 | try: 256 | os.makedirs(af_input_path, exist_ok=True) 257 | with open(json_save_path, "w") as json_file: 258 | json.dump(alphafold_input, json_file, indent=2) 259 | st.success(f"JSON file saved to {json_save_path}") 260 | logger.info(f"JSON file saved to {json_save_path}") 261 | except Exception as e: 262 | st.error(f"Error saving JSON file: {e}") 263 | logger.error(f"Error saving JSON file: {e}") 264 | 265 | # Run AlphaFold 3 266 | if st.button("Run AlphaFold 3 Now ▶️"): 267 | # Build the Docker command 268 | docker_command = ( 269 | f"docker run --rm " 270 | f"--volume {af_input_path}:/root/af_input " 271 | f"--volume {af_output_path}:/root/af_output " 272 | f"--volume {model_parameters_dir}:/root/models " 273 | f"--volume {databases_dir}:/root/public_databases " 274 | f"--gpus all " 275 | f"alphafold3 " 276 | f"python run_alphafold.py " 277 | f"--json_path=/root/af_input/fold_input.json " 278 | f"--model_dir=/root/models " 279 | f"--output_dir=/root/af_output " 280 | f"{'--run_data_pipeline' if run_data_pipeline else ''} " 281 | f"{'--run_inference' if run_inference else ''} " 282 | f"{'--buckets ' + ','.join(map(str, bucket_sizes)) if bucket_sizes else ''}" 283 | ) 284 | 285 | st.markdown("#### Docker Command:") 286 | st.code(docker_command, language="bash") 287 | logger.debug(f"Docker command: {docker_command}") 288 | 289 | # Run the command and display output in a box 290 | with st.spinner('AlphaFold 3 is running...'): 291 | output_placeholder = st.empty() 292 | output = run_alphafold(docker_command, placeholder=output_placeholder) 293 | 294 | # Display the output in an expander box 295 | st.markdown("#### Command Output:") 296 | with st.expander("Show Command Output 📄", expanded=False): 297 | st.text_area("Command Output", value=output, height=400) 298 | 299 | logger.info("AlphaFold 3 execution completed.") 300 | 301 | # Check if the output directory exists 302 | job_output_folder_name = job_name.lower().replace(' ', '_') 303 | output_folder_path = os.path.join(af_output_path, job_output_folder_name) 304 | 305 | if os.path.exists(output_folder_path): 306 | st.success("AlphaFold 3 execution completed successfully.") 307 | st.info(f"Results are saved in: {output_folder_path}") 308 | logger.info(f"Results saved in: {output_folder_path}") 309 | 310 | # Provide download option 311 | st.markdown("### Download Results 📥") 312 | zip_data = compress_output_folder(output_folder_path, job_output_folder_name) 313 | st.download_button( 314 | label="Download ZIP", 315 | data=zip_data, 316 | file_name=f"{job_output_folder_name}.zip", 317 | mime="application/zip" 318 | ) 319 | logger.info("User downloaded the results ZIP file.") 320 | 321 | # Provide instructions to run the Visualization App 322 | st.markdown("### Visualize Your Results") 323 | st.write("To visualize your results, run the following command:") 324 | st.code(f"afusion visualization --output_folder_path '{output_folder_path}'", language="bash") 325 | st.write("Or launch the Visualization App and enter the output folder path.") 326 | logger.info("Provided instructions to the user to run the Visualization App.") 327 | 328 | else: 329 | st.error("AlphaFold 3 execution did not complete successfully. Please check the logs.") 330 | logger.error("AlphaFold 3 execution did not complete successfully.") 331 | else: 332 | st.info("Click the 'Run AlphaFold 3 Now ▶️' button to execute the command.") 333 | 334 | st.markdown("---") 335 | 336 | # Provide access to the log file 337 | st.markdown("### Download Log File 📥") 338 | with open('afusion.log', 'r') as log_file: 339 | log_content = log_file.read() 340 | st.download_button( 341 | label="Download Log File", 342 | data=log_content, 343 | file_name='afusion.log', 344 | mime='text/plain' 345 | ) 346 | 347 | # Display log content in the app 348 | with st.expander("Show Log Content 📄", expanded=False): 349 | st.text_area("Log Content", value=log_content, height=200) 350 | 351 | st.markdown("---") 352 | # Add footer 353 | st.markdown("

© 2024 Hanzi. All rights reserved.

", unsafe_allow_html=True) 354 | 355 | if __name__ == "__main__": 356 | main() 357 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | %SPHINXBUILD% >NUL 2>NUL 14 | if errorlevel 9009 ( 15 | echo. 16 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 17 | echo.installed, then set the SPHINXBUILD environment variable to point 18 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 19 | echo.may add the Sphinx directory to PATH. 20 | echo. 21 | echo.If you don't have Sphinx installed, grab it from 22 | echo.https://www.sphinx-doc.org/ 23 | exit /b 1 24 | ) 25 | 26 | if "%1" == "" goto help 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | streamlit 2 | pandas 3 | loguru 4 | numpy 5 | py3Dmol 6 | biopython 7 | plotly 8 | myst-parser 9 | furo 10 | -------------------------------------------------------------------------------- /docs/source/.conf.py.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hanziwww/AlphaFold3-GUI/b18760506a53e8799af2d1d285e36c37544768b6/docs/source/.conf.py.swp -------------------------------------------------------------------------------- /docs/source/api.md: -------------------------------------------------------------------------------- 1 | # API Documentation 2 | 3 | ```{eval-rst} 4 | .. automodule:: afusion.api 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # -- Project information ----------------------------------------------------- 2 | import os 3 | import sys 4 | sys.path.insert(0, os.path.abspath('../../')) 5 | 6 | 7 | project = 'AFusion' 8 | copyright = '2024, Hanzi' 9 | author = 'Hanzi' 10 | release = '1.2.2' 11 | 12 | # -- General configuration --------------------------------------------------- 13 | extensions = [ 14 | 'sphinx.ext.autodoc', 15 | 'myst_parser', 16 | ] 17 | # Enable Markdown support 18 | source_suffix = ['.rst', '.md'] 19 | autoclass_content = 'both' 20 | autodoc_member_order = 'bysource' 21 | 22 | templates_path = ['_templates'] 23 | exclude_patterns = [] 24 | 25 | 26 | 27 | # -- Options for HTML output ------------------------------------------------- 28 | # The theme to use for HTML and HTML Help pages. 29 | html_theme = 'furo' 30 | html_theme_options = { 31 | "sidebar_hide_name": False, # 确保页面名称显示在侧边栏 32 | } 33 | html_static_path = ['_static'] 34 | -------------------------------------------------------------------------------- /docs/source/index.md: -------------------------------------------------------------------------------- 1 | # 🔬 AFusion: AlphaFold 3 GUI & Toolkit 2 | 3 | ![image](https://github.com/user-attachments/assets/d1d894c7-c0cc-4218-9677-1917c1ad7b88) 4 | 5 | ## Introduction 6 | **AFusion** is a user-friendly graphical interface designed to simplify AlphaFold 3 usage, making advanced protein structure modeling accessible to everyone. Whether you prefer a GUI over command-line interactions or need an API for batch predictions, AFusion has you covered. 7 | 8 | [**Demo Site**](https://af3gui.streamlit.app/) *(generates input JSON files ONLY)* 9 | 10 | [**Usable visualization site**](https://af3vis.streamlit.app/) *(fully usable)* 11 | 12 | ## Features 13 | 14 | - **🧭 Guided Installation**: GUI-based installer to simplify the installation process, easily set up the application through step-by-step guidance. 15 | - **✨ Intuitive Interface**: Easily configure job settings, sequences, and execution parameters through a clean and modern GUI. 16 | - **📋 Entity Management**: Add multiple entities (Protein, RNA, DNA, Ligand) with support for modifications, MSA options, and templates. 17 | - **⚙️ Dynamic JSON Generation**: Automatically generates the required JSON input file for AlphaFold 3 based on user inputs. 18 | - **🚀 Integrated Execution**: Run AlphaFold 3 directly from the GUI with customizable Docker execution settings. 19 | - **🖥️ Visual Feedback**: Provides command output within the interface for monitoring and debugging. 20 | - **🖥️ Console Output**: Track processes and debug more effectively with backend console output. 21 | - **🧩 API for Batch Predictions**: Perform batch predictions using the AFusion API in Python scripts. 22 | 23 | ### **🌟 New Feature!** 24 | - **AlphaFold 3 Output Analysis System**: Automatically analyze and visualize results with customizable visualizations and generate detailed PDF reports for streamlined insights. 25 | 26 | ## Acknowledgements 27 | 28 | - **AlphaFold 3**: This GUI is designed to work with [AlphaFold 3](https://github.com/google-deepmind/alphafold3) by DeepMind. 29 | - **Streamlit**: AFusion is built using [Streamlit](https://streamlit.io/), an open-source app framework for machine learning and data science teams. 30 | - **Contributors**: Waiting for more! 31 | 32 | ```{toctree} 33 | :caption: Contents 34 | :maxdepth: 1 35 | 36 | installation 37 | tutorial 38 | api 39 | release 40 | ``` 41 | --- 42 | 43 | If you encounter any issues or have suggestions for improvements, please open an [issue](https://github.com/Hanziwww/AlphaFold3-GUI/issues) or submit a [pull request](https://github.com/Hanziwww/AlphaFold3-GUI/pulls). 44 | 45 | Happy Folding! 🧬 46 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to Afusion's Documentation! 2 | =================================== 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | :caption: Contents: 7 | 8 | installation 9 | tutorial 10 | api 11 | 12 | -------------------------------------------------------------------------------- /docs/source/installation.md: -------------------------------------------------------------------------------- 1 | # Installation Guide 2 | 3 | This section provides detailed instructions on how to install and set up AFusion and its prerequisites. 4 | 5 | ## Option 1: Install Using the Terminal 6 | 7 | Before installing AFusion, ensure that you have the following components installed on your system: 8 | 9 | ### 1. 🐳 Docker Installed 10 | 11 | - **Docker** is required to run AlphaFold 3. 12 | - **Installation**: Download and install Docker from the [official website](https://www.docker.com/get-started/). 13 | - **Post-Installation**: 14 | - Ensure Docker is running properly. 15 | - Verify that your user has permission to execute Docker commands. 16 | 17 | ### 2. 🧬 AlphaFold 3 Installed 18 | 19 | - AFusion requires **AlphaFold 3** to be installed and set up on your system. 20 | - **Installation Instructions**: 21 | - Follow the instructions provided in the [AlphaFold 3 GitHub Repository](https://github.com/google-deepmind/alphafold3) to install AlphaFold 3. 22 | - Make sure to download the model parameters and required databases. 23 | 24 | ### 3. 🐍 Python 3.10 or Higher 25 | 26 | - AFusion is built with Python and requires **Python 3.10** or higher. 27 | - **Installation**: 28 | - Download Python from the [official website](https://www.python.org/downloads/). 29 | - Alternatively, use a package manager like `apt`, `brew`, or `conda`. 30 | 31 | ## Option 2: Use the Guided GUI Installation 32 | 33 | Alternatively, you can use the guided GUI installation process provided by AFusion, which simplifies the installation steps through an interactive interface. 34 | 35 | - **Start the Installation GUI**: 36 | - Run the following command in your terminal: 37 | ```bash 38 | afusion install 39 | ``` 40 | - This command will launch the AFusion installation GUI, guiding you step-by-step through the process of installing Docker, AlphaFold 3, and Python if they are not already installed. 41 | 42 | By choosing Option 2, you can streamline the installation process with a user-friendly graphical interface that handles the setup for you. 43 | 44 | ## Installation and Running 45 | 46 | Follow these steps to install and launch AFusion: 47 | 48 | ### 1. Install AFusion 49 | 50 | Run the following command in your terminal to install AFusion: 51 | 52 | ```bash 53 | pip install afusion 54 | ``` 55 | 56 | - **Note**: This command will install AFusion and all its dependencies, including Streamlit. 57 | 58 | ### 2. Run AFusion GUI 59 | 60 | After installation, you can start AFusion by running: 61 | 62 | ```bash 63 | afusion run 64 | ``` 65 | 66 | - This command will launch the AFusion graphical user interface (GUI) in your default web browser. 67 | 68 | --- 69 | 70 | **Important Notes:** 71 | 72 | - **AlphaFold 3 Installation**: Ensure you have correctly installed AlphaFold 3, including model parameters and required databases, following the [AlphaFold 3 Installation Guide](https://github.com/google-deepmind/alphafold3/blob/main/docs/installation.md). 73 | - **Docker Configuration**: After installing Docker, make sure it is running properly and that your user has permission to execute Docker commands. 74 | - **Streamlit Dependency**: AFusion's installation will automatically install all required dependencies, including Streamlit. There's no need to install it separately. 75 | 76 | --- 77 | 78 | ## Troubleshooting 79 | 80 | If you encounter any issues during installation or usage, consider the following steps: 81 | 82 | - **Docker Issues**: 83 | - Ensure Docker is running. 84 | - On Linux, you might need to add your user to the `docker` group: 85 | 86 | ```bash 87 | sudo usermod -aG docker $USER 88 | ``` 89 | 90 | - Log out and log back in for the changes to take effect. 91 | 92 | - **Python Version**: 93 | - Verify your Python version: 94 | 95 | ```bash 96 | python --version 97 | ``` 98 | 99 | - If it's below 3.10, install the correct version. 100 | 101 | - **AlphaFold 3 Setup**: 102 | - Double-check that all paths and environment variables required by AlphaFold 3 are correctly set. 103 | 104 | - **Dependencies**: 105 | - If you have conflicting packages, consider using a virtual environment: 106 | 107 | ```bash 108 | python -m venv afusion_env 109 | source afusion_env/bin/activate 110 | ``` 111 | 112 | - Then install AFusion within this environment. 113 | 114 | --- 115 | 116 | For further assistance, please refer to the official documentation or [open an issue](https://github.com/your-repo/issues) on the GitHub repository. 117 | 118 | --- 119 | 120 | **Next Steps**: 121 | 122 | - Proceed to the [Usage Guide](index.md#usage) to learn how to use AFusion. 123 | - Explore the [API Documentation](api.md) for information on batch predictions (coming soon). 124 | 125 | --- 126 | 127 | **Happy Folding! 🧬** 128 | -------------------------------------------------------------------------------- /docs/source/release.md: -------------------------------------------------------------------------------- 1 | # Release Notes 2 | 3 | ## v1.2.1 "Visualization Optimized" (Release Date: November 23, 2024) 4 | 5 | ### Improvements 6 | 7 | - **Visualization Performance Optimization**: Enhanced the visualization module to improve rendering speed and reduce memory usage, enabling smoother analysis of large AlphaFold 3 output files. 8 | 9 | - **Stability Improvements**: Addressed minor bugs and improved the stability of the visualization tools, ensuring a seamless user experience during structure analysis. 10 | 11 | 12 | ## v1.2.0 "Visualization & Analysis" (Release Date: November 21, 2024) 13 | 14 | ### New Features 15 | 16 | - **Visualization Module**: Introduced a powerful visualization module for AlphaFold 3 results. Users can upload output files (e.g., `.pdb`, `.json`) to analyze predictions with detailed structure displays, customizable plots, and PDF report generation. 17 | 18 | - **Integrated Visualization**: The visualization tools are now seamlessly integrated into the prediction GUI, allowing users to switch to the visualization tab immediately after predictions are complete. 19 | 20 | - **Enhanced Output Analysis**: Added an automated AlphaFold 3 output analysis system that provides streamlined insights with customizable visualizations and detailed reports. 21 | 22 | - **Batch Prediction API Improvements**: Updated the batch prediction API to support visualization integration and enhanced error handling. 23 | 24 | ## v1.1.2 "Guided Installation" (Release Date: November 21, 2024) 25 | 26 | ### New Features 27 | 28 | - **Guided Installation**: Introduced a new GUI-based installer to simplify the installation process. Users can now easily set up the application through step-by-step guidance. 29 | 30 | - **CLI Launch**: Added command-line interface support, allowing users to start the application or installation process directly from the command line using the `afusion` command. 31 | 32 | --- 33 | 34 | Let me know if there's anything else I can help you with! 35 | ## v1.1.1 "Debug and Docs" (Release Date: November 20, 2024) 36 | 37 | ### New Features 38 | 39 | - **Documentation Update**: Created and improved project documentation, providing more detailed usage guidance and API descriptions. 40 | 41 | ### Bug Fixes 42 | 43 | - Resolved known issues, enhancing application stability and reliability. 44 | 45 | --- 46 | 47 | ## v1.1.0 "Console and API" (Release Date: November 19, 2024) 48 | 49 | ### New Features 50 | 51 | - **Console Output**: Integrated console output functionality, allowing users to view the running process in real-time within the interface for easier tracking and debugging. 52 | - **Batch Predictions API**: Added an API for AFusion, supporting batch predictions in Python scripts, increasing automation. 53 | 54 | ### Improvements 55 | 56 | - **Performance Optimization**: Improved application performance and stability, enhancing user experience. 57 | - **Interface Enhancements**: Made minor adjustments to the user interface for smoother and more user-friendly operation. 58 | 59 | --- 60 | 61 | ## v1.0.0 "Refactor" (Release Date: November 18, 2024) 62 | 63 | ### Overview 64 | 65 | AFusion v1.0.0 has been officially released. This marks our first stable version, featuring a complete codebase refactor for improved performance and reliability. 66 | 67 | ### Installation 68 | 69 | ```bash 70 | pip install afusion 71 | ``` 72 | 73 | ### Run 74 | 75 | ```bash 76 | afusion 77 | ``` 78 | 79 | ### Features 80 | 81 | - **Code Refactoring**: Comprehensive optimization of the codebase, improving maintainability and execution efficiency. 82 | - **Stability Enhancements**: Fixed issues from previous versions, significantly enhancing application stability. 83 | 84 | --- 85 | 86 | ## v0.2.2 "Python Package" (Release Date: November 17, 2024) 87 | 88 | ### New Features 89 | 90 | - **Released as a Python Package**: AFusion is now available as a Python package. Users can install and run it with a simple command, making it more convenient. 91 | 92 | ### Installation 93 | 94 | ```bash 95 | pip install afusion 96 | ``` 97 | 98 | ### Run 99 | 100 | ```bash 101 | afusion 102 | ``` 103 | 104 | --- 105 | 106 | ## v0.2.1 "Copies" (Release Date: November 16, 2024) 107 | 108 | ### New Features 109 | 110 | - **Copy Number Specification**: Users can now specify the number of copies for each sequence/entity, making it easy to create multiple copies of a sequence. Each copy can be assigned a unique ID, providing greater flexibility when setting up simulations. 111 | - **Enhanced ID Handling**: Maintained the original functionality where multiple IDs can be specified separated by commas (e.g., `A,B`), while adding the option to explicitly specify the number of copies, offering more customization possibilities. 112 | 113 | ### Improvements 114 | 115 | - **User Interface Improvements**: Optimized the interface design to make the application more intuitive and user-friendly. 116 | - **Performance Enhancements**: Fixed minor issues to enhance stability and performance. 117 | 118 | --- 119 | 120 | ## v0.2.0 "New Features" (Release Date: November 15, 2024) 121 | 122 | ### New Features 123 | 124 | 1. **Run Completion Detection** 125 | 126 | - **Automatic Success Check**: After running AlphaFold 3, the application now automatically checks whether the prediction completed successfully. 127 | - **Output Folder Verification**: Verifies the existence of the output directory named after your job (based on the name field in your input) to ensure results are generated. 128 | - **User Feedback**: Upon successful completion, a confirmation message is displayed along with the path to the results. 129 | 130 | 2. **Download Results as ZIP** 131 | 132 | - **In-App Download Option**: Users can now download the prediction results directly from the app without needing to access the server filesystem. 133 | - **Automatic Compression**: Compresses the output folder into a ZIP file for quick and efficient downloads. 134 | - **Seamless Integration**: The download button appears immediately after a successful run, streamlining the workflow. 135 | 136 | ### Important Notes 137 | 138 | - **Ensure Correct Paths**: Before running, double-check that all directory paths in the execution settings are accurate and accessible by the application. 139 | - **Docker Requirements**: The application runs AlphaFold 3 within a Docker container. Ensure that Docker and AlphaFold 3 are installed and properly configured on your system. 140 | - **Permissions**: The application needs appropriate permissions to read and write to the specified directories. 141 | 142 | --- 143 | 144 | ## v0.1.1 "Flag Bucket" (Release Date: November 14, 2024) 145 | 146 | ### New Features 147 | 148 | - **Compilation Buckets Configuration** 149 | 150 | - **Custom Bucket Sizes**: AFusion now supports specifying custom compilation bucket sizes introduced in AlphaFold 3. Users can define bucket sizes that match the input sequence lengths, reducing unnecessary model recompilations and improving performance. 151 | - **Usage**: 152 | 1. **Enable Custom Buckets**: In the "AlphaFold 3 Execution Settings" section, check the "Specify Custom Compilation Buckets" option. 153 | 2. **Input Bucket Sizes**: Provide a list of bucket sizes separated by commas in the "Bucket Sizes (comma-separated)" field, e.g., `256,512,768,1024`. 154 | 3. **Run**: Review the generated Docker command to confirm it includes the `--buckets` flag, then click "Run AlphaFold 3 Now" to execute the prediction. 155 | - **Benefits**: 156 | - **Performance Optimization**: Matching bucket sizes to input sequences minimizes padding and reduces the number of model recompilations. 157 | - **Flexibility**: Customize bucket sizes to handle a diverse range of input lengths, ensuring efficient processing. 158 | 159 | ### Improvements 160 | 161 | - **User Interface Updates**: Adjusted the execution settings section to include the new compilation buckets configuration in an intuitive manner. Provided helpful tooltips and validation messages to guide users through the new settings. 162 | 163 | --- 164 | 165 | ## v0.1.0 "First Release" (Release Date: November 13, 2024) 166 | 167 | ### Overview 168 | 169 | AFusion v0.1.0 has been released, providing a user-friendly graphical interface for AlphaFold 3. It simplifies the prediction process, making it accessible to users who are not familiar with command-line interactions. 170 | 171 | ### Features 172 | 173 | - **Intuitive Interface**: Easily configure job settings, sequences, and execution parameters through a clean and modern GUI. 174 | - **Entity Management**: Add multiple entities (Protein, RNA, DNA, Ligand) with support for modifications, MSA options, and templates. 175 | - **Dynamic JSON Generation**: Automatically generates the required JSON input file for AlphaFold 3 based on user inputs. 176 | - **Integrated Execution**: Run AlphaFold 3 directly from the GUI with customizable Docker execution settings. 177 | 178 | --- 179 | -------------------------------------------------------------------------------- /docs/source/tutorial.md: -------------------------------------------------------------------------------- 1 | # AlphaFold3 Batch Predictions with `afusion.api` 2 | 3 | ## Introduction 4 | 5 | This tutorial demonstrates how to use the `afusion.api` module to create batch tasks from a pandas DataFrame and run batch predictions using AlphaFold. We'll guide you through the entire process—from preparing your data to interpreting the results—using a minimal example with protein sequences. 6 | 7 | **Prerequisites**: 8 | 9 | - Python 3.10 or higher 10 | - AlphaFold 3 installed and configured 11 | - The `afusion` package installed 12 | - Basic knowledge of Python and pandas 13 | 14 | --- 15 | 16 | ## 1. Import Necessary Modules 17 | 18 | Begin by importing the required modules: 19 | 20 | ```python 21 | import pandas as pd 22 | from afusion.api import create_tasks_from_dataframe, run_batch_predictions 23 | ``` 24 | 25 | - **`pandas`**: Used for data manipulation and analysis. 26 | - **`afusion.api`**: Contains the functions we'll use to create tasks and run predictions. 27 | 28 | --- 29 | 30 | ## 2. Prepare the Data 31 | 32 | We'll create a pandas DataFrame containing the necessary information for our batch predictions. In this example, we'll predict the structure of a minimal protein sequence for two jobs. 33 | 34 | ```python 35 | # Define the DataFrame for the test 36 | data = { 37 | 'job_name': ['TestJob1', 'TestJob1', 'TestJob2'], 38 | 'type': ['protein', 'protein', 'protein'], 39 | 'id': ['A', 'B', 'A'], # Entity IDs 40 | 'sequence': ['MVLSPADKTNVKAAW', 'MVLSPADKTNVKAAW', 'MVLSPADKTNVKAAW'], # Protein sequences 41 | # No modifications or optional parameters in this example 42 | } 43 | 44 | df = pd.DataFrame(data) 45 | ``` 46 | 47 | Let's display the DataFrame to verify its contents: 48 | 49 | ```python 50 | df 51 | ``` 52 | 53 | **Output**: 54 | 55 | | | job_name | type | id | sequence | 56 | |----|----------|---------|------|-----------------| 57 | | 0 | TestJob1 | protein | A | MVLSPADKTNVKAAW | 58 | | 1 | TestJob1 | protein | B | MVLSPADKTNVKAAW | 59 | | 2 | TestJob2 | protein | A | MVLSPADKTNVKAAW | 60 | 61 | **Explanation**: 62 | 63 | - **`job_name`**: Specifies the name of the job. `TestJob1` has two entities, while `TestJob2` has one. 64 | - **`type`**: Indicates the entity type; all are proteins in this case. 65 | - **`id`**: Identifier for each entity. 66 | - **`sequence`**: The protein sequences to be predicted. 67 | 68 | --- 69 | 70 | ## 3. Create Tasks from the DataFrame 71 | 72 | We will use the `create_tasks_from_dataframe` function to convert our DataFrame into a list of task dictionaries suitable for AlphaFold predictions. 73 | 74 | ```python 75 | # Create tasks from DataFrame 76 | tasks = create_tasks_from_dataframe(df) 77 | ``` 78 | 79 | This function processes the DataFrame and creates tasks based on the parameters provided. 80 | 81 | Let's inspect the tasks generated: 82 | 83 | ```python 84 | tasks 85 | ``` 86 | 87 | **Output**: 88 | 89 | ```python 90 | [ 91 | { 92 | 'name': 'TestJob1', 93 | 'modelSeeds': [1], 94 | 'sequences': [ 95 | { 96 | 'protein': { 97 | 'sequence': 'MVLSPADKTNVKAAW', 98 | 'unpairedMsa': None, 99 | 'pairedMsa': None, 100 | 'templates': [], 101 | 'id': 'A' 102 | } 103 | }, 104 | { 105 | 'protein': { 106 | 'sequence': 'MVLSPADKTNVKAAW', 107 | 'unpairedMsa': None, 108 | 'pairedMsa': None, 109 | 'templates': [], 110 | 'id': 'B' 111 | } 112 | } 113 | ], 114 | 'dialect': 'alphafold3', 115 | 'version': 1 116 | }, 117 | { 118 | 'name': 'TestJob2', 119 | 'modelSeeds': [1], 120 | 'sequences': [ 121 | { 122 | 'protein': { 123 | 'sequence': 'MVLSPADKTNVKAAW', 124 | 'unpairedMsa': None, 125 | 'pairedMsa': None, 126 | 'templates': [], 127 | 'id': 'A' 128 | } 129 | } 130 | ], 131 | 'dialect': 'alphafold3', 132 | 'version': 1 133 | } 134 | ] 135 | ``` 136 | 137 | **Explanation**: 138 | 139 | - **`name`**: Corresponds to `job_name` in the DataFrame. 140 | - **`modelSeeds`**: List of model seeds; defaults to `[1]` if not specified. 141 | - **`sequences`**: Contains the sequences and related data for each entity. 142 | - **`protein`**: Dictionary with the protein sequence and optional parameters. 143 | - **`sequence`**: The protein sequence. 144 | - **`unpairedMsa`, `pairedMsa`, `templates`**: Set to `None` or empty lists as we didn't specify them. 145 | - **`id`**: Entity ID. 146 | - **`dialect`**: Specifies the AlphaFold version; set to `'alphafold3'`. 147 | - **`version`**: Version number; set to `1`. 148 | 149 | --- 150 | 151 | ## 4. Configure Paths 152 | 153 | Before running predictions, specify the input and output directories, as well as the locations of the model parameters and databases. 154 | 155 | ```python 156 | # Path configurations (update these paths as needed) 157 | af_input_base_path = "/path/to/af_input" 158 | af_output_base_path = "/path/to/af_output" 159 | model_parameters_dir = "/path/to/model_parameters" # Update with the correct path 160 | databases_dir = "/path/to/databases" # Update with the correct path 161 | ``` 162 | 163 | **Note**: Replace `"/path/to/..."` with the actual paths on your system. 164 | 165 | Ensure that the directories exist: 166 | 167 | ```python 168 | import os 169 | 170 | os.makedirs(af_input_base_path, exist_ok=True) 171 | os.makedirs(af_output_base_path, exist_ok=True) 172 | ``` 173 | 174 | --- 175 | 176 | ## 5. Run Batch Predictions 177 | 178 | Now, run the batch predictions using the `run_batch_predictions` function. 179 | 180 | ```python 181 | # Run batch predictions 182 | results = run_batch_predictions( 183 | tasks=tasks, 184 | af_input_base_path=af_input_base_path, 185 | af_output_base_path=af_output_base_path, 186 | model_parameters_dir=model_parameters_dir, 187 | databases_dir=databases_dir, 188 | run_data_pipeline=False, # Set to True to run the data pipeline 189 | run_inference=False, # Set to True to run inference (requires GPU) 190 | ) 191 | ``` 192 | 193 | **Parameters**: 194 | 195 | - **`tasks`**: The list of tasks generated from the DataFrame. 196 | - **`af_input_base_path`**: Base directory for AlphaFold input files. 197 | - **`af_output_base_path`**: Base directory for AlphaFold output files. 198 | - **`model_parameters_dir`**: Directory containing the model parameters. 199 | - **`databases_dir`**: Directory containing the required databases. 200 | - **`run_data_pipeline`**: Whether to run the data pipeline (`True` or `False`). 201 | - **`run_inference`**: Whether to run inference (`True` if you have a GPU). 202 | 203 | **Important**: For this minimal test, we set `run_data_pipeline` and `run_inference` to `False`. In a real prediction scenario, you should set these to `True`. 204 | 205 | --- 206 | 207 | ## 6. Interpret the Results 208 | 209 | After running the predictions, process and print the results: 210 | 211 | ```python 212 | # Process and print results 213 | for result in results: 214 | print(f"Job Name: {result['job_name']}") 215 | print(f"Output Folder: {result['output_folder']}") 216 | print(f"Status: {result['status']}") 217 | print("---") 218 | ``` 219 | 220 | **Sample Output**: 221 | 222 | ``` 223 | Job Name: TestJob1 224 | Output Folder: /path/to/af_output 225 | Status: Success 226 | --- 227 | Job Name: TestJob2 228 | Output Folder: /path/to/af_output 229 | Status: Success 230 | --- 231 | ``` 232 | 233 | **Explanation**: 234 | 235 | - **`job_name`**: The name of the job. 236 | - **`output_folder`**: The directory where the output files are stored. 237 | - **`status`**: The status of the prediction (`'Success'` or an error message). 238 | 239 | --- 240 | 241 | ## 7. Notes and Considerations 242 | 243 | - **System Configuration**: This example was run on a system with the following configuration: 244 | - CPU: Xeon Silver 4410T 245 | - GPU: NVIDIA RTX 4090 246 | - Operating System: Ubuntu Server 24.04 LTS 247 | 248 | **Note**: Your hardware configuration can significantly affect the performance and runtime of AlphaFold predictions. Ensure that your system meets the necessary requirements, especially regarding GPU capabilities. 249 | 250 | - **GPU Requirement**: AlphaFold predictions require substantial computational resources and are optimized for GPUs. Ensure that your system meets the hardware requirements if you plan to run actual predictions. 251 | 252 | - **Database Availability**: The databases specified in `databases_dir` are essential for AlphaFold's operation. Make sure that you have downloaded and correctly configured all necessary databases. 253 | 254 | - **Model Parameters**: The `model_parameters_dir` should contain the AlphaFold model parameters. Ensure that you have obtained these parameters and placed them in the specified directory. 255 | 256 | - **Adjusting Parameters**: Depending on your use case, you may need to adjust additional parameters such as `model_seeds`, `msa_option`, and others. Refer to the `afusion.api` documentation for more details. 257 | 258 | - **Error Handling**: The `run_batch_predictions` function returns a list of results with status messages. If any job fails, the status will contain the error message, which can be used for debugging. 259 | 260 | --- 261 | 262 | ## Conclusion 263 | 264 | In this tutorial, we demonstrated how to use the `afusion.api` module to create batch tasks from a pandas DataFrame and run batch predictions using AlphaFold. By following these steps, you can streamline the process of setting up and executing multiple predictions, making it efficient to handle large-scale protein structure predictions. 265 | 266 | --- 267 | 268 | ## Additional Resources 269 | 270 | - **AlphaFold GitHub Repository**: [https://github.com/deepmind/alphafold](https://github.com/deepmind/alphafold) 271 | 272 | --- 273 | 274 | **Disclaimer**: Ensure that you comply with all licensing and usage terms when using AlphaFold and associated data. 275 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | streamlit 2 | pandas 3 | loguru 4 | numpy 5 | py3Dmol 6 | biopython 7 | plotly 8 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | setup( 4 | name='afusion', 5 | version='1.2.2.2', 6 | author='Han Wang', 7 | author_email='marspenman@gmail.com', 8 | description='AFusion: AlphaFold 3 GUI & Toolkit with Visualization', 9 | long_description=open('README.md', encoding='utf-8').read(), 10 | long_description_content_type='text/markdown', 11 | url='https://github.com/Hanziwww/AlphaFold3-GUI', 12 | packages=find_packages(include=['afusion', 'afusion.*']), 13 | include_package_data=True, 14 | install_requires=[ 15 | 'streamlit', 16 | 'pandas', 17 | 'loguru', 18 | 'numpy', 19 | 'py3Dmol', 20 | 'biopython', 21 | 'plotly', 22 | ], 23 | entry_points={ 24 | 'console_scripts': [ 25 | 'afusion = afusion.cli:main', 26 | ], 27 | }, 28 | classifiers=[ 29 | 'Programming Language :: Python :: 3', 30 | 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 31 | 'Operating System :: POSIX :: Linux', 32 | ], 33 | python_requires='>=3.10', 34 | ) 35 | --------------------------------------------------------------------------------