Skip to content

Commit a68e025

Browse files
authored
10/08/2024 Update
* Fixed a bug while handling charged molecules.
1 parent b6f80cd commit a68e025

File tree

6 files changed

+25
-23
lines changed

6 files changed

+25
-23
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![PyPI](https://img.shields.io/pypi/v/mol2chemfigPy3?color=ff69b4)](https://pypi.org/project/mol2chemfigPy3/)
44
[![Downloads](https://static.pepy.tech/personalized-badge/mol2chemfigpy3?period=total&units=international_system&left_color=black&right_color=green&left_text=Downloads)](https://pepy.tech/project/mol2chemfigpy3)
55
![OS](https://img.shields.io/badge/OS-Win%20|%20Linux%20|%20macOS-blue?color=00B16A)
6-
![python](https://img.shields.io/badge/Python-3.8%20|%203.9%20|%203.10-blue.svg?color=dd9b65)
6+
![python](https://img.shields.io/badge/Python->3.8%20-blue.svg?color=dd9b65)
77
![black](https://img.shields.io/badge/code%20style-black-black)
88
![pytest](https://github.com/Augus1999/mol2chemfigPy3/actions/workflows/pytest.yml/badge.svg)
99

mol2chemfigPy3/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
mol2chemfig generates chemfig code from mol files.
66
"""
77
import re
8-
from typing import Optional, Any
8+
from pathlib import Path
9+
from typing import Optional, Union
910
from .main import main
1011
from .processor import process
1112
from .common import program_version
@@ -18,7 +19,7 @@
1819

1920

2021
def mol2chemfig(
21-
content: Any,
22+
content: Union[int, str, Path],
2223
*args: str,
2324
rotate: float = 0.0,
2425
aromatic: bool = True,

mol2chemfigPy3/chemfig_mappings.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def num_round(num: Union[int, float], sig: Union[int, float]) -> Union[int, floa
118118
# one hydrogen
119119
one_h=dict(
120120
east=(r"%(element)sH^{%(charge)s}", 1),
121-
h_west=(r"^{%(charge)s}H%(element)s", 3),
121+
west=(r"^{%(charge)s}H%(element)s", 3),
122122
north=(r"\mcfaboveright{%(element)s}{H}{^{%(charge)s}}", 0),
123123
south=(r"\mcfbelowright{%(element)s}{H}{^{%(charge)s}}", 0),
124124
),
@@ -262,7 +262,9 @@ def format_bond(
262262
return bond_code + modifier + specifiers
263263

264264

265-
def fill_atom(keys: Tuple, data: Dict, phantom: str, phantom_pos: int = 0) -> tuple:
265+
def fill_atom(
266+
keys: Tuple[str, str, str], data: Dict, phantom: str, phantom_pos: int = 0
267+
) -> tuple:
266268
"""
267269
helper for finalizing atom code. phantom_pos is the
268270
target position of a bond attaching to a phantom;
@@ -330,7 +332,6 @@ def format_atom(
330332
"""
331333

332334
_mt = macro_templates # shortcuts
333-
_at = atom_templates
334335

335336
# collect elements in a dict that then is used to fill
336337
# the configured string templates.
@@ -474,7 +475,7 @@ def format_aromatic_ring(
474475
return ring_bond_code, ring_code, comment
475476

476477

477-
def strip_output(output_list: List) -> List:
478+
def strip_output(output_list: List[str]) -> List[str]:
478479
"""
479480
remove white space and comments
480481
@@ -505,7 +506,7 @@ def strip_output(output_list: List) -> List:
505506
return chunked
506507

507508

508-
def format_output(options: Dict, output_list: List) -> str:
509+
def format_output(options: Dict, output_list: List[str]) -> str:
509510
"""
510511
optionally wrap the translated output into a command,
511512
to ease inclusion in LaTeX documents with \\input

mol2chemfigPy3/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55
from .options import getParser
66

7-
program_version = "1.5.9"
7+
program_version = "1.5.10"
88

99
# pubchem url for retrieving sdf for numerical IDs
1010
pubchem_url = (

mol2chemfigPy3/optionparser.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class attributes and more subclassing than
1515
import getopt
1616
import re
1717
import textwrap
18-
from typing import Union, Optional, List, Tuple, Dict
18+
from typing import Union, Optional, Tuple, Any, List, Dict
1919

2020

2121
class OptionError(Exception):
@@ -85,7 +85,7 @@ def validate(self, value) -> bool:
8585
return True
8686
return False
8787

88-
def validate_form_value(self, value: any) -> bool:
88+
def validate_form_value(self, value: Any) -> bool:
8989
"""
9090
validation of option value received through a
9191
web form. May need to be different from CLI,
@@ -96,7 +96,7 @@ def validate_form_value(self, value: any) -> bool:
9696
"""
9797
return self.validate(value)
9898

99-
def _validate(self, value: any) -> Tuple[bool, any]:
99+
def _validate(self, value: Any) -> Tuple[bool, Any]:
100100
"""
101101
no-op default
102102
@@ -145,7 +145,7 @@ def format_help(self, indent: int = 30, linewidth: int = 80) -> list:
145145

146146
return h_wrap
147147

148-
def format_tag_value(self, value: any) -> str:
148+
def format_tag_value(self, value: Any) -> str:
149149
"""
150150
format the default value for insertion into form tag
151151
@@ -156,7 +156,7 @@ def format_tag_value(self, value: any) -> str:
156156
return ""
157157
return str(value)
158158

159-
def format_tag(self, value: any = None) -> Tuple[str, str, str, str]:
159+
def format_tag(self, value: Any = None) -> Tuple[str, str, str, str]:
160160
"""
161161
render a html form tag
162162
@@ -184,7 +184,7 @@ def _default(self) -> bool:
184184
"""
185185
return False
186186

187-
def validate(self, value: any = None) -> bool:
187+
def validate(self, value: Any = None) -> bool:
188188
"""
189189
value should be empty; we accept and discard it.
190190
we simply switch the default value.
@@ -195,7 +195,7 @@ def validate(self, value: any = None) -> bool:
195195
self.value = not self.default
196196
return True
197197

198-
def validate_form_value(self, value: any) -> bool:
198+
def validate_form_value(self, value: Any) -> bool:
199199
"""
200200
if a value arrives through a web form, the box has been
201201
ticked, so we set to True regardless of default. The passed
@@ -258,7 +258,7 @@ def _validate(self, value: str) -> Tuple[bool, str]:
258258
"""
259259
return True, value.lower()
260260

261-
def format_tag(self, value: any = None) -> Tuple[str, str, str, str]:
261+
def format_tag(self, value: Any = None) -> Tuple[str, str, str, str]:
262262
"""
263263
:param value: value
264264
:return: (key, tag, form text, help text)
@@ -294,7 +294,7 @@ class TypeOption(Option):
294294
r"""<input type="text" name="%(key)s" value="%(value)s" size="8"/>"""
295295
)
296296

297-
def _validate(self, value: any) -> Tuple[bool, any]:
297+
def _validate(self, value: Any) -> Tuple[bool, Any]:
298298
"""
299299
:param value: any value
300300
:return: (bool, value)

mol2chemfigPy3/processor.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import os.path
77
import traceback
88
from urllib import request
9-
from typing import Union, List, Tuple
9+
from typing import Union, Tuple, List, Any
1010
from indigo import Indigo, IndigoException, IndigoObject
1111
from . import common, options, molecule
1212

1313

1414
class HelpError(common.MCFError):
15-
def __init__(self, text: any):
15+
def __init__(self, text: Any):
1616
self.text = str(text) # convert error messages to string
1717

1818
def __str__(self):
@@ -28,7 +28,7 @@ def __init__(
2828
self,
2929
raw_args: Union[List, str, None],
3030
data: str,
31-
form_fields: any,
31+
form_fields: Any,
3232
program_name: str,
3333
web_form: bool,
3434
rpc: bool,
@@ -202,8 +202,8 @@ def parseMolecule(self) -> IndigoObject:
202202

203203
def process(
204204
raw_args: Union[List, str, None] = None,
205-
data: any = None,
206-
form_fields: any = None,
205+
data: Any = None,
206+
form_fields: Any = None,
207207
program_name: str = "mol2chemfigPy3",
208208
web_form: bool = False,
209209
rpc: bool = False,

0 commit comments

Comments
 (0)