Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JAX for relaxation #11

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macos-11]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
auto-update-conda: true
python-version: '3.11'
- name: Installing dependencies
run: conda install -c conda-forge sphinx cython numpy numpydoc biotite
run: conda install -c conda-forge sphinx numpy numpydoc biotite
- name: Building documentation
run: sphinx-build ./doc ./build/doc
- name: Zipping documentation
Expand Down
9 changes: 2 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ htmlcov
# Ignore all compiled python files (e.g. from running the unit tests)
*.pyc
*.pyo
*.py{}
*.py-e

# Ignore files created via Cython
*.c
*.so
*.pyd

# Ignore potential directory created during install
*.egg-info

Expand All @@ -42,5 +36,6 @@ htmlcov
*.code-workspace
.vscode/*

# Ignore fuse_hidden files on Linux systems
# Ignore OS specific files
*.fuse_hidden*
.DS_Store
6 changes: 2 additions & 4 deletions doc/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Structure input and output

``--infile``/``-i`` and ``-outfile``/``-o`` define the paths of the input or
output structure file, respectively.
*Hydride* supports the *PDB*, *PDBx/mmCIF*, *MMTF*, *MOL* and *SDF*
*Hydride* supports the *PDB*, *PDBx/mmCIF*, *BinaryCIF*, *MOL* and *SDF*
format.
By default, the format is determined from the file extension, but it can also
be explicitly provided via the ``--informat``/``-I`` or
Expand All @@ -38,8 +38,6 @@ used is specified with ``--model``/``-m``. By default, the first model is used.

The addition of hydrogen atoms requires complete information about the
bonds between atoms.
Currently, this information can only be read from *PDB*, *MMTF*, *MOL* and
*SDF* files.
If bond information is absent, *Hydride* automatically connects
atoms based on the molecule/residue name and the atom names.
However, the automatic bond detection only works for molecules in the
Expand Down Expand Up @@ -97,7 +95,7 @@ libraries by providing a path to a corresponding structure file via
Analogous to the input and output file parameters, the file format can be
specified with ``--fragformat``/``-f``.
Note that the file must contain proper bond information and correct formal
charges, so effectively a *MMTF*, *MOL* and *SDF* must be supplied.
charges.

By default, *Hydride* does not consider periodic boundary conditions,
as they appear e.g. in MD simulations.
Expand Down
68 changes: 30 additions & 38 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,31 @@

__author__ = "Patrick Kunzmann"

try:
import numpy as np
import pyximport
pyximport.install(
build_in_temp=False,
setup_args={"include_dirs":np.get_include()},
language_level=3
)
except ImportError:
pass

from os.path import realpath, dirname, join, isdir, isfile, basename
from os import listdir, makedirs
import sys
from os.path import dirname, join, realpath

doc_path = dirname(realpath(__file__))
# Include hydride/src in PYTHONPATH
# in order to import the 'hydride' package
package_path = join(dirname(doc_path), "src")
sys.path.insert(0, package_path)
import hydride
import hydride # noqa: E402

# Include gecos/doc in PYTHONPATH
# in order to import modules for plot genaration etc.
sys.path.insert(0, doc_path)


#### General ####

extensions = ["sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.doctest",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"numpydoc"]
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.doctest",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"numpydoc",
]

templates_path = ["templates"]
source_suffix = [".rst"]
Expand All @@ -62,25 +53,26 @@

html_theme = "alabaster"
html_static_path = ["static"]
html_css_files = [
"hydride.css",
"fonts.css"
]
html_css_files = ["hydride.css", "fonts.css"]
html_favicon = "static/assets/hydride_icon_32p.png"
htmlhelp_basename = "HydrideDoc"
html_sidebars = {"**": ["about.html",
"navigation.html",
"relations.html",
"searchbox.html",
"donate.html"]}
html_sidebars = {
"**": [
"about.html",
"navigation.html",
"relations.html",
"searchbox.html",
"donate.html",
]
}
html_theme_options = {
"description" : "Adding hydrogen atoms to molecular models",
"logo" : "assets/hydride_logo.png",
"logo_name" : "false",
"github_user" : "biotite-dev",
"github_repo" : "hydride",
"github_type" : "star",
"github_banner" : "true",
"page_width" : "85%",
"fixed_sidebar" : "true"
"description": "Adding hydrogen atoms to molecular models",
"logo": "assets/hydride_logo.png",
"logo_name": "false",
"github_user": "biotite-dev",
"github_repo": "hydride",
"github_type": "star",
"github_banner": "true",
"page_width": "85%",
"fixed_sidebar": "true",
}
15 changes: 8 additions & 7 deletions doc/figure_scripts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
"""

import tempfile
import ammolite
import biotite.structure as struc
import biotite.structure.io.mol as mol
import biotite.structure.info as info
import ammolite
import biotite.structure.io.mol as mol
from util import COLORS, init_pymol_parameters


ZOOM = 1.5
PNG_SIZE = (400, 400)

Expand Down Expand Up @@ -63,7 +62,7 @@ def color_atoms(pymol_object, atom_array):

print("\nEND OF SNIPPET\n")
pymol_heavy = ammolite.PyMOLObject.from_structure(molecule, "heavy")
#pymol_heavy.orient()
# pymol_heavy.orient()
pymol_heavy.zoom(buffer=ZOOM)
color_atoms(pymol_heavy, molecule)
ammolite.cmd.png("api_01.png", *PNG_SIZE)
Expand Down Expand Up @@ -168,9 +167,10 @@ def color_atoms(pymol_object, atom_array):


print("\nEND OF SNIPPET\n", end="")
import matplotlib.pyplot as plt
import matplotlib as mpl
plt.rcParams['axes.prop_cycle'] = mpl.cycler(color=[COLORS["N"]])
import matplotlib.pyplot as plt

plt.rcParams["axes.prop_cycle"] = mpl.cycler(color=[COLORS["N"]])


########################################################################
Expand Down Expand Up @@ -201,6 +201,7 @@ def color_atoms(pymol_object, atom_array):
fig.savefig("api_04.png")

import biotite.structure.info as info

molecule = info.residue("ASP")


Expand Down Expand Up @@ -229,4 +230,4 @@ def color_atoms(pymol_object, atom_array):

#
#
########################################################################
########################################################################
35 changes: 11 additions & 24 deletions doc/figure_scripts/cover_structure.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import numpy as np
import pyximport
pyximport.install(
build_in_temp=False,
setup_args={"include_dirs":np.get_include()},
language_level=3
)

from os.path import join
import numpy as np
import biotite.structure as struc
import biotite.structure.io.mmtf as mmtf
import biotite.database.rcsb as rcsb
import hydride
import ammolite
import biotite.database.rcsb as rcsb
import biotite.structure as struc
import biotite.structure.io.pdbx as pdbx
import numpy as np
from util import COLORS, init_pymol_parameters
import hydride


mmtf_file = mmtf.MMTFFile.read(rcsb.fetch("1bna", "mmtf"))
heavy_atoms = mmtf.get_structure(
mmtf_file, model=1, include_bonds=True, extra_fields=["charge"]
pdbx_file = pdbx.BinaryCIFFile.read(rcsb.fetch("1bna", "bcif"))
heavy_atoms = pdbx.get_structure(
pdbx_file, model=1, include_bonds=True, extra_fields=["charge"]
)
heavy_atoms = heavy_atoms[heavy_atoms.res_name != "HOH"]

Expand All @@ -43,9 +33,7 @@
pymol_all.zoom(buffer=1.0)
ammolite.cmd.rotate("z", 90)

for pymol_object, atoms in zip(
(pymol_heavy, pymol_all), (heavy_atoms, all_atoms)
):
for pymol_object, atoms in zip((pymol_heavy, pymol_all), (heavy_atoms, all_atoms)):
for element in ("H", "C", "N", "O", "P"):
pymol_object.color(COLORS[element], atoms.element == element)

Expand All @@ -56,9 +44,8 @@
pymol_heavy.disable()
pymol_all.enable()
for i, (_, atom_i, atom_j) in enumerate(bonds):
color = COLORS["N"] if all_atoms.element[atom_j] == "N"\
else COLORS["O"]
color = COLORS["N"] if all_atoms.element[atom_j] == "N" else COLORS["O"]
pymol_all.distance(str(i), atom_i, atom_j, show_label=False)
ammolite.cmd.set_color(f"bond_color_{i}", list(color))
ammolite.cmd.color(f"bond_color_{i}", str(i))
ammolite.cmd.png("cover_hydrogenated.png", 400, 800)
ammolite.cmd.png("cover_hydrogenated.png", 400, 800)
29 changes: 15 additions & 14 deletions doc/figure_scripts/fragments.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import time
from os.path import join, abspath, dirname
import numpy as np
from sklearn.decomposition import PCA
from os.path import abspath, dirname, join
import ammolite
import biotite.structure as struc
import biotite.structure.io.mol as mol
import ammolite
import numpy as np
from util import COLORS, init_pymol_parameters


PNG_SIZE = (300, 300)
ZOOM = 3.5
MOL_DIR = dirname(abspath(__file__))
Expand All @@ -20,17 +17,18 @@ def load_and_orient(mol_name):
molecule.coord -= struc.centroid(molecule)
return molecule

benzene = load_and_orient("benzene")

benzene = load_and_orient("benzene")
butylene = load_and_orient("isobutylene")
toluene = load_and_orient("toluene")
toluene = load_and_orient("toluene")
benzene_heavy, butylene_heavy, toluene_heavy = [
atoms[atoms.element != "H"] for atoms in (benzene, butylene, toluene)
]


init_pymol_parameters()

center = struc.array([struc.Atom([0,0,0], atom_name="C", element="C")])
center = struc.array([struc.Atom([0, 0, 0], atom_name="C", element="C")])
center.bonds = struc.BondList(1)
CENTER = ammolite.PyMOLObject.from_structure(center, "center_")
ammolite.cmd.disable("center_")
Expand All @@ -41,7 +39,9 @@ def load_and_orient(mol_name):
ammolite.cmd.png("toluene.png", *PNG_SIZE)
ammolite.cmd.disable("toluene")

pymol_toluene_heavy = ammolite.PyMOLObject.from_structure(toluene_heavy, "toluene_heavy")
pymol_toluene_heavy = ammolite.PyMOLObject.from_structure(
toluene_heavy, "toluene_heavy"
)
CENTER.zoom(buffer=ZOOM)
pymol_toluene_heavy.color(COLORS["O"])
ammolite.cmd.png("toluene_heavy.png", *PNG_SIZE)
Expand Down Expand Up @@ -70,7 +70,7 @@ def visualize_fragments(molecule, mol_name, color):
fragment = molecule[np.append(bonded_i, [i])]
fragment_name = f"{mol_name}_frag_{frag_num:02d}"
frag_num += 1

pymol_fragment = ammolite.PyMOLObject.from_structure(
fragment, fragment_name
)
Expand All @@ -80,6 +80,7 @@ def visualize_fragments(molecule, mol_name, color):
ammolite.cmd.png(f"{fragment_name}.png", *PNG_SIZE)
ammolite.cmd.disable(fragment_name)

visualize_fragments(toluene_heavy, "toluene", COLORS["O"])
visualize_fragments(benzene, "benzene", COLORS["N"])
visualize_fragments(butylene, "butylene", COLORS["N"])

visualize_fragments(toluene_heavy, "toluene", COLORS["O"])
visualize_fragments(benzene, "benzene", COLORS["N"])
visualize_fragments(butylene, "butylene", COLORS["N"])
24 changes: 10 additions & 14 deletions doc/figure_scripts/rotation_freedom.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import time
from os.path import join, abspath, dirname
import numpy as np
from sklearn.decomposition import PCA
from os.path import abspath, dirname, join
import ammolite
import biotite.structure as struc
import biotite.structure.io.mol as mol
import ammolite
import numpy as np
from util import COLORS, init_pymol_parameters


PNG_SIZE = (300, 300)
ZOOM = 1.0
MOL_DIR = dirname(abspath(__file__))
Expand All @@ -20,14 +17,15 @@ def load_and_orient(mol_name):
molecule.coord -= struc.centroid(molecule)
return molecule

propane = load_and_orient("propane")

propane = load_and_orient("propane")


ammolite.launch_interactive_pymol()

init_pymol_parameters()

center = struc.array([struc.Atom([0,0,0], atom_name="C", element="C")])
center = struc.array([struc.Atom([0, 0, 0], atom_name="C", element="C")])
center.bonds = struc.BondList(1)
CENTER = ammolite.PyMOLObject.from_structure(center, "center_")
ammolite.cmd.disable("center_")
Expand All @@ -37,12 +35,10 @@ def load_and_orient(mol_name):
bonded_i = all_bonds[carbon_i]
bonded_i = bonded_i[bonded_i != -1]
fragment = propane[np.append(bonded_i, [carbon_i])]

pymol_fragment = ammolite.PyMOLObject.from_structure(
fragment, name, delete=False
)

pymol_fragment = ammolite.PyMOLObject.from_structure(fragment, name, delete=False)
CENTER.zoom(buffer=ZOOM)
pymol_fragment.color(COLORS["C"], fragment.element != "H")
pymol_fragment.color(COLORS["N"], -1)
#ammolite.cmd.png(f"{name}.png", *PNG_SIZE)
#ammolite.cmd.disable(name)
# ammolite.cmd.png(f"{name}.png", *PNG_SIZE)
# ammolite.cmd.disable(name)
Loading
Loading