Skip to content

Commit

Permalink
1.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Augus1999 authored Jan 30, 2022
1 parent fbf73ee commit a66f098
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mol2chemfigPy3

Current version 1.4.3333 (transferred from mol2chemfig v1.4).
Current version 1.4.4 (transferred from mol2chemfig v1.4).

This is NOT an official version of mol2chemfig for python 3.

Expand Down
54 changes: 52 additions & 2 deletions mol2chemfigPy3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,59 @@
a python 3 version of mol2chemfig.
mol2chemfig generates chemfig code from molfiles.
"""
import os
import re
from typing import Optional
from .main import main
from .processor import process
from .common import program_version
from .addin import mol2chemfig
__version__ = program_version
__Author__ = 'Nianze A. TAO'
__all__ = ['process', 'mol2chemfig', '__version__']
__all__ = ['main', 'mol2chemfig', 'mol2chemfig', '__version__']


def mol2chemfig(content: str,
*args: str,
rotate: float = 0.0,
aromatic: bool = True,
marker: Optional[str] = None,
name: Optional[str] = None,
relative_angle: bool = False,
show_carbon: bool = False,
show_methyl: bool = False,
inline: bool = False) -> Optional[str]:
"""
wrapper of mol2chemfigPy3.process(.)
:param content: chemical file name, InChem, SMILES, or Pubchem index
:param rotate: rotation angle
:param aromatic: whether drawing circle(s) in aromatic ring(s)
:param marker: mark atoms, e.g., with value 'a', atom 2 will be labeled @{a2}
:param name: name of the molecule
:param relative_angle: whether using relative bond angles
:param show_carbon: whether show carbon symbol
:param show_methyl: whether show methyl symbol
:param inline: inline mode: if true return the result else print the result
:return: None or result
"""
assert isinstance(aromatic, bool), "This value should be in type Bool"
assert isinstance(relative_angle, bool), "This value should be in type Bool"
assert isinstance(show_carbon, bool), "This value should be in type Bool"
assert isinstance(show_methyl, bool), "This value should be in type Bool"
others = ' '.join(args)
arg = f'-wz{"o" if aromatic else ""}{"v" if relative_angle else ""}' \
f'{"c" if show_carbon else ""}{"m" if show_methyl else ""}' \
f' -a {rotate} {"" if marker is None else "-g "+marker}' \
f' {"" if name is None else "-l "+name} {others}'
if os.path.isfile(content):
arg += f' -i file \"{content}\"'
else:
if re.match(r'[0-9]+', content).group(0) == content:
arg += f' -i pubchem {content}'
else:
arg += f' -i direct {content}'
arg = re.sub(r'\s+', ' ', arg)
success, result = process(raw_args=arg)
if inline:
return result.render_user() if success else result
print(f'{result.render_user() if success else "Failed..."}')
10 changes: 10 additions & 0 deletions mol2chemfigPy3/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Author: Nianze A. TAO (Omozawa SUENO)
"""
call mol2chemfigPy3.main
"""
import mol2chemfigPy3


if __name__ == "__main__":
mol2chemfigPy3.main()
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.4.3333'
program_version = '1.4.4'

# pubchem url for retrieving sdf for numerical IDs
pubchem_url = r"http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=%s&disopt=DisplaySDF"
Expand Down
24 changes: 24 additions & 0 deletions mol2chemfigPy3/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Author: Nianze A. TAO (Omozawa SUENO)
"""
package main
"""
import sys
from .processor import process


def main() -> None:
"""
console function
:return: None
"""
success, result = process(raw_args=sys.argv[1:], program_name=sys.argv[0])
if success:
print(result.render_user())
else:
print(result)


if __name__ == "__main__":
main()
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
package_dir={'mol2chemfigPy3': 'mol2chemfigPy3'},
author='Nianze A. Tao',
author_email='TaoN@cardiff.ac.uk',
scripts=['mol2chemfig', 'mol2chemfig.py'],
packages=find_packages(),
python_requires='>=3.7',
install_requires=['epam.indigo'],
project_urls={"Source": "https://github.com/Augus1999/mol2chemfigPy3"},
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
Expand All @@ -49,6 +49,9 @@
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Chemistry",
],
entry_points={
'console_scripts': ['mol2chemfig=mol2chemfigPy3.main:main']
},
)

if os.path.exists('build'):
Expand Down

0 comments on commit a66f098

Please sign in to comment.