Git Product home page Git Product logo

Comments (3)

uwezi avatar uwezi commented on July 1, 2024

ok, some more corrections in templates.py

`

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{{angle_increment={:d}".format(angle_increment)
    if atom_sep:
        set_chemfig += ",atom sep={:s}".format(atom_sep)
    if chemfig_style:
        set_chemfig += ",chemfig style={:s}".format(chemfig_style)
    if atom_style:
        set_chemfig += ",atom style={:s}".format(atom_style) 
    if bond_offset:
        set_chemfig += ",bond offset={:s}".format(bond_offset) 
    if double_bond_sep:
        set_chemfig += ",double bond sep={:s}".format(double_bond_sep) 
    if node_style:
        set_chemfig += ",node style={:s}".format(node_style)
    if bond_style:
        set_chemfig += ",bond style={:s}".format(bond_style)
    set_chemfig += "}"
    print(set_chemfig)
    self.add_to_preamble(set_chemfig)

class ChemReactionTemplate(TexTemplate):
def init(self,**kwargs):
super().init(**kwargs)
self.add_to_preamble("\usepackage{chemfig}")

def set_chemfig(
    self,

    ##Individual molecule params
    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="{}",

    ## Reaction scheme params
    arrow_length:int=1,
    arrow_angle:int=0,
    arrow_style:str="",
    debug:str="false",
):
    set_chemfig = "\\setchemfig{{angle_increment={:d},arrow angle={:d},arrow coeff={:s}".format(angle_increment,arrow_angle,arrow_length)
    if atom_sep:
        set_chemfig += ",atom sep={:s}".format(atom_sep)
    if chemfig_style:
        set_chemfig += ",chemfig style={:s}".format(chemfig_style)
    if atom_style:
        set_chemfig += ",atom style={:s}".format(atom_style) 
    if bond_offset:
        set_chemfig += ",bond offset={:s}".format(bond_offset) 
    if double_bond_sep:
        set_chemfig += ",double bond sep={:s}".format(double_bond_sep) 
    if node_style:
        set_chemfig += ",node style={:s}".format(node_style)
    if bond_style:
        set_chemfig += ",bond style={:s}".format(bond_style)
    if debug:
        set_chemfig += ",scheme debug={:s}".format(debug)
    if arrow_style:
        set_chemfig += ",arrow styel={:s}".format(arrow_style)
            
    set_chemfig += "}"
    print(set_chemfig)


    self.add_to_preamble(set_chemfig)

def get_texcode_for_expression(self, expression):
    """Inserts expression verbatim into TeX template.

    Parameters
    ----------
    expression : :class:`str`
        The string containing the expression to be typeset, e.g. ``$\\sqrt{2}$``

    Returns
    -------
    :class:`str`
        LaTeX code based on current template, containing the given ``expression`` and ready for typesetting
    """
    return self.body.replace(self.placeholder_text, "\n\\schemestart\n"+expression+"\n\\schemestop\n\n")

def get_texcode_for_expression_in_env(self,expression,environment):
    """Inserts an expression wrapped in a given environment into the TeX template.

    Parameters
    ----------
    environment : :class:`str`
        The environment in which we should wrap the expression.
    expression : :class:`str`
        The string containing the expression to be typeset, e.g. ``"$\\sqrt{2}$"``

    Returns
    -------
    :class:`str`
        LaTeX code based on template, containing the given expression and ready for typesetting
    """
    print(environment)
    begin = r"\begin{" + environment + "}" + "\n\\schemestart"
    end = "\\schemestop\n" + r"\end{" + environment + "}"
    print(begin,end)
    return self.body.replace(
        self.placeholder_text, "{0}\n{1}\n{2}".format(begin,expression, end)
    )

`

from chanim.

sexy-Chen avatar sexy-Chen commented on July 1, 2024

After I modified the ChemTemplate and chem_objects.py code the way you did, the generated video (.mp4) has some problems, all the chemical element symbols overlap, but the generated gifs are correct, but I don't know why, sad.

from chanim.

uwezi avatar uwezi commented on July 1, 2024

This is almost too long ago for me to remember what I did, how and why.
Let me check later...

from chanim.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.