Menu

Create new Compound via Python

Ella Daiki
2023-02-16
2023-02-16
  • Ella Daiki

    Ella Daiki - 2023-02-16

    Hello all,
    I would like to create and add a new compound into DWSIM database using python script, so that i can add the compound into my simulation afterwards.

    I want to add a protein such as lysin and save the following data: Name, CAS, formula, molecular weight and SMILES.

    Here is want I tried:

    -> Import the necessary classes:
    from DWSIM.Thermodynamics.BaseClasses import Compound

    -> Create a new instance of the CompoundData class:
    compound = Compound("Lysin", "Protein")

    -> Set the compound's properties:
    compound.CAS = "70-54-2"
    compound.Formula = "C6H14N2O2"
    compound.Name = "Lysin"
    compound.MolecularWeight = 146.19
    -> SMILES?

    ->Add the compound to the database:
    compound.SaveData()

    -> Create new flowsheet to add lysin
    interf = Automation3()
    sim = interf.CreateFlowsheet()
    sim.AddCompound("Lysin")

    But this doesn't work. I think the compound is not saved in the database. Does anyone know how to add lysin into the database? Should I save lysin in a dictionary as a XML or JSON file first?

    I hope I was able to describe my problem in an understandable way. Thanks in advance!

     
  • Daniel Medeiros

    Daniel Medeiros - 2023-02-16

    Hi,

    This data is not enough to perform simulations, unless it is a solid and will always be a solid.

    Also, AddCompound() only works with compounds that are on the database already.

    Depending on the property package that you want to use, you'll have to provide a curve for vapor pressure, ideal gas heat capacity, critical properties and acentric factor as a minimum. Then you save the JSON file into the "addcomps" folder so they will be available to add through AddCompound().

    I recommend using the compound creator to create the json before going to automation.

    Regards,
    Daniel

     
    👍
    1
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.