From a66f09880e9a12fee4d4075db5d49b46b4647d84 Mon Sep 17 00:00:00 2001 From: SUENO Omozawa <39725660+Augus1999@users.noreply.github.com> Date: Sun, 30 Jan 2022 22:02:41 +0000 Subject: [PATCH] 1.4.4 --- README.md | 2 +- mol2chemfigPy3/__init__.py | 54 ++++++++++++++++++++++++++++++++++++-- mol2chemfigPy3/__main__.py | 10 +++++++ mol2chemfigPy3/common.py | 2 +- mol2chemfigPy3/main.py | 24 +++++++++++++++++ setup.py | 5 +++- 6 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 mol2chemfigPy3/__main__.py create mode 100644 mol2chemfigPy3/main.py diff --git a/README.md b/README.md index 20f9e9a..2be89c6 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/mol2chemfigPy3/__init__.py b/mol2chemfigPy3/__init__.py index 85c629f..70126b2 100644 --- a/mol2chemfigPy3/__init__.py +++ b/mol2chemfigPy3/__init__.py @@ -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..."}') diff --git a/mol2chemfigPy3/__main__.py b/mol2chemfigPy3/__main__.py new file mode 100644 index 0000000..4b6a584 --- /dev/null +++ b/mol2chemfigPy3/__main__.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Author: Nianze A. TAO (Omozawa SUENO) +""" +call mol2chemfigPy3.main +""" +import mol2chemfigPy3 + + +if __name__ == "__main__": + mol2chemfigPy3.main() diff --git a/mol2chemfigPy3/common.py b/mol2chemfigPy3/common.py index ae10e75..9d50302 100644 --- a/mol2chemfigPy3/common.py +++ b/mol2chemfigPy3/common.py @@ -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" diff --git a/mol2chemfigPy3/main.py b/mol2chemfigPy3/main.py new file mode 100644 index 0000000..f431de6 --- /dev/null +++ b/mol2chemfigPy3/main.py @@ -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() diff --git a/setup.py b/setup.py index 207a982..50b2ac6 100644 --- a/setup.py +++ b/setup.py @@ -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", @@ -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'):