From f095c78cd3dc65d2fef941a4a7babc0fea006ba5 Mon Sep 17 00:00:00 2001
From: SUENO Omozawa <39725660+Augus1999@users.noreply.github.com>
Date: Fri, 15 Jul 2022 12:18:43 +0100
Subject: [PATCH] update
---
mol2chemfigPy3/atom.py | 12 ++++++------
mol2chemfigPy3/bond.py | 20 ++++++++++----------
mol2chemfigPy3/chemfig_mappings.py | 20 ++++++++++----------
mol2chemfigPy3/common.py | 2 +-
mol2chemfigPy3/molecule.py | 24 ++++++++++++------------
mol2chemfigPy3/optionparser.py | 28 ++++++++++++++--------------
mol2chemfigPy3/processor.py | 8 ++++----
7 files changed, 57 insertions(+), 57 deletions(-)
diff --git a/mol2chemfigPy3/atom.py b/mol2chemfigPy3/atom.py
index 72b5d15..1999867 100644
--- a/mol2chemfigPy3/atom.py
+++ b/mol2chemfigPy3/atom.py
@@ -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
@@ -43,7 +43,7 @@ class Atom:
def __init__(
self,
- options: dict,
+ options: Dict,
idx: int,
x: Union[int, float],
y: Union[int, float],
@@ -51,7 +51,7 @@ def __init__(
hydrogens: Optional[int],
charge: int,
radical: int,
- neighbors: list[int],
+ neighbors: List[int],
):
self.options = options
self.idx = idx
@@ -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
@@ -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
@@ -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
diff --git a/mol2chemfigPy3/bond.py b/mol2chemfigPy3/bond.py
index 465907f..ff0f6e7 100644
--- a/mol2chemfigPy3/bond.py
+++ b/mol2chemfigPy3/bond.py
@@ -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
@@ -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.
@@ -98,7 +98,7 @@ class Bond:
def __init__(
self,
- options: dict,
+ options: Dict,
start_atom: Atom,
end_atom: Atom,
bond_type: Optional[str] = None,
@@ -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
@@ -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.
@@ -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.
@@ -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.
@@ -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
@@ -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.
@@ -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],
diff --git a/mol2chemfigPy3/chemfig_mappings.py b/mol2chemfigPy3/chemfig_mappings.py
index 69e3059..91083cd 100644
--- a/mol2chemfigPy3/chemfig_mappings.py
+++ b/mol2chemfigPy3/chemfig_mappings.py
@@ -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
@@ -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
@@ -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,
@@ -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:
"""
@@ -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;
@@ -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],
@@ -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
@@ -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
@@ -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
diff --git a/mol2chemfigPy3/common.py b/mol2chemfigPy3/common.py
index ac913c3..b6e3a8b 100644
--- a/mol2chemfigPy3/common.py
+++ b/mol2chemfigPy3/common.py
@@ -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 = (
diff --git a/mol2chemfigPy3/molecule.py b/mol2chemfigPy3/molecule.py
index 7099888..d34b803 100644
--- a/mol2chemfigPy3/molecule.py
+++ b/mol2chemfigPy3/molecule.py
@@ -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
@@ -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
@@ -138,7 +138,7 @@ 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
@@ -146,7 +146,7 @@ def molecule_fragments(self) -> list:
: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
@@ -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
@@ -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,
@@ -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
@@ -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
@@ -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
@@ -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.
@@ -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:
@@ -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
diff --git a/mol2chemfigPy3/optionparser.py b/mol2chemfigPy3/optionparser.py
index e4e1192..16f128e 100644
--- a/mol2chemfigPy3/optionparser.py
+++ b/mol2chemfigPy3/optionparser.py
@@ -15,7 +15,7 @@ class attributes and more subclassing than
import getopt
import re
import textwrap
-from typing import Union, Optional
+from typing import Union, Optional, List, Tuple, Dict
class OptionError(Exception):
@@ -36,7 +36,7 @@ def __init__(
form_text: Optional[str] = None,
key: Optional[str] = None,
default: Union[bool, int, float, str, None] = None,
- valid_range: Union[list, tuple, None] = None,
+ valid_range: Union[List, Tuple, None] = None,
help_text: str = """
Our engineers deemed it self-explanatory
""",
@@ -97,7 +97,7 @@ def validate_form_value(self, value: any) -> bool:
"""
return self.validate(value)
- def _validate(self, value: any) -> tuple[bool, any]:
+ def _validate(self, value: any) -> Tuple[bool, any]:
"""
no-op default
@@ -157,7 +157,7 @@ def format_tag_value(self, value: any) -> str:
return ""
return str(value)
- def format_tag(self, value: any = None) -> tuple[str, str, str, str]:
+ def format_tag(self, value: any = None) -> Tuple[str, str, str, str]:
"""
render a html form tag
@@ -250,7 +250,7 @@ def _default(self) -> None:
except (TypeError, IndexError):
raise OptionError("valid_range does not supply default")
- def _validate(self, value: str) -> tuple[bool, str]:
+ def _validate(self, value: str) -> Tuple[bool, str]:
"""
we enforce conversion to lowercase
@@ -259,7 +259,7 @@ def _validate(self, value: str) -> tuple[bool, str]:
"""
return True, value.lower()
- def format_tag(self, value: any = None) -> tuple[str, str, str, str]:
+ def format_tag(self, value: any = None) -> Tuple[str, str, str, str]:
"""
:param value: value
:return: (key, tag, form text, help text)
@@ -295,7 +295,7 @@ class TypeOption(Option):
r""""""
)
- def _validate(self, value: any) -> tuple[bool, any]:
+ def _validate(self, value: any) -> Tuple[bool, any]:
"""
:param value: any value
:return: (bool, value)
@@ -332,7 +332,7 @@ class RangeOption(Option):
r""""""
)
- def _validate(self, raw_value: str) -> tuple[bool, Union[list, str]]:
+ def _validate(self, raw_value: str) -> Tuple[bool, Union[List, str]]:
"""
:param raw_value: string value
:return: (bool, range)
@@ -380,7 +380,7 @@ def append(self, option: any) -> None:
# also maintain options ordered in a list
self._options.append(option)
- def validKeys(self) -> list:
+ def validKeys(self) -> List:
"""
required by the web form front end
@@ -388,7 +388,7 @@ def validKeys(self) -> list:
"""
return list(self._options_by_key.keys())
- def option_values(self) -> dict:
+ def option_values(self) -> Dict:
"""
read current option values
@@ -401,7 +401,7 @@ def option_values(self) -> dict:
return option_dict
- def process_form_fields(self, fields: any) -> tuple[dict, list]:
+ def process_form_fields(self, fields: any) -> Tuple[Dict, List]:
"""
process options received through the web form.
we don't look at the cargo data here at all.
@@ -422,7 +422,7 @@ def process_form_fields(self, fields: any) -> tuple[dict, list]:
return self.option_values(), warnings
- def process_cli(self, raw_input: Union[list, str]) -> tuple[dict, list]:
+ def process_cli(self, raw_input: Union[List, str]) -> Tuple[Dict, List]:
"""
process input from the command line interface
- assemble template strings for getopt and run getopt
@@ -452,7 +452,7 @@ def process_cli(self, raw_input: Union[list, str]) -> tuple[dict, list]:
return self.option_values(), args
- def format_for_getopt(self) -> tuple[str, list]:
+ def format_for_getopt(self) -> Tuple[str, List]:
"""
:return: (shorts, [long_1, long_2,...])
"""
@@ -494,7 +494,7 @@ def format_help(
return "\n".join(output)
- def form_tags(self) -> list:
+ def form_tags(self) -> List:
"""
collect the html for each option
diff --git a/mol2chemfigPy3/processor.py b/mol2chemfigPy3/processor.py
index a6b2836..37cc648 100644
--- a/mol2chemfigPy3/processor.py
+++ b/mol2chemfigPy3/processor.py
@@ -6,7 +6,7 @@
import os.path
import traceback
from urllib import request
-from typing import Union
+from typing import Union, List, Tuple
from indigo import Indigo, IndigoException, IndigoObject
from . import common, options, molecule
@@ -26,7 +26,7 @@ class Processor:
def __init__(
self,
- raw_args: Union[list, str, None],
+ raw_args: Union[List, str, None],
data: str,
form_fields: any,
program_name: str,
@@ -206,14 +206,14 @@ def parseMolecule(self) -> IndigoObject:
def process(
- raw_args: Union[list, str, None] = None,
+ raw_args: Union[List, str, None] = None,
data: any = None,
form_fields: any = None,
program_name: str = "mol2chemfigPy3",
web_form: bool = False,
rpc: bool = False,
inline: bool = False,
-) -> tuple[bool, Union[str, molecule.Molecule]]:
+) -> Tuple[bool, Union[str, molecule.Molecule]]:
"""
process is a convenience wrapper for external callers