# Define my own substance

**URL:** <https://discourse.kitware.com/t/define-my-own-substance/1298>\
**Category:** Pulse Physiology Engine\
**Created:** [May 30, 2024, 10:39pm UTC](https://discourse.kitware.com/t/define-my-own-substance/1298 "2024-05-30T22:39:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yiwen\_Hu](https://discourse.kitware.com/user_avatar/discourse.kitware.com/yiwen_hu/32/889_2.png) [@Yiwen\_Hu](https://discourse.kitware.com/u/Yiwen_Hu)\
**Post date:** [May 30, 2024, 10:39pm UTC](https://discourse.kitware.com/t/define-my-own-substance/1298/1 "2024-05-30T22:39:57Z")

</div>

Hi!

I’m wondering if I can use the serialize\_from\_file to define a substance in the python SDK of Pulse Physiology Engine, as I didn’t find such a method in the python codes?

Many Thanks

---

<div class="post-metadata">

**Author:** ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)\
**Post date:** [May 31, 2024, 2:18am UTC](https://discourse.kitware.com/t/define-my-own-substance/1298/2 "2024-05-31T02:18:33Z")

</div>

To define a new substance, we modify the [Data.xlsx](https://gitlab.kitware.com/physiology/engine/-/blob/stable/data/Data.xlsx?ref_type=heads) Substances tab  
Just expand a comperable substance and copy the 4 associated columns  
 ![image](https://discourse.kitware.com/uploads/default/original/1X/43e3e3718240d955689d35f379b4d33b50734411.png)

and paste it where you want it and fill out the properties for you particular substance.

Then run the `genData` option from the [Pulse dev tools](https://gitlab.kitware.com/physiology/engine/-/wikis/Test-Suite)

This will generate a substance for use in Pulse

---

<div class="post-metadata">

**Author:** ![Yiwen\_Hu](https://discourse.kitware.com/user_avatar/discourse.kitware.com/yiwen_hu/32/889_2.png) [@Yiwen\_Hu](https://discourse.kitware.com/u/Yiwen_Hu)\
**Post date:** [May 31, 2024, 1:15pm UTC](https://discourse.kitware.com/t/define-my-own-substance/1298/3 "2024-05-31T13:15:51Z")

</div>

Thanks for your reply!

 ![image](https://discourse.kitware.com/uploads/default/original/1X/e5169643494f30e5ef26d28fe00dfda2d04ccccf.png)

For example I added a new PropofolChange, should just leave the reference value, reference source, notes/pages columns blank?

Many thanks

---

<div class="post-metadata">

**Author:** ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)\
**Post date:** [May 31, 2024, 1:24pm UTC](https://discourse.kitware.com/t/define-my-own-substance/1298/4 "2024-05-31T13:24:16Z")

</div>

If you are going to push this back into the repository, we require that you reference where/how you get your values from so we can properly review, test, and assure that PK/PD is appropriate.  
You can see that a lot of drugs have a single URL on one row where we get most data.

This is assuming you trying to model an available real world drug.

We do have drugs like, our oversedation drug that is used for specific targeted effect, so no references there.

As always, documentation and sourcing is always a good practice, but it depends on what you are trying to accomplish

---

<div class="post-metadata">

**Author:** ![Yiwen\_Hu](https://discourse.kitware.com/user_avatar/discourse.kitware.com/yiwen_hu/32/889_2.png) [@Yiwen\_Hu](https://discourse.kitware.com/u/Yiwen_Hu)\
**Post date:** [May 31, 2024, 1:39pm UTC](https://discourse.kitware.com/t/define-my-own-substance/1298/5 "2024-05-31T13:39:52Z")

</div>

Thanks for your reply!

No, I’m just testing see if I can modify any of the substance properties, not pushing it back to the repo. I was just wondering why I still get this Unknown Substance error, as I can already see the PropofolChange.json file in the bin/substance folder. So I thought these three columns might have gone wrong. However, it seems that there’s some other problems.

 ![image](https://discourse.kitware.com/uploads/default/original/1X/8dbdd4714db923c8fe7fab7bd8c93039f02f6957.png)

Many thanks

---

<div class="post-metadata">

**Author:** ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)\
**Post date:** [May 31, 2024, 1:44pm UTC](https://discourse.kitware.com/t/define-my-own-substance/1298/6 "2024-05-31T13:44:54Z")

</div>

Ah  
So you are loading a state.  
States contain the substance database  
You have created a new substance, but your state file does not have that new substances in it.

Now you will need to regenerate those states so they contain your new substance.

To generate all states, execute `./run.sh genStates` from the install/bin directory  
Or if you just want to generate StandardMale, you can execute `./PulseScenarioDriver InitialPatientState.json`, which will just generate the StandardMale state

Then try your test again

You can open that states/StandardMale@0s.json and search for your new substance after state generation

---

<div class="post-metadata">

**Author:** ![Yiwen\_Hu](https://discourse.kitware.com/user_avatar/discourse.kitware.com/yiwen_hu/32/889_2.png) [@Yiwen\_Hu](https://discourse.kitware.com/u/Yiwen_Hu)\
**Post date:** [May 31, 2024, 1:53pm UTC](https://discourse.kitware.com/t/define-my-own-substance/1298/7 "2024-05-31T13:53:48Z")

</div>

Thank you so much! Your explanation makes perfect sense and that worked!

I wonder if I serialze the patient data from a file, instead of using states, and then do an infusion. I don’t need to run genStates, do I?

 ![image](https://discourse.kitware.com/uploads/default/original/1X/342adff49d8473b73cddadee52ff4bdcf690f9dc.png)

---

<div class="post-metadata">

**Author:** ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)\
**Post date:** [May 31, 2024, 1:56pm UTC](https://discourse.kitware.com/t/define-my-own-substance/1298/8 "2024-05-31T13:56:46Z")

</div>

That will load a json file into a SEPatient object, but you want to initialize your engine with that patient.

You should play with this [initialization method](https://gitlab.kitware.com/physiology/engine/-/blob/stable/src/python/pulse/engine/PulseEngine.py?ref_type=heads#L89), should be plenty of HowTo’s demonstrating using this method

---

<div class="post-metadata">

**Author:** ![Yiwen\_Hu](https://discourse.kitware.com/user_avatar/discourse.kitware.com/yiwen_hu/32/889_2.png) [@Yiwen\_Hu](https://discourse.kitware.com/u/Yiwen_Hu)\
**Post date:** [May 31, 2024, 1:59pm UTC](https://discourse.kitware.com/t/define-my-own-substance/1298/9 "2024-05-31T13:59:04Z")

</div>

Thank you so much! I can see plenty of examples in the HowTos!
