Skip to content

Commit

Permalink
31/01/2024 Update.
Browse files Browse the repository at this point in the history
Version 1.5.8
* Simplified code.
  • Loading branch information
Augus1999 authored Jan 31, 2024
1 parent 12587a4 commit 9404412
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 28 deletions.
7 changes: 1 addition & 6 deletions mol2chemfigPy3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ def mol2chemfig(
f' {"" if name is None else "-l "+name} {others}'
)
arg = re.sub(r"\s+", " ", arg).split()
if content.endswith(
(
".mol",
".smi",
)
):
if content.endswith((".mol", ".smi")):
arg += ["-i", "file", content]
else:
try:
Expand Down
2 changes: 1 addition & 1 deletion mol2chemfigPy3/bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def is_clockwise(self, center_x: float, center_y: float) -> None:
if self.clockwise: # assign only once
return

center_dist, center_angle = compare_positions(
_, center_angle = compare_positions(
self.end_atom.x, self.end_atom.y, center_x, center_y
)

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.7"
program_version = "1.5.8"

# pubchem url for retrieving sdf for numerical IDs
pubchem_url = (
Expand Down
29 changes: 10 additions & 19 deletions mol2chemfigPy3/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, options: Dict, tkmol: IndigoObject):
# positioning of implicit hydrogen and charges.

for connection, bond in list(self.bonds.items()):
first_idx, last_idx = connection
first_idx, _ = connection
self.atoms[first_idx].bond_angles.append(bond.angle)

# this would be the place to work out the placement of the second
Expand Down Expand Up @@ -113,7 +113,6 @@ def connect_fragments(self) -> None:
fragments = self.molecule_fragments()

if len(fragments) > 1:

for head, tail in zip(fragments[:-1], fragments[1:]):
head_last = head[-1][-1]
tail_first = tail[0][0]
Expand Down Expand Up @@ -288,7 +287,6 @@ def default_exit_bond(self) -> Bond:
:return: the most distant bond
"""
scored = []
bonds = {}
for bond in self.treebonds():
if bond.to_phantom: # don't pick phantom atoms as exit
continue
Expand All @@ -301,11 +299,9 @@ def default_exit_bond(self) -> Bond:
distance += 1
the_bond = the_bond.parent

scored.append((distance, len(bond.descendants)))
bonds[(distance, len(bond.descendants))] = bond
scored.sort()
bond_out = bonds[scored[-1]]
return bond_out
scored.append((distance, len(bond.descendants), bond))
scored.sort(key=lambda x: x[0])
return scored[-1][-1]

def pickFirstLastAtoms(self) -> Tuple[Optional[Atom], Optional[Atom]]:
"""
Expand Down Expand Up @@ -359,7 +355,7 @@ def parseAtoms(self) -> Dict:

neighbors = [na.index() for na in ra.iterateNeighbors()]

x, y, z = ra.xyz()
x, y, _ = ra.xyz()

wrapped_atoms[idx] = Atom(
self.options,
Expand Down Expand Up @@ -584,21 +580,17 @@ def annotateRings(self) -> None:
self.tkmol.aromatize()

all_rings = []
rings = {}
_all_rings = []
for key, ring in enumerate(self.tkmol.iterateSSSR()):

for ring in self.tkmol.iterateSSSR():
# bond-order == 4 means "aromatic"; all rings bonds must be aromatic
is_aromatic = all(bond.bondOrder() == 4 for bond in ring.iterateBonds())
all_rings.append((is_aromatic, key))
rings[(is_aromatic, key)] = ring
all_rings.append((is_aromatic, ring))

# prefer aromatic rings to non-aromatic ones, so that double bonds on
# fused rings go preferably into aromatic rings
all_rings.sort()
for i in all_rings:
_all_rings.append((i[0], rings[i]))
all_rings.sort(key=lambda x: x[0])

for is_aromatic, ring in reversed(_all_rings):
for is_aromatic, ring in reversed(all_rings):
self.annotateRing(ring, is_aromatic)

def scaleBonds(self) -> None:
Expand Down Expand Up @@ -650,7 +642,6 @@ def render_server(self) -> str:
# override some options
params = dict(self.options)
params["submol_name"] = None
# params['terse'] = False # why?
params["chemfig_command"] = True

return cfm.format_output(params, self._rendered)
Expand Down
1 change: 0 additions & 1 deletion mol2chemfigPy3/optionparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def __init__(
Our engineers deemed it self-explanatory
""",
):

self.long_name = long_name
self.short_name = short_name
self.key = key or long_name
Expand Down

0 comments on commit 9404412

Please sign in to comment.