kilacoda / chanim Goto Github PK
View Code? Open in Web Editor NEWAnimation engine for explanatory chemistry videos
License: MIT License
Animation engine for explanatory chemistry videos
License: MIT License
when run "manim -p -qm chem.py ChanimScene" i get the error "def init(self, bond: TexSymbol, length=0.7, **kwargs):
NameError: name 'TexSymbol' is not defined" u can help me?
All temporary TeX-files (.tex
, .log
, .aux
) are now stored in the directory manim is run instead of media/Tex/
. It was thus necessary to manually add the correct folders to manimlib/constants.py
, e.g. like this:
MEDIA_DIR = "/home/alexander_schoch/Documents/Python/manim/media/"
VIDEO_DIR = "/home/alexander_schoch/Documents/Python/manim/video/"
VIDEO_OUTPUT_DIR = "/home/alexander_schoch/Documents/Python/manim/video/"
TEX_DIR = "/home/alexander_schoch/Documents/Python/manim/media/Tex/"
I was trying to implement the following reaction scheme in chanim but couldn't manage to how I can. It will be really helpful if there is some more example in the README file.
\schemestart
\chemfig{@{a1}=_[@{db}::30]-[::-60]\charge{90=\|}{X}}
\arrow{<->}
\chemfig{\chemabove{\vphantom{X}}{\ominus}-[::30]=_[::-60]
\chemabove{X}{\scriptstyle\oplus}}
\schemestop
\chemmove{\draw(db).. controls +(100:5mm) and +(145:5mm).. (a1);}
This should produce the following figure like scene render:
I use the README code to render the scene but got this problem. I think chanim use older manim version. But I couldn't figure out which version will resolve this issue as there was no mention in the README file.
I was expecting to generate the following scene:
from chanim import *
class ChanimScene(Scene):
def construct(self):
chem = ChemWithName("*6((=O)-N(-CH_3)-*5(-N=-N(-CH_3)-=)--(=O)-N(-H_3C)-)")
self.play(chem.creation_anim())
self.wait()
Manim Community v0.6.0
Traceback (most recent call last):
File "/home/emonhossain/.local/bin/manim", line 8, in <module>
sys.exit(main())
File "/home/emonhossain/.local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/emonhossain/.local/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/emonhossain/.local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/emonhossain/.local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/emonhossain/.local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/emonhossain/.local/lib/python3.8/site-packages/manim/cli/render/commands.py", line 153, in render
for SceneClass in scene_classes_from_file(file):
File "/home/emonhossain/.local/lib/python3.8/site-packages/manim/utils/module_ops.py", line 118, in scene_classes_from_file
module = get_module(file_path)
File "/home/emonhossain/.local/lib/python3.8/site-packages/manim/utils/module_ops.py", line 47, in get_module
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "chem.py", line 1, in <module>
from chanim import *
File "/home/emonhossain/Desktop/chanim/chanim/__init__.py", line 8, in <module>
from .chem_objects import *
File "/home/emonhossain/Desktop/chanim/chanim/chem_objects.py", line 17, in <module>
from manim.mobject.geometry import SmallDot
ImportError: cannot import name 'SmallDot' from 'manim.mobject.geometry' (/home/emonhossain/.local/lib/python3.8/site-packages/manim/mobject/geometry.py)
python/py/python3 --version
): 3.8.5pip list
):Package Version Location
---------------------- -------------------- --------------------------------
appdirs 1.4.3
apturl 0.5.2
argon2-cffi 20.1.0
astroid 2.5.6
async-generator 1.10
attrs 20.3.0
backcall 0.2.0
bcrypt 3.1.7
beautifulsoup4 4.8.2
bleach 3.3.0
blessings 1.7
blinker 1.4
bpython 0.21
Brlapi 0.7.0
certifi 2019.11.28
cffi 1.14.5
chanim 0.1.0 /home/emonhossain/Desktop/chanim
chardet 3.0.4
chrome-gnome-shell 0.0.0
click 7.1.2
click-default-group 1.2.2
cloudpickle 1.6.0
cloup 0.7.0
colorama 0.4.3
colour 0.1.5
command-not-found 0.3
commonmark 0.9.1
cryptography 2.8
cupshelpers 1.0
curtsies 0.3.5
cwcwidth 0.1.4
cycler 0.10.0
dbus-python 1.2.16
decorator 4.4.2
defer 1.0.6
defusedxml 0.7.1
distlib 0.3.0
distro 1.4.0
distro-info 0.23ubuntu1
duplicity 0.8.12.0
entrypoints 0.3
fasteners 0.14.1
filelock 3.0.12
future 0.18.2
glcontext 2.3.2
gpg 1.13.1-unknown
greenlet 1.0.0
html5lib 1.0.1
httplib2 0.14.0
idna 2.8
imageio 2.9.0
importlib-metadata 1.5.0
ipykernel 5.5.3
ipython 7.20.0
ipython-genutils 0.2.0
ipywidgets 7.6.3
isort 5.8.0
jedi 0.18.0
Jinja2 2.11.3
jsonschema 3.2.0
jupyter 1.0.0
jupyter-client 6.1.12
jupyter-console 6.4.0
jupyter-core 4.7.1
jupyterlab-pygments 0.1.2
jupyterlab-widgets 1.0.0
keyring 18.0.1
kiwisolver 1.3.1
language-selector 0.1
launchpadlib 1.10.13
lazr.restfulclient 0.14.2
lazr.uri 1.0.3
lazy-object-proxy 1.6.0
linecache2 1.0.0
lockfile 0.12.2
louis 3.12.0
lxml 4.5.0
macaroonbakery 1.3.1
Mako 1.1.0
manim 0.6.0
manim-fonts 0.1.0.post4
manim-rubikscube 0.0.8
ManimPango 0.2.4
mapbox-earcut 0.12.10
MarkupSafe 1.1.0
mathinspector 0.9.3.post0
matplotlib 3.3.4
mccabe 0.6.1
mistune 0.8.4
moderngl 5.6.4
moderngl-window 2.3.0
monotonic 1.5
more-itertools 4.2.0
mpmath 1.2.1
multipledispatch 0.6.0
nbclient 0.5.3
nbconvert 6.0.7
nbformat 5.1.3
nest-asyncio 1.5.1
netifaces 0.10.4
networkx 2.5
notebook 6.3.0
numpy 1.20.1
oauthlib 3.1.0
olefile 0.46
opencv-python 4.5.1.48
packaging 20.9
pandocfilters 1.4.3
paramiko 2.6.0
parso 0.8.1
pbr 5.4.5
persepolis 3.2.0
pexpect 4.6.0
pickleshare 0.7.5
Pillow 7.0.0
pip 21.1.1
progressbar 2.5
prometheus-client 0.10.1
prompt-toolkit 3.0.16
protobuf 3.6.1
psutil 5.5.1
ptyprocess 0.7.0
pycairo 1.20.0
pycparser 2.20
pycups 1.9.73
pydub 0.24.1
pygame 2.0.1
pyglet 1.5.15
PyGLM 1.99.3
Pygments 2.8.0
PyGObject 3.36.0
PyJWT 1.7.1
pylint 2.8.2
pymacaroons 0.13.0
PyNaCl 1.3.0
PyOpenGL 3.1.5
PyOpenGL-accelerate 3.1.5
pyparsing 2.4.7
PyQt5 5.14.1
pyRFC3339 1.1
pyrr 0.10.3
pyrsistent 0.17.3
PySocks 1.6.8
python-apt 2.0.0+ubuntu0.20.4.4
python-dateutil 2.7.3
python-debian 0.1.36ubuntu1
pytz 2019.3
PyWavelets 1.1.1
pyxattr 0.6.1
pyxdg 0.26
PyYAML 5.3.1
pyzmq 22.0.3
qtconsole 5.0.3
QtPy 1.9.0
reportlab 3.5.34
requests 2.22.0
requests-unixsocket 0.2.0
rich 6.2.0
scikit-image 0.18.1
scipy 1.6.1
scour 0.37
screeninfo 0.6.7
SecretStorage 2.3.1
Send2Trash 1.5.0
setproctitle 1.1.10
setuptools 53.0.0
Shapely 1.7.1
simplejson 3.16.0
sip 4.19.21
six 1.14.0
soupsieve 1.9.5
sympy 1.7.1
systemd-python 234
terminado 0.9.4
testpath 0.4.4
testresources 2.0.0
tifffile 2021.3.17
toml 0.10.2
torbrowser-launcher 0.3.2
tornado 6.1
tqdm 4.57.0
traceback2 1.4.0
traitlets 5.0.5
ttkthemes 2.0.6
typing-extensions 3.7.4.3
ubuntu-advantage-tools 27.0
ubuntu-cleaner 1.1.3
ubuntu-drivers-common 0.0.0
ufw 0.36
unattended-upgrades 0.1
unittest2 1.1.0
urllib3 1.25.8
usb-creator 0.3.7
validators 0.18.2
virtualenv 20.0.17
wadllib 1.3.3
watchdog 2.0.2
wcwidth 0.2.5
webencodings 0.5.1
wheel 0.36.2
widgetsnbextension 3.5.1
wrapt 1.12.1
xkit 0.0.0
youtube-dl 2020.3.24
zipp 1.0.0
ImportError: cannot import name 'OpenGLMathTex' from 'manim.opengl'
In Manim Community v0.14.0,there is no 'OpenGLMathTex' from 'manim.opengl' , how to solve this question, thx!
Manim Community v0.14.0
Traceback (most recent call last):
File "/Users/lemon/opt/anaconda3/envs/manimce/bin/manim", line 8, in <module>
sys.exit(main())
File "/Users/lemon/opt/anaconda3/envs/manimce/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
return self.main(*args, **kwargs)
File "/Users/lemon/opt/anaconda3/envs/manimce/lib/python3.9/site-packages/click/core.py", line 1062, in main
rv = self.invoke(ctx)
File "/Users/lemon/opt/anaconda3/envs/manimce/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/lemon/opt/anaconda3/envs/manimce/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/lemon/opt/anaconda3/envs/manimce/lib/python3.9/site-packages/click/core.py", line 763, in invoke
return __callback(*args, **kwargs)
File "/Users/lemon/opt/anaconda3/envs/manimce/lib/python3.9/site-packages/manim/cli/render/commands.py", line 136, in render
for SceneClass in scene_classes_from_file(file):
File "/Users/lemon/opt/anaconda3/envs/manimce/lib/python3.9/site-packages/manim/utils/module_ops.py", line 125, in scene_classes_from_file
module = get_module(file_path)
File "/Users/lemon/opt/anaconda3/envs/manimce/lib/python3.9/site-packages/manim/utils/module_ops.py", line 50, in get_module
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/lemon/Documents/animation/ManimCE/chemistry.py", line 9, in <module>
from chanim import *
File "/Users/lemon/opt/anaconda3/envs/manimce/lib/python3.9/site-packages/chanim/__init__.py", line 8, in <module>
from .chem_objects import *
File "/Users/lemon/opt/anaconda3/envs/manimce/lib/python3.9/site-packages/chanim/chem_objects.py", line 22, in <module>
from manim.opengl import OpenGLMathTex
ImportError: cannot import name 'OpenGLMathTex' from 'manim.opengl' (/Users/lemon/opt/anaconda3/envs/manimce/lib/python3.9/site-packages/manim/opengl/__init__.py)
Hey I am a beginner in python and I tried your chanim library and it does not work for me. Also it compiles some of your tests as seen in the first 2 lines.
The output I get is:
[4]H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-OH
[4]H-C(-[2]H)(-[6]H)-COOH
Traceback (most recent call last):
File "C:\Users<username>\Anaconda3\envs\math_venv\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "C:\Users<username>\Anaconda3\envs\math_venv\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "D:\AutomatisierungSubgroupstuff\Python\Real_Prog\manim_projects\manim.py", line 5, in
manimlib.main()
File "D:\AutomatisierungSubgroupstuff\Python\Real_Prog\manim_projects\manimlib_init.py", line 11, in main
config = manimlib.config.get_configuration(args)
File "D:\AutomatisierungSubgroupstuff\Python\Real_Prog\manim_projects\manimlib\config.py", line 185, in get_configuration
module = get_module(args.file)
File "D:\AutomatisierungSubgroupstuff\Python\Real_Prog\manim_projects\manimlib\config.py", line 180, in get_module
spec.loader.exec_module(module)
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "FLN_color.py", line 43, in
class Chem(Scene):
File "FLN_color.py", line 45, in Chem
self.play(Write(Ass))
NameError: name 'self' is not defined
My Code:
from manimlib.imports import *
from chanimlib.imports import *
class Chem(Scene):
test = ChemObject("A-B")
self.play(Write(test))
Also your ChemObject() class has no init() function.
I have cairo installed and manim is working fine, but I get this error:
OSError: no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so.2': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x7e
cannot load library 'libcairo-2.dll': error 0x7e
every time I try to run this:
from chanim import *
class ChanimScene(Scene):
def construct(self):
chem = ChemWithName("*6((=O)-N(-CH_3)-*5(-N=-N(-CH_3)-=)--(=O)-N(-H_3C)-)")
self.play(chem.creation_anim())
self.wait()
I had the exact same idea as you - a manim based chemistry animation engine. I stumbled over this project while searching for ways to create such a thing, I really hope I can get Chanim to work it's an awesome project.
Any help is appreciated.
ERROR LaTeX compilation error: Undefined tex_file_writing.py:200
control sequence.
ERROR Context for error: tex_file_writing.py:225
\begin{align}
\chemfig{6((=O)-N(-CH_3)-5(-N=-N(-CH_3
)-=)--(=O)-N(-H_3C)-)}
\end{align}
ValueError Traceback (most recent call last)
in
----> 1 get_ipython().run_cell_magic('manim', 'ChanimScene', 'class ChanimScene(Scene):\n def construct(self):\n ## ChemWithName creates a chemical diagram with a name label\n chem = ChemWithName("6((=O)-N(-CH_3)-5(-N=-N(-CH_3)-=)--(=O)-N(-H_3C)-)", "Caffeine")\n\n self.play(chem.creation_anim())\n self.wait()\n')
11 frames
in
in construct(self)
/usr/local/lib/python3.7/dist-packages/manim/utils/tex_file_writing.py in compile_tex(tex_file, tex_compiler, output_format)
233
234 raise ValueError(
--> 235 f"{tex_compiler} error converting to"
236 f" {output_format[1:]}. See log output above or"
237 f" the log file: {log_file}"
ValueError: latex error converting to dvi. See log output above or the log file: media/Tex/4799158acc41e94f.log
I AM HAVING This error in Google Colab while running it , I installed both manim and chanim and also !tlmgr install chemfig but still having the problem please solve this , while running
!tlmgr install chemfig
It's showing
Cannot determine type of tlpdb from /root/textmf!
Cannot set up TLPDB in /root/textmf at /usr/bin/tlmgr line 6424
In the new ManimCE v0.17 which was released in December 2022 the TexSymbol() class was removed.
When I try to use ChemArrow class, I'm noticing that the arrow isn't showing up once the video is successfully created. I was wondering if this is a known issue with this class.
I've also been playing around with the chem_objects.py and constants.py file to see if I can fix this. On MiXTeX I'm able to see the arrow just fine, but when creating the video again, the arrow is just messing with things.
I was wondering if you have further insight on this. Thanks!
Hello. I have recently found the chanim package here on GitHub. I really love the package and the idea to use the chemfig library from LaTex. I immediately installed it via pip. Then of course the packages mactex and ffmpg (I am on a Mac). But for some reason some classes used by the Chanim package do not exist anymore (e.g. the TexTemplate Class. Am I using the wrong version of manim or am I missing something?
This code (acetone)
#!/usr/bin/env python
from manimlib.imports import *
from chanimlib.imports import *
class tikz(Scene):
def construct(self):
testobject = ChemObject("-[:30](=[2]O)-[:30]")
self.play(Write(testobject))
self.wait(3)
results in three .tex
files in media/Tex
(without preamble):
\begin{document}
\begin{align*}
\setchemfig{atom sep = 2em}
\chemfig{[4]H-C(-[2]H)(-[6]H)-COOH}
\end{align*}
\end{document}
\begin{document}
\begin{align*}
\setchemfig{atom sep = 2em}
\chemfig{[4]H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-OH}
\end{align*}
\end{document}
\begin{document}
\begin{align*}
\setchemfig{atom sep = 2em}
\chemfig{-[:30](=[2]O)-[:30]}
\end{align*}
\end{document}
Only the last one was actually used as an input.
Would love some code examples on usage of this lib. Maybe consider adding source code of videos you produce in a folder?
I was trying to make some molecules and I noticed that hatched bonds show up as normal bonds
class Methane(Scene):
def construct(self):
f1 = ChemObject("C(-[5]H)(-[2]H)(<[:-70]H)(<:[:-20]H)")
self.play(Write(f1))
self.wait()
also I'm having some trouble trying to change the color of bonds and atoms
class Chem2(Scene):
def construct(self):
f1 = ChemObject("-[:30]=[:-30,,,,red]-[:30]")
self.play(Write(f1))
self.wait()
Does anyone know what am I doing wrong?
WIll compatibility with manim 0.17 become available soon or is there anything we can do about it?
I'm not good in handling forks on github, but here are the changes necessary to make chanim compatible with both the latest version of LaTeX/chemfig/Tikz and Manim v0.17:
in templates.py change the empty strings against "{}"
`
class ChemTemplate(TexTemplate):
def init(self,**kwargs):
super().init(**kwargs)
self.add_to_preamble("\usepackage{chemfig}")
def set_chemfig(
self,
atom_sep: str = "2em", ## all of these are the defaults in chemfig
chemfig_style:str="{}",
atom_style:str="{}",
angle_increment:int=45,
bond_offset:str="2pt",
double_bond_sep:str="2pt",
node_style:str="{}",
bond_style:str="{}",
):
set_chemfig = "\\setchemfig{atom sep=%s,chemfig style=%s, atom style=%s,angle increment=%d,bond offset=%s,double bond sep=%s, node style=%s, bond style=%s}" % (atom_sep,chemfig_style,atom_style,angle_increment,bond_offset,double_bond_sep,node_style,bond_style)
self.add_to_preamble(set_chemfig)
`
in chem_objects.py recreate the class TexSymbol
from manim.mobject.text.tex_mobject import * from manim.mobject.svg.svg_mobject import VMobjectFromSVGPath class TexSymbol(VMobjectFromSVGPath): """Purely a renaming of SVGPathMobject.""" pass
At least I am able to render the first example again with these settings.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.