This is not included in the original mol2chemfig.
mol2chemfigPy3.mol2chemfig(content: Union[str, int, pathlib.Path], *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]
A wrapper of ~mol2chemfigPy3.process(...) function.
Note that this function uses file extensions to judge whether an input is a valid file name or not. Please make sure your file names end with .gz .sdf .rdf .mol .rxn .txt .cml .mrv .xml .smi.
Parameters
- content - chemical file name, InChI, SMILES, or PubChem index
- *args - any other CLI arguments, e.g.,
"-r","-u", etc- rotate - rotation angle
- aromatic - whether to draw circle(s) in aromatic ring(s)
- marker - mark atoms, e.g., with value ‘a’, atom 2 will be labeled as @{a2}
- name - name of the molecule
- relative_angle - whether to use relative bond angles
- show_carbon - whether to show carbon symbols
- show_methyl - whether to show methyl symbols
- inline - inline mode: if
Truereturn the result else print the resultReturns
- LATEX
chemfigcode or error message ifinline=TrueelseNone
from mol2chemfigPy3 import mol2chemfig
mol2chemfig('996') # search the PubChem database
mol2chemfig('C1=CC=C(C=C1)O') # transfer InChI/SMILES to chemfig
mol2chemfig('./methanol.smi') # read from a file
mol2chemfig('c1ccncc1', '-r')
Some users suggested that we should include support for reaction SMILES. For some reasons, it is not flexible to add this feature in the package. However, it is easy to write a function to handle reaction via API, e.g.,
import textwrap
def rxn2chemfig(rxn: str, ignore_structure_check: bool = False) -> str:
reactants, products = rxn.split(">>")
reactants = reactants.split(".")
products = products.split(".")
reactant_chemfig = [
mol2chemfig(i, f"{'-r' if ignore_structure_check else ''}", inline=True)
for i in reactants
]
product_chemfig = [
mol2chemfig(i, f"{'-r' if ignore_structure_check else ''}", inline=True)
for i in products
]
reactant_block = "\n\\+\n".join(reactant_chemfig)
product_block = "\n\\+\n".join(product_chemfig)
rxn_chemfig = (
r"\schemestart"
f"\n{textwrap.indent(reactant_block, ' ')}\n"
f"{textwrap.indent(r'\arrow', ' ')}"
f"\n{textwrap.indent(product_block, ' ')}\n"
r"\schemestop"
)
return rxn_chemfig
which defines a template to translate reactants and products to chemfig code.