> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ntop.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to set up a DOE in Python for nTop Automate

## Question:

How to set up a DOE in Python for nTop Automate

## Applies to:

* nTop Automate
* DOE
* Python

## Answer:

1. Prepare your nTop notebook by setting up the Inputs and Outputs for running in nTop Automate ([Preparing an nTop Notebook for nTop Command Line](/help-articles/knowledge-base/ntop-automate/preparing-an-ntop-notebook-for-ntop-automate)). The inputs for this example are Unit Cell Size and Thickness, which we wish to change for multiple values and get the relative density values as output.

![An example notebook setup for running the notebook using Python and nTop Automate.](https://files.learn.ntop.com/help-articles/ntop-automate/17802688369171.png)

![A walled TPMS Unit Cell. The Thickness, Unit Cell Size, and Bounding box are labeled.](https://files.learn.ntop.com/help-articles/ntop-automate/17802688370963.png)

<Tip>
  \*\*Tip:\*\*These learning center courses have step-by-step instructions and examples for automating your nTop files ([https://learn.ntop.com/courses/230-intro-to-automation/](https://learn.ntop.com/courses/230-intro-to-automation/)and [https://learn.ntop.com/courses/330-ntop-automate/](https://learn.ntop.com/courses/330-ntop-automate/))
</Tip>

2. Run the -t template command in ntopcl with the nTop file to generate the *input\_template.json* and *output\_template.json*

* [input\_template.json](https://ntop.box.com/s/2o84yxvhbw4hzsbjcxmukoj16zmdb6xw)
* [output\_template.json](https://ntop.box.com/s/75ip22vtx625kwp3phjgmnqiizphswot)

3. Open your preferred code editor and create a new .py file to run the script to generate multiple input JSON files for running multiple values.

This article ([Running nTop Command Line in Python scripts](/help-articles/knowledge-base/ntop-automate/running-ntop-automate-in-python-scripts)) has a Python template file you can use as a base and modify for your use case.

*Tips: There are two important things to remember while using a list of values to run multiple iterations. You can use a list directly for one of the inputs; see below for how we have used thickness values. To use another list input, we will create multiple input.json files to run DOE; see below how we have used cellsize\_values.*

[Python Script to download](https://ntop.box.com/s/oqk8foftbmdm3uxyolljg6ougqjzfb7a)

```

 import os
 import subprocess
 import json

 # Assuming this script, ntop file, and json files will be in the same folde
 Current_Directory = os.path.dirname(os.path.realpath('__file__'))
 exePath = r"C:/Program Files/nTopology/nTopology/nTopCL.exe" # nTopCL path
 nTopFilePath = r"RelDensity.ntop" # nTop notebook file name
 Output_Directory = r"C:\Users\ajayprasad\Downloads\RelDensity" # Output directory path
 Input_File_Name = "input{}.json" # JSON input file name template
 Output_File_Name = "out{}.json" # JSON output file name template

 # Input variables in JSON structure
 thickness_values = [round(x * 0.1, 1) for x in range(1, 21)] # List of thickness values from 0.1 to 2 with increments of 0.1
 cellsize_values = [round(x * 0.5, 1) for x in range(1, 21)] # List of L values from 0.5 to 10 with increments of 0.5

 # Iterate over each cell size value
 for i, cellsize in enumerate(cellsize_values):
 Inputs_JSON = {
 	"description": "",
 	"inputs": [
 {
 "description": "",
 "name": "Output directory",
 "type": "text",
 "value": Output_Directory
 },
 {
 "description": "",
 "name": "Unit cell",
 "type": "enum",
 "value": 0
 },
 {
 "description": "",
 "name": "L",
 "type": "real",
 "units": "mm",
 "value": 10.0
 },
 {
 "description": "",
 "name": "Unit Cell Size",
 "type": "real",
 "units": "mm",
 "value": cellsize
 },
 {
 "description": "",
 "name": "Thickness",
 "type": "real",
 "units": "mm",
 "values": thickness_values
 }
 ],
 "title": "Relative Density of Walled TPMS"
 }

 # Create input.json file
 input_file_name = Input_File_Name.format(i + 1)
 with open(input_file_name, 'w') as outfile:
 json.dump(Inputs_JSON, outfile, indent=4)

 # nTopCL arguments in a list
 Arguments = [exePath] # nTopCL path
 Arguments.append("-j") # json input argument
 Arguments.append(input_file_name) # json path
 Arguments.append("-o") # output argument
 output_file_name = Output_File_Name.format(i + 1)
 Arguments.append(output_file_name) # output json path
 Arguments.append(nTopFilePath) # .ntop notebook file path
 Arguments.append("-v2")

 # nTopCL call with arguments
 print("Running nTopCL with input file: {}".format(input_file_name))
 print(" ".join(Arguments))
 output, error = subprocess.Popen(Arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()

 # Print the return messages
 print(output.decode("utf-8"))
```

4. When you run this script, the folder will have multiple input and output JSON files generated.

![After running the script, a JSON file is generated for each input and output configuration of the unit cell.](https://files.learn.ntop.com/help-articles/ntop-automate/17802864210707.png)

5. You can then write a script to read the output JSON files to plot as needed.

![3D Plotting the JSON file results to compare Thickness, Relative Density, and Cell Size.](https://files.learn.ntop.com/help-articles/ntop-automate/17803158109715.png)

![A 2D plot showing Relative Density as a function of Thickness.](https://files.learn.ntop.com/help-articles/ntop-automate/17803120085907.png)

## Attachments

[RelDensity.ntop](https://ntop.box.com/s/kfjjidq9r9th2jxoxrgaku8ymr4l5v4x)

## Keywords:

*lattice question ntopcl python json doe relative density ntop automate loop*
