Skip to content

Commit

Permalink
Use linter/formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
padix-key committed Jul 23, 2024
1 parent 66c80ea commit 84d6f92
Show file tree
Hide file tree
Showing 23 changed files with 876 additions and 827 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ htmlcov
# Ignore all compiled python files (e.g. from running the unit tests)
*.pyc
*.pyo
*.py{}
*.py-e

# Ignore files created via Cython
Expand Down
60 changes: 32 additions & 28 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,40 @@
try:
import numpy as np
import pyximport

pyximport.install(
build_in_temp=False,
setup_args={"include_dirs":np.get_include()},
language_level=3
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

# 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 +65,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):

#
#
########################################################################
########################################################################
23 changes: 9 additions & 14 deletions doc/figure_scripts/cover_structure.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import numpy as np
import pyximport

pyximport.install(
build_in_temp=False,
setup_args={"include_dirs":np.get_include()},
language_level=3
build_in_temp=False, setup_args={"include_dirs": np.get_include()}, language_level=3
)

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

import hydride

pdbx_file = pdbx.BinaryCIFFile.read(rcsb.fetch("1bna", "bcif"))
heavy_atoms = pdbx.get_structure(
Expand Down Expand Up @@ -42,9 +40,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 @@ -55,9 +51,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)
6 changes: 3 additions & 3 deletions doc/figure_scripts/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from matplotlib.colors import to_rgb
import ammolite
from matplotlib.colors import to_rgb


def init_pymol_parameters():
Expand All @@ -20,5 +20,5 @@ def init_pymol_parameters():
"N": to_rgb("#0a6efd"),
"O": to_rgb("#e1301d"),
"P": to_rgb("#098a07"),
#df059e
}
# df059e
}
Loading

0 comments on commit 84d6f92

Please sign in to comment.