# A 3D Agent-Based Model of Lung Fibrosis
## 2 Materials and Methods
### Building the Simulation Space  
Human and mammary airways can be split in two subsystems: the proximal, ending with the terminal bronchioles, where conducting airways move air inside and outside the body, and the distal/peripheral, where the actual oxygen exchange takes place in the acinar airways [4]. Within the latter, further morphological structures can be distinguished: some 30,000 acini branch by irregular dichotomy for 8-9 generations, terminating with alveolar sacs. The non-terminal segments that make up the branches of an acinus are the alveolar ducts (256 per acinus on average [4]), onto which clusters of alveoli with common openings towards the lumen are localized (the same holds for alveolar sacs). Previous work has reported an average length of 730 \(\upmu\)m and an average outer diameter of 600-699 \(\upmu\)m for the alveolar ducts, which can be seen as hollow cylinders [49; 50]. Given that the most common shape of a human alveolus is a three-quarter sphere [51] with an average diameter of 260 \(\upmu\)m [52], we estimate that each duct should serve between 18 and 24 alveoli, arranged in 3 rings of 6-8 alveoli each [53] (a slightly larger value can be found from the ratio between the total number of alveoli and the total number of segments).  
Our model aims to mechanistically replicate the onset of lung fibrosis on a scale bigger than the cellular one as the disease affects large portions of the pulmonary tissue. For this reason, we build our simulation space as a dichotomic tree structure (see Figure 2) that mimics a part of an acinus and choose the alveolar segments as agents. The tree expands along the z-axis in the 3D simulation space and each segment has the same length (thatis, the average segment length from [49; 50]), expressed in \(\upmu\)m. Since the average segment length and outer diameter are similar, we replace the segments with the corresponding inscribed spheres (spherical-shaped agents are included in the BioDynaMo platform). The algorithm that we implement to build the structure is the following:  
1. Given the number of generations Ngen, define the number of segments as Nseg = \(2^{\text{Ngen}}-1\), the average segment length as avgSegLength, and the vector containing the coordinates of all the agents as Coords.
2. Set the coordinates of the agent 0 (the first alveolar segment) to {0, 0, 0, 0} (i.e., the center of the simulation space), its unique index to 0, its origin to {0, 0, -avgSegLength/2}, and its end to {0, 0, 0, avgSegLength/2}. Add {0, 0, 0, 0} to Coords.
3. Loop (Nseg/2) times. At each step (starting from 1): 1. Define the index of the father agent (i.e., the one from which branch 1 and branch 2 stem) as father = [(step + 1)/2] - 1. 2. Project the coordinates of the father agent along its axis by avgSegLength. 3. For each of the two new branches: 1. Generate random polar and azimuthal angles \(\theta\) and \(\varphi\). 2. Rotate the projected father agent by \(\theta\) and \(\varphi\), keeping its origin fixed. 3. If the branch doesn't overlap with the other agents already in the tree add its coordinates to Coords. 4. If the branch overlaps with any of the other agents already in the tree, go back to step i.
4. Write Coords to a file, so that it can be used for multiple simulations.  
Specifically, our tree branches at random angles for 7 generations and includes a total of 127 alveolar ducts, which fit inside a simulation volume of 10,000 \(\upmu\)m\({}^{3}\) (or 1 cm\({}^{3}\)). The ranges that we choose for \(\theta\) and \(\varphi\) are [20\({}^{\circ}\), 160\({}^{\circ}\)] and [45\({}^{\circ}\), 89\({}^{\circ}\)], respectively, and are the smallest that allow the tree to fully develop without overlaps. Since the alveolar ducts could be further decomposed into multiple agents (i.e., the alveoli) made up of subagents (i.e., the cells, [54]), the agents in our model can be seen as meta-agents.