Originally from December 2022: using chemfig in Manim
| from manim import * | |
| from mol2chemfigPy3 import mol2chemfig | |
| myChemTemplate = TexTemplate( | |
| tex_compiler="latex", | |
| output_format='.dvi', | |
| preamble=r""" | |
| \usepackage{amsmath} | |
| \usepackage{amssymb} | |
| \usepackage{chemfig} | |
| \usepackage{mol2chemfig} | |
| \setchemfig{atom sep=2em,angle increment=45,bond offset=2pt,double bond sep=2pt} | |
| """ | |
| ) | |
| class caffeine(Scene): | |
| def construct(self): | |
| chem = Tex( | |
| r"\chemfig{*6((=O)-N(-CH_3)-*5(-N=-N(-CH_3)-=)--(=O)-N(-H_3C)-)}", | |
| tex_template=myChemTemplate | |
| ).set_stroke(width=3) | |
| self.play(Write(chem)) | |
| self.wait() | |
| class pubchem(Scene): | |
| def construct(self): | |
| cmd = mol2chemfig('997', inline=True) | |
| chem = Tex( | |
| cmd, | |
| tex_template=myChemTemplate | |
| ).set_stroke(width=3) | |
| self.play(Write(chem)) | |
| self.wait() | |
| class kadir(Scene): | |
| def construct(self): | |
| a = mol2chemfig('CN1C=NC2=C1C(=O)N(C(=O)N2C)C', inline=True, aromatic=False) | |
| chem = Tex( | |
| a, | |
| tex_template=myChemTemplate | |
| ).set_stroke(width=3) | |
| self.play(Write(chem)) | |
| self.wait() |