Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Augus1999 authored Jul 15, 2022
1 parent 7dab30c commit f095c78
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 57 deletions.
12 changes: 6 additions & 6 deletions mol2chemfigPy3/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
define Atom object
"""
import string
from typing import Optional, Union
from typing import Optional, Union, Dict, List, Tuple
from . import chemfig_mappings as cfm

# some atoms should carry their hydrogen to the left, rather than
Expand Down Expand Up @@ -43,15 +43,15 @@ class Atom:

def __init__(
self,
options: dict,
options: Dict,
idx: int,
x: Union[int, float],
y: Union[int, float],
element: Optional[str],
hydrogens: Optional[int],
charge: int,
radical: int,
neighbors: list[int],
neighbors: List[int],
):
self.options = options
self.idx = idx
Expand Down Expand Up @@ -91,7 +91,7 @@ def _score_angle(a: int, b: int, turf: int) -> int:
angle = min(diff, 360 - diff)
return (max(0, turf - angle)) ** 2

def _score_angles(self, choices: list[list[int, int, str]], turf: int) -> list[str]:
def _score_angles(self, choices: List[List], turf: int) -> List[str]:
"""
backend for score_angles
Expand Down Expand Up @@ -143,7 +143,7 @@ def score_angles(self) -> None:
0
]

def render_phantom(self) -> tuple[Optional[str], str]:
def render_phantom(self) -> Tuple[Optional[str], str]:
"""
render a bond that closes a ring or loop, or for
late-rendered cross bonds. The target atom
Expand All @@ -162,7 +162,7 @@ def render_phantom(self) -> tuple[Optional[str], str]:
)
return atom_code, comment_code

def render(self) -> tuple[str, str]:
def render(self) -> Tuple[str, str]:
"""
render the atom and a comment
Expand Down
20 changes: 10 additions & 10 deletions mol2chemfigPy3/bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
My name is Bond. JAMES Bond.
"""
from typing import Optional, Union
from typing import Optional, Union, Tuple, Dict
from copy import deepcopy, copy
from math import atan, tan, pi
from indigo import Indigo
Expand Down Expand Up @@ -32,7 +32,7 @@

def compare_positions(
x1: float, y1: float, x2: float, y2: float
) -> tuple[float, float]:
) -> Tuple[float, float]:
"""
calculate distance and angle between the
coordinates of two atoms.
Expand Down Expand Up @@ -98,7 +98,7 @@ class Bond:

def __init__(
self,
options: dict,
options: Dict,
start_atom: Atom,
end_atom: Atom,
bond_type: Optional[str] = None,
Expand Down Expand Up @@ -145,7 +145,7 @@ def __init__(
else:
self.marker = ""

def bond_dimensions(self) -> tuple[float, float]:
def bond_dimensions(self) -> Tuple[float, float]:
"""
determine bond angle and distance between two atoms
Expand Down Expand Up @@ -266,7 +266,7 @@ def _adjoining_angles(

return int(round(angles[0])), int(round(angles[-1]))

def upstream_angles(self) -> dict:
def upstream_angles(self) -> Dict:
"""
determine the narrowest upstream left and upstream right angle.
Expand All @@ -280,7 +280,7 @@ def upstream_angles(self) -> dict:

return dict(left=first, right=last)

def downstream_angles(self) -> dict:
def downstream_angles(self) -> Dict:
"""
determine the narrowest downstream left and downstream right angle.
Expand Down Expand Up @@ -345,7 +345,7 @@ def shorten_stroke(

return self.cotan100(angle)

def fancy_double(self) -> Optional[tuple[str, int, int]]:
def fancy_double(self) -> Optional[Tuple[str, int, int]]:
"""
work out the parameters for rendering a fancy double bond.
Expand Down Expand Up @@ -427,7 +427,7 @@ def fancy_double(self) -> Optional[tuple[str, int, int]]:

return side, start, end

def fancy_triple(self) -> tuple[int, int]:
def fancy_triple(self) -> Tuple[int, int]:
"""
work out parameters for fancy triple bond. We don't
need to choose sides here, just calculate the required
Expand Down Expand Up @@ -545,7 +545,7 @@ def render(self, level: int) -> str:
return self.indent(level, bond_code, atom_code, comment_code)


class DummyFirstBond:
class DummyFirstBond(Bond):
"""
semi-dummy class that only takes an end-atom, which is the
first atom in the molecule, and just renders that.
Expand Down Expand Up @@ -581,7 +581,7 @@ class AromaticRingBond(Bond):

def __init__(
self,
options: dict,
options: Dict,
parent: Optional[Bond],
angle: Union[int, float],
length: Union[int, float],
Expand Down
20 changes: 10 additions & 10 deletions mol2chemfigPy3/chemfig_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
the TeX syntax defined by the chemfig package.
"""
import textwrap
from typing import Union, Optional
from typing import Union, Optional, List, Tuple, Dict

BOND_CODE_WIDTH = 50 # space for bonds - generous upfront, will be trimmed at the end
TERSE_LINE_WIDTH = 75 # in terse code format, force linebreaks
Expand Down Expand Up @@ -137,7 +137,7 @@ def num_round(num: Union[int, float], sig: Union[int, float]) -> Union[int, floa


def format_angle(
options: dict, angle: Union[int, float], parent_angle: Union[int, float, None]
options: Dict, angle: Union[int, float], parent_angle: Union[int, float, None]
) -> str:
"""
format prefix and number for bond angle
Expand Down Expand Up @@ -175,7 +175,7 @@ def specifier_default(val: any, default: any) -> str:


def format_bond(
options: dict,
options: Dict,
angle: Union[int, float, None],
parent_angle: Union[int, float, None],
bond_type: str,
Expand All @@ -184,8 +184,8 @@ def format_bond(
length: Union[int, float],
departure: str,
arrival: str,
tikz_styles: Union[set, dict],
tikz_values: Union[set, dict],
tikz_styles: Union[set, Dict],
tikz_values: Union[set, Dict],
marker: str,
) -> str:
"""
Expand Down Expand Up @@ -262,7 +262,7 @@ def format_bond(
return bond_code + modifier + specifiers


def fill_atom(keys: tuple, data: dict, phantom: str, phantom_pos: int = 0) -> tuple:
def fill_atom(keys: Tuple, data: Dict, phantom: str, phantom_pos: int = 0) -> tuple:
"""
helper for finalizing atom code. phantom_pos is the
target position of a bond attaching to a phantom;
Expand Down Expand Up @@ -298,7 +298,7 @@ def format_marker(marker: Optional[str]) -> Optional[str]:


def format_atom(
options: dict,
options: Dict,
idx: int,
element: str,
hydrogens: Optional[int],
Expand All @@ -307,7 +307,7 @@ def format_atom(
first_quadrant: str,
second_quadrant: str,
charge_angle: Optional[str],
) -> tuple:
) -> Tuple:
"""
render an atom with hydrogens and charges. Return
- the chemfig code of the rendered atom
Expand Down Expand Up @@ -417,7 +417,7 @@ def format_atom(
return fill_atom(keys, data, element_phantom)


def format_atom_comment(options: dict, idx: int) -> str:
def format_atom_comment(options: Dict, idx: int) -> str:
"""
render an optional end-of-line comment after a regular atom
Expand Down Expand Up @@ -449,7 +449,7 @@ def format_aromatic_ring(
parent_angle: Union[int, float, None],
length: Union[int, float],
radius: Union[int, float],
) -> tuple[str, str, str]:
) -> (str, str, str):
"""
:param options: option dict
:param angle: angle
Expand Down
2 changes: 1 addition & 1 deletion mol2chemfigPy3/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from .options import getParser

program_version = "1.5.5"
program_version = "1.5.6"

# pubchem url for retrieving sdf for numerical IDs
pubchem_url = (
Expand Down
24 changes: 12 additions & 12 deletions mol2chemfigPy3/molecule.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# parse a molfile molecule and render to chemfig code
import math
from typing import Optional, Union
from typing import Optional, Union, Tuple, List, Dict
from indigo import IndigoException, IndigoObject
from . import chemfig_mappings as cfm
from .common import MCFError, Counter
Expand All @@ -13,7 +13,7 @@ class Molecule:
bond_scale = 1.0 # can be overridden by user option
exit_bond = None # the first bond in the tree that connects to the exit atom

def __init__(self, options: dict, tkmol: IndigoObject):
def __init__(self, options: Dict, tkmol: IndigoObject):
self.options = options
self.tkmol = tkmol

Expand Down Expand Up @@ -138,15 +138,15 @@ def connect_fragments(self) -> None:
for atom in un_bonded:
self.link_atoms(anchor, atom)

def molecule_fragments(self) -> list:
def molecule_fragments(self) -> List:
"""
identify unconnected fragments in the molecule.
used by connect_fragments
:return: fragments
"""

def split_pairs(pair_list: list) -> tuple[list, list]:
def split_pairs(pair_list: List) -> Tuple[List, List]:
"""
break up pair_list into one list that contains all pairs
that are connected, directly or indirectly, to the first
Expand Down Expand Up @@ -194,7 +194,7 @@ def split_pairs(pair_list: list) -> tuple[list, list]:
else:
atom_pairs = rest

def treebonds(self, root: bool = False) -> list:
def treebonds(self, root: bool = False) -> List:
"""
return a list with all bonds in the molecule tree
Expand Down Expand Up @@ -307,7 +307,7 @@ def default_exit_bond(self) -> Bond:
bond_out = bonds[scored[-1]]
return bond_out

def pickFirstLastAtoms(self) -> tuple[Optional[Atom], Optional[Atom]]:
def pickFirstLastAtoms(self) -> Tuple[Optional[Atom], Optional[Atom]]:
"""
If the first atom is not given, we try to pick one
that has only one bond to the rest of the molecule,
Expand All @@ -334,7 +334,7 @@ def pickFirstLastAtoms(self) -> tuple[Optional[Atom], Optional[Atom]]:

return entry_atom, exit_atom

def parseAtoms(self) -> dict:
def parseAtoms(self) -> Dict:
"""
Read some attributes from the toolkit atom object
Expand Down Expand Up @@ -375,7 +375,7 @@ def parseAtoms(self) -> dict:

return wrapped_atoms

def parseBonds(self) -> tuple[dict, list]:
def parseBonds(self) -> Tuple[Dict, List]:
"""
read some bond attributes
Expand Down Expand Up @@ -622,7 +622,7 @@ def scaleBonds(self) -> None:
for bond in self.treebonds():
bond.length = self.bond_scale * bond.length

def render(self) -> list:
def render(self) -> List:
"""
render molecule to chemfig
Expand Down Expand Up @@ -655,7 +655,7 @@ def render_server(self) -> str:

return cfm.format_output(params, self._rendered)

def _renderBranches(self, output: list, level: int, bonds: list) -> None:
def _renderBranches(self, output: List, level: int, bonds: List) -> None:
"""
render a list of branching bonds indented and inside enclosing brackets.
Expand All @@ -673,7 +673,7 @@ def _renderBranches(self, output: list, level: int, bonds: list) -> None:

def _render(
self,
output: list,
output: List,
bond: Union[Bond, DummyFirstBond, AromaticRingBond],
level: int,
) -> None:
Expand Down Expand Up @@ -702,7 +702,7 @@ def _render(
self._renderBranches(output, level + 1, branches)
self._render(output, first, level)

def dimensions(self) -> tuple[float, float]:
def dimensions(self) -> Tuple[float, float]:
r"""
this calculates the approximate width and height
of the rendered molecule, in units of chemfig
Expand Down
Loading

0 comments on commit f095c78

Please sign in to comment.