402 capstone thesis

67
Ning Shu BIOEN402 SENIOR YEAR CAPSTONE THESIS Designing An Aqueous Environment Adhesive Derived From E. Coli Fimbriae: A Computational Approach By Ning Shu Principle Investigator/Mentor: Wendy E. Thomas Department of Bioengineering, University of Washington

Upload: nina-shu

Post on 08-Apr-2017

65 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

Designing An Aqueous Environment Adhesive Derived From E. Coli Fimbriae: A Computational Approach

By Ning ShuPrinciple Investigator/Mentor: Wendy E. Thomas

Department of Bioengineering, University of Washington

Page 2: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

Table of Contents

1. BACKGROUND & SIGNFICANCE......................................................................................................... 31.1 Introduction............................................................................................................................................... 31.2 Literature Review & Previous Work..................................................................................................3

1.2.1 Current Adhesion Landscape..........................................................................................................................31.2.2 Previous Work on E. coli Fimbrial Adhesion............................................................................................5

1.3 Financial Support..................................................................................................................................... 81.4 Consequence of Success..........................................................................................................................91.5 Economic Significance............................................................................................................................. 91.6 Ethical and Legal Implications.............................................................................................................9

2. METHODS & DESIGN APPROACH................................................................................................... 102.1 Overview of Equations, Experimental Set-Up and Design Approach...................................102.2 Data Acquisition..................................................................................................................................... 12

2.2.1 Fimbrial Mesh Set-Up.......................................................................................................................................122.2.2 AFM Driver............................................................................................................................................................122.2.3 Global Parameters Input.................................................................................................................................122.2.4 Simulation Core Code.......................................................................................................................................132.2.5 Outputs & MATLAB...........................................................................................................................................142.2.6 VMD Visualization of the AFM experiment.............................................................................................142.2.7 AFM pull experiments: trajectory analysis.............................................................................................14

3. RESULTS & DISCUSSIONS................................................................................................................. 163.1 Research Data & Design Process.......................................................................................................16

3.1.1 Figure 8: Effect of Pulling Speed on Maximum Rupture Force and Work of Adhesion. Using default k12 type I fimbria parameters....................................................................................................183.1.2 Figure 9: Effect of varying k1,2 on-rate and k2,1 off-rate......................................................................193.1.3. Figure 10: Effects of Varying Coiling Parameter Ka,b.......................................................................213.1.4 Figure 11: Effects of Varying Coiling Parameter kb,a...........................................................................223.1.5: Final Design & Improvements in Adhesiveness..................................................................................233.1.6 Statistical Analysis.............................................................................................................................................23

CONCLUSION & FUTURE DIRECTIONS................................................................................................ 27

KEY PERSONNEL & RESOURCES........................................................................................................... 28Key Personnel................................................................................................................................................ 28Resources......................................................................................................................................................... 28

Works Cited......................................................................................................................................... 29

Page 3: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS1. BACKGROUND & SIGNFICANCE

1.1 IntroductionThe biophysics of how organisms adhere to surfaces is of great interest to the field of

biomimetic and bioengineering, as the process of evolution has already provided many novel and effective biological adhesive mechanisms. The operating conditions for these adhesive mechanisms vary vastly in terms of the magnitude of force as well as the function it performs—some adhesives are designed to release under certain conditions, such is the case for E. coli adhesion, while some are meant to become death grips such as in the case of marine mussels. Consequently, these tools provided by nature would have to be studied and applied in the context of trade-offs between adhesive strength, adhesion reversibility, and the target chemical environment.

The current adhesive design landscape is filled with options in terms of getting creative, but designs generally fall into the categories of either dry or wet adhesives. The gecko is a famous model organism for adhesive design, however as a dry adhesive it is not suited for aqueous environments, a particular environment of great interest to bioengineers as it pertains to organs and tissues of a biological system. Wet adhesives, on the other hand, are by definition able to perform well within aqueous environments, particularly in cases of tissue adhesion inside a body or organ. Two promising models exist for the wet adhesive landscape: the marine mussel and the intestinal bacteria E. coli. E. coli is unique in its ability to not only form strong bonds with a mannose surface, but also forming bonds that are completely reversible—in other words, maintaining adhesive strengths after repeated attachment and detachment cycles to mannose without leaving behind residues that could reduce the adhesiveness. However, the magnitude of force associated with E. coli adhesion is only within the nano-scale, and efforts in replicating the strong adhesion in the micro-scale has been unsuccessful, which poses a unique design question—what could be done to increase the adhesiveness, but at a bigger scale and yet still retaining the reversibility?

In terms of applications, drug delivery systems frequently target the mucous parts of the body such as the intestines and nose for its accessibility and blood supply, but without proper securement to the epithelia the delivery system would not have enough time to release its content before becoming displaced by the shear flow of mucous layer. Likewise, diagnostic procedures such as endoscopy has reached a stage involving less invasive techniques such as robotic capsules, but the success of this method depends on the mobility of the capsule in shear flow environments, and bio-adhesives that work in such an environment can greatly enhance its effectiveness if it is able to bind strongly and reversibly. Therefore, understanding the binding mechanism of E. coli could well be the solution to the creation of a smart adhesive designated for use in aqueous application.

1.2 Literature Review & Previous Work

1.2.1 Current Adhesion LandscapeAs mentioned briefly before, the gecko’s ability to adhere to vertical walls is well known

and this particular adhesion mechanism dominates the dry adhesive design landscape. The gecko’s foot is composed of hair-like structures called setae that are capable of standing up to

Page 4: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS~200 μN of force each in non-aqueous environments, which amounts to a staggering support load of 100 N per gecko foot1. Taking advantage of this amazing property, synthetic versions of the gecko adhesives have been developed and refined, the most prominent product being the Waalbot, a synthetic gecko-inspired wall-climbing robot that could climb steep walls at 90-degree angles with great agility2. Yet despite the gecko adhesive’s impressive strength, it is restricted from widespread biological applications as it fails in aqueous environments unless modified.

On the wet adhesives landscape, the mechanisms of focus are primarily that of the marine mussel and the E. coli bacteria. It is known that E. coli type I fimbria binds to a mannose molecule or a mannose glycoprotein via a receptor-ligand mechanism and that shear forces actually enhance the binding strength. This anti-intuitive behavior is proposed by Wendy et al. to be the result of allosterically regulated catch bonds, where the E. coli receptor FimH undergoes conformational change to a strong affinity state upon experiencing a certain level of shear force, which results in the formation of bond that is longer-lived 3. The implication of the allosteric model is that when the shear force reverts to a lower level, the high affinity state of the receptor actually switches back to the low affinity state, effectively “releasing” the ligand and creates a new opportunity for binding—essentially, the catch bond behavior not only smartly increase adhesion when needed but also has the potential for a completely reversible adhesive. However, one of the biggest obstacles for an E. coli-based adhesive is scaling, as Atomic Force Spectroscopy (AFM) experiments with FimH films demonstrate that adhesive strength is not scaling proportionally higher as the contact area increases, which seriously hinders application on the macroscale4. Fortunately, it has been discovered that the inclusion of the fimbriae linkage portion FimA into the FimH films effectively increased bond lifetimes and the overall adhesiveness, which suggests that the FimA structure has a significant role in buffering the forces exerted on the E. coli fimbria4. In fact, Forero et al proposed that FimA is capable of uncoiling its tertiary structure to elongate and buffer the forces applied to the fimbria5. The mechanisms in which FimA and FimH affects fimbrial adhesion will be elaborated on in further detail throughout this paper.

Aside from E. coli, the marine mussel is another organism that utilizes wet adhesive mechanisms, specifically through the unique modified amino acid 3,4-dihydroxy-L-phenylalanine (DOPA). DOPA is unique in that the dissociation force between its adhesive bonds is strong, in the range of hundreds of pico-Newtons3. It has been observed that through oxidation, DOPA allows the mussel to bind reversibly to a metallic surface but irreversibly to organic, aqueous surfaces4. Although the DOPA amino acid exhibits extraordinary binding strength and also provides unique flexibility in terms of binding to both organic and inorganic surfaces, which are all useful properties, its lack of reversible binding to organic surfaces would limit its range of applications unless this limitation could be overcome through synthetic processes.

Most interestingly, there have been recent efforts in developing a hybrid gecko-mussel adhesive and they were able to successfully develop the “geckel” adhesive, which retains the adhesive’s binding strength under water (which normally would have been lost) by coating a synthetic gecko-inspired micropillar adhesive with a mussel-inspired DOPA infused polymer layer5. However, the geckel still performs far better in dry environments than in aqueous

Page 5: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISenvironments: the adhesive strength being higher for gecko in air than in water, and the reversibility is higher in air than water as well.

A key distinction between the E. coli adhesive and the geckel adhesive is that the geckel binds reversibly only to an inorganic surface whereas the E. coli adhesive is capable of reversibly binding to organic, glycosylated surfaces. Therefore these two mechanisms are not the same and should have different applications completely. In addition, it is not known if the geckel’s adhesive efficacy can be scaled to a bigger area than the current half a square centimeter surface area, which interestingly is a similar concern faced by E. coli adhesive design as scaling E. coli adhesion to the macro scale has also proven to be difficult [5]7.

1.2.2 Previous Work on E. coli Fimbrial Adhesion

OverviewAs mentioned earlier, E. coli readily adhere to tissues in wet conditions using receptor-

ligand bonds. This particular mechanism is advantageous for three reasons: first, receptor-ligand bonds are optimal for an aqueous environment; second, the ligand mannose is present in mannose glycoproteins that exist on most human and tissues; third, previous work on FimH and mannose sugar binding has shown that not only is FimH-mannose binding strong and reversible on the nano-scale, it is also non-fouling, a term in adhesion meaning being able to retain bond strengths after numerous repeated interactions between FimH and mannose without leaving residues on the binding surface4.

The study of these adhesion mechanisms is largely based on simulations coupled with atomic force microscopy (AFM) and parallel-plate flow chamber experiments. Previous work began on leukocyte microvilli adhesion, which has similarities to type I fimbrial adhesion as both structures involve a “tether” linker structure with a receptor structure at its tip that identifies carbohydrate molecules3. Briefly, leukocyte adhesion involves short and stubby microvilli with selectin cells, whereas fimbria is comprised of the long coiled rope-like structure FimA and the receptor FimH at the outer tip of the FimA. To reiterate a point made earlier, the adhesion behavior of the fimbria is the combination of FimH catch-bond formation and FimA uncoiling behavior. The structure of the fimbria is presented in Figure 1.

Figure 1: Forero et al., 2006. Schematic of the Fimbria Structure within an AFM experiment. Here an AFM cantilever coated with mannose (red dots) is pulling on a fimbria that is uncoiling at the base (FimA) while attached to the receptor FimH on top.

Page 6: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISCatch-Bonds

Catch-bond formation between the receptor FimH and mannose is shear-enhanced and allosterically regulated. Specifically, the FimH adhesion receptor protein has two distinct shear-force activated conformations, one low affinity state and one high affinity state, that result in two distinct unbinding rates that are inversely related to the shear-force. In other words, since unbinding rate is inversely proportional to the bond lifetime, FimH anti-intuitively forms a longer lived, stronger bond with mannose at a high shear force, but a short lived and weaker bond at low shear force4. Therefore, the allosteric catch bond model explains how E. coli bacteria are able to achieve adhesion at higher shear flow, by activating the higher bond strength conformation of FimH receptors. An implication of this behavior is that receptor-ligand bond based adhesives are self-cleaning and reversible, since at low shear flow, the FimH receptor returns to the weaker conformation and releases the ligand, therefore the target tissue (ligand) is not being harmed through adhesion, leaving no residue of binding, and the FimH is ready to bond strongly again when the shear increases.

However, data from flow-chamber experiments in the Wendy Thomas lab also shows that between stationary adhesion at high shear and free floatation at low shear exists a “stop-and-go” phase called “shear-stabilized rolling” that which the previous allosteric catch bond model could not explain entirely, indicating that catch-bond mechanism is not the entire story9. The implication of the discovery of this shear-stabilized rolling behavior of E. coli is that the E. coli adhesion mechanism is not just about catch-bonds between FimH and mannose, but also highly dependent on the physical behavior of the FimA “tether” segment that connects the E. coli body with its FimH receptors.

UncoilingIndeed, FimA, (the fimbriae “tethers”) proved to be absolutely essential in the force

loading capability of E. coli in any force effects, not just shear forces, as observed in AFM experiments. The fimA segments serve as shock absorbers for the FimH receptors at the tip when the FimH-mannose bond is subject to high force. AFM experiments involving FimH films (FimH without FimA) and fimbriae (FimH and FimA intact) films indicate that FimH receptors arranged into a film is much weaker than films made out of whole fimbriae where the FimA is present, and this is particularly true as the target mannose surface increased in size and contact area increased to the micro-scale4. Further investigation on the fimbria properties indicates that a fimbria is nonlinearly elastic, being extremely stiff at low shear force but highly elastic at high shear force and even exhibits an uncoiling mechanism that buffers the force loading process over a specific threshold shear force and equalizes the load across bonds like shock absorbers5. In addition, this finding validates previous literature suggesting that pili-like structures like fimbria can have cooperative binding of multiple pili that leads to the distribution of load and improved bond strength such that two pili can take on more forces than allowed by each pili on its own9. (see Figure 2)

This cooperativity of pili structures is in turn determined by the intrinsic qualities of the individual pilus involved. Because real life adhesives are on a much larger size and time scale, it is vital to consider incorporation of fimbriae properties into the simulation and design of the wet

Page 7: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISadhesive, since it is inherent that using mere FimH-mannose binding alone is not strong enough to create a strong adhesive.

Figure 2: Elongation from single pillus and two pili combined

Source: Multipili attachment of bacteria with helixlike pili exposed to stress. 9

In order to effectively design a reversible wet adhesive, the Wendy Thomas’ laboratory’s approach is to perform research experiments on FimH and mannose bonding using AFM experiments, and then use computational model to fit these experimental data so that the simulations can then be used to determine optimum design parameters for the wet adhesive. The fundamental framework of the initial Thomas lab fimbrial simulation by doctorate student Matthew Whitfield was first derived from Adhesive Dynamics by Hammer and Apte, where the approach indicated in the work served as the backbone structure of the computer codes10. E. coli is modeled as a spherical object with many fimbrial structures surrounding it, and the entire object is acted upon by numerous parameters such as but not limited to the ones indicated in Figure 3.

Figure 3: E. Coli modeling diagram, forces and structural features involved in simulation.

Page 8: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISSource: Simulations of cell rolling and adhesion on surfaces in shear flow: general results and analysis of selectin-mediated neutrophil adhesion. Hammer, D and Apte, S. 1992, Biophysical Journal, Vol. 63.

A sophisticated foundation simulation protocol written in C++ programming language has already been established, along with a set of automated MATLAB scripts that read and generate graphs and other visualizations from the output of the simulation program. The basic principles behind the simulations are: 1) uses Monte Carlo principles to simulate the randomness present in a real biological system 2) treating the coiled fimbria as a Hookean spring that uncoils into a worm-like chain and 3) sums the forces of fluid flow with fimbrial interactions with the mannose surface to calculate the state of the bond. The coding can be readily changed to account for any new parameters that arise and running the simulation can provide insights to the next direction for wet lab experiments, and vice versa, fitting the simulation to new experimental data is always crucial to acquire a more realistic model of the system.

The Fimbrial Simulation has two experiment modes, AFM or FLOW representing AFM or flow chamber experimental set ups, respectively. The simulation code for the AFM mode has been modified extensively by graduate student Keith Johnson to reflect realistically the orientation of mannose and fimbriae surfaces. Specifically, the AFM experiment from the previous version of the simulation has a bead covered with radially-spread fimbriae moving towards a mannosylated surface, but in reality most of the AFM experiments performed, such as the representative AFM experiment pulls from the publication “A Nanoadhesive Composed of Receptor Ligand Bonds” has a mannosylated bead moving towards a fimbriae-covered surface. The orientation mismatch has resulted in incongruent data and in response, the code was modified to accommodate the addition of a fimbriae mesh set up, where the fimbriae are arranged in a haystack manner to more realistically represent a fimbriated surface. The bead is changed to a simple mannose bead similar to the kind that is attached to an AFM cantilever. The protocol to achieve the fimbrial mesh is specified further in the methods section.

1.3 Financial SupportThe study and designing of reversible wet adhesive at the Wendy E. Thomas laboratory is

supported by the National Science Foundation’s CAREER award. The mission statement of the National Science Foundation is to promote the progress of science; to advance the national health, prosperity, and welfare; [and] to secure the national defense" by “keeping close track of research around the United States and the world, maintaining constant contact with the research community to identify ever-moving horizons of inquiry, monitoring which areas are most likely to result in spectacular progress and choosing the most promising people to conduct the research 12.” The Career Award specifically awards junior faculty who demonstrates “leadership in integrating education and research” 12. This funding has provided not only research funding for the development of a wet adhesive that would have an impact on healthcare but also provided valuable research opportunities to both undergraduate and graduate students.

Generally, any research that can implicate the optimization of a drug delivery process is of high interest to pharmaceutical companies, as successful delivery of dosage is often crucial to obtain the statistically significant differences in drug trials, and passing drug trials opens the door

Page 9: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISto the launch of highly profitable products to market. In addition, while E. coli adhesion to the intestinal wall is normally harmless, significant urinary tract infection could result from mutated, virulent E. coli strains that display a different glycoprotein binding behavior. Knowledge of E. coli adhesion could therefore lead to the development of anti-adhesive drugs against pathogenic E. coli strains, effectively eliminating reliance on antibiotics for treatment of infections. Furthermore, bioinstrumentation companies would also be likely to fund such research because instruments often require strong adhesion to tissues and cells to function properly, but the adhesive should not tarnish the tissue it binds to after the instrument is removed, therefore requiring the reversible characteristic of the smart adhesive.

1.4 Consequence of SuccessThe immediate application of a successful E. coli-derived reversible wet adhesive would

most likely result in the drastic improvement of endoscopic micro-robots used for endoscopy diagnostic technology. The adhesive would be certainly appropriate in terms of biocompatibility since the material is E. coli derived and E. coli is naturally found within the intestinal walls. The wet adhesive would allow the micro-robots to firmly adhere to the gastro-intestinal walls but at the same time the reversible quality would also allow the micro-robots to release the adhesion and move freely, while being less damaging to the GI tract walls compared to traditional endoscopic micro-robots. Improved GI tract diagnostics can greatly benefit patients who are suffering from Celiac disease, Crohn’s disease as well as colon cancer, as endoscopy capsules are less invasive and can serve as a more regular diagnostic tool for their conditions. In addition, the E. coli-derived reversible wet adhesive can be applied to biomedical instruments or drug delivery systems in general. When applied to robotic arms or fingers, the adhesive can provide a stronger grip but also mechanical endurance and dexterity, as the robotic device would have the ability to let go as commanded and repeat a certain motion indefinitely.

1.5 Economic SignificanceThe cost of a capsule endoscopy procedure is extremely high, with the recorder costing 25,000 dollars while the capsule itself anywhere from 250 dollars to 450 dollars each13. Although improved endoscopy methods would not necessarily cause a direct decrease in the cost of the procedure, it can improve better data acquisition while the capsule is within the patient and this in turn will reduce the number of repeats of the procedure, saving the patient money indirectly. According to a recent study on capsule endoscopy, given the low compliance rate for colonoscopy, colon capsule endoscopy might be a more effective and cheaper alternative for patients, saving the economy 16,165 dollars to 29,244 dollars per life-year saved14”.

1.6 Ethical and Legal ImplicationsBecause a wet reversible adhesive can have such wide range of potential areas of

application, the ethical implications of this design is far-reaching and complex. Although this technology can obviously do inherent good through the improvements of medical instruments, helpful robots and drug delivery, it is not unreasonable to assume the very same technology can be used for the improvements of weapons and agents of biological warfare. As mentioned in one particular lecture given by Dr. Paul Yager, chairman of the department of Bioengineering at the University of Washington, the ability to achieve a strong grip can result in the improvement of

Page 10: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIShandguns that might not serve the social interest even though the technology itself is quite benign. The development of the smart reversible adhesive has no immediate legal or economic implications, but due to the flexibility of this technology, there can be legal or economic impacts that are out of the control of the original designer as a result of others applying this technology to advance their own means. Certainly, if the adhesive is being used for refining biomedical or drug delivery processes and robotics, one could expect increase in productivity leading to more consumptions and jobs within at least the biomedical industry. However, it is possible, as with any advances in the field of biology, that the technology could be used toward weapons of biological warfare. A specific scenario could be the development of a mutant strain of E. coli that is optimized adhesively to be the most virulent strain, which could devastate human population should it contaminate food or water sources.

2. METHODS & DESIGN APPROACH

2.1 Overview of Equations, Experimental Set-Up and Design ApproachThe simulation characterizes the adhesive behavior of a particular AFM experiment through a series of parameters. The parameters can be roughly categorized into three categories, experimental, state rate constants, and coiling rate constants. The values of these parameters are set to the default values derived from previous experiments unless specifically altered for the purpose of experimentations. Table 1 exhibits some of the experimental/simulation parameters. The state rate parameters are k0,1, k0,2, k1,2 and k2,1, representing transition rate from unbound to weak state, unbound to strong state, weak to strong state and strong to weak state respectively (See Figure 5).

Figure 4: 2-state model of fimbrial adhesion binding.3These bond transition are related to the force acting upon the fimbria as modeled by the following equation:

Equation 1: bond transition equation relating bond state, transition distance, and force where i is 1 or 2, and j is 0, 1 or 2 and x are the transition distances. 3

TkFx

kkB

bijoijij exp

Page 11: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISLastly, another major contributor to the adhesive behavior is the uncoiling phenomenon, characterized by segmenting the FimA into three distinct segments. Section A is modeled as a coiled spring, while section B and C are modeled as worm-like chains. As the FimA uncoils, the effective distance of the three segments changes.

Equations 2 and 3: Force dynamics of the three uncoiling segments

The transition rates between states A and B are given by

the transition rates between state B and C:

One very important equation relates the velocity of extension to the force experienced by the bond (uncoiling velocity and uncoiling force)

where Ku is Kab while Kc is Kba, ΔXu is Xab and ΔXc is Xbc. ΔL is 5.0 nm. 5

Equation 8: Extension Velocity as a function of the Force on the Fimbria

Page 12: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISTable 1 Simulation parameters

Symbol Variable Value

kB Boltzmann constant 1.38 10-23

J/K

T Temperature 298° K

n Number of fimbriae 186

ka Fimbrial stiffness 2.06 pN/nm

Lavg Average fimbrial length 0.572 μm

E Fimbrial elasticity 2 GPa

ρ Cell density 1300 kg/m3

η Fluid viscosity 0.001 Pa*s

r Cell radius Variable*

τ Time step 500 ns

2.2 Data Acquisition

2.2.1 Fimbrial Mesh Set-UpGraduate student Keith Johnson has implemented a new scheme for the AFM experiment

mode, where fimbriae are arranged into a haystack-like orientation through a MATLAB script called Fim_Fall. The script simulates a realistic fimbriated surface by letting the fimbriae “fall” onto a surface and on top of one another in a randomized fashion, taking in fimbrial density, fimbrial surface area and equilibrium fimbrial length as parameters. The output of this script is a set of six coordinate files (x_start, x_end, y_start, y_end, z_start, z_end, respectively) that will serve as inputs for the execution of the core simulation code. See Figure 6 for a visual example of the fimbrial mesh. For all experiments performed, the fimbrial density used is 240 fimH per square micron of area and the equilibrium fimbrial length is the literature value of 0.572 microns 4.

2.2.2 AFM DriverThe simulated AFM experiment requires a driver input file that serves as the trajectory of

the AFM cantilever. The script driver.m is called to generate three driver files, one for each of the axis. The inputs to the program are arrays xstr, ystr and zstr, which each represent an array dictating the movement of in the specific axis. For example, xstr = {0, ‘t’, 20} would signify a movement of 0 microns/s, with time variable t, for 20 seconds.

2.2.3 Global Parameters InputAs aforementioned, the global parameters are saved inside a text file that is read in by the

main simulation code upon execution (See Table 3).

Table 2. Coiling parametersParameter Value

kAB 0.069 s-1

kBA 4.3x106 s-1

xAB 0.461 nm

xBA -1.9 nm

keqBC 2.63x105 s-1

xeqBC 0.64 nm

LpB 3.35 nm

LpC 0.516 nm

Page 13: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

Page 14: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISTable 3: List of global parameters and their respective values according to strain

PARAMETER DEFINITION UNITS/VALUE Strain:kb91 Strain: k12TYPE type of experiment AFM or FLOWTMAX runtime of simulation seconds(s)Fast amount of outputs 0=all, 1 = subsetTIMESTEP time step of simulation seconds(s)PPS times per second output times per second (s-1)Numfim total number of fimbriae 5654fluid_shear fluid shear rate times per second (s-1) 5000 5000cell_density density of cell kg/m3 1300 1300cell_radius radius of cell meters (m) 1.5*10^-6 1.5*10^-6cellE Young's Modulus for cell pascals (Pa)viscosity viscosity of fluid Pascal second (Pa*s)eq.fim_length mean fimbrial length meters (m) 0.572 10^-6 0.572*10^-6fim_stiffness effective fimbrial stiffness Newton/meter (N/m) 0.00875 0.00875fimbrialE Young's Modulus for Fim pascals (Pa) 2*10^9 2.00E+09kbT Thermal energy Joules (J) 4.21E-21 4.21E-21k01 state 1 (weak) on-rate times per second (s-1) 3 3k10 state 1 (weak) off-rate times per second (s-1) 6 1.37k12 transition from weak to strong times per second (s-1) 1.25E-03 3.00E-05k20 state 2 (strong) off-rate times per second (s-1) 5.00E-06 5.00E-06k21 transition rate from strong to weak times per second (s-1) 0.025 0.11ΔL10 transition distance (state 1 unbinding) meters (m) 4.52E-10 2.80E-10ΔL12transition distance from weak to strong meters (m) 1.20E-10 1.50E-09ΔL20transition distance for state 2 unbinding meters (m) 4.52E-10 4.52E-10ΔL21transition distance from strong to weak meters (m) -1.20E-09 -3.80E-10Ku kb,a (uncoiling) times per second (s-1) 4.3e6 4.3e6Kc ka,b (uncoiling) times per second (s-1) 0.0688 0.0688Naming what number to start appending to file nametorsional_stiffness allows scaling of torsional stiffness 0 or 1usecoil Allowing uncoiling 1 = yes, 0 = nomaxstate2 sets the max number of bonds allowed in state 2

2.2.4 Simulation Core CodeThe core simulation codes contain the main algorithms for the simulation, implementing

the aforementioned equations from section 2.1. Some important functions are FimbrialLocations() which reads in the Fim Mesh files to construct the fimbrial surface, Globals() and setVariables() to read in the global parameters and set the variables, and Coil() to set the coiling parameters and adjust each time step with the added effect of coiling. The code details can be found within the appendix.

Page 15: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS2.2.5 Outputs & MATLAB

The simulation generates total of six output files, called trajectory, state change, coil, lifetime and forvmd respectively. MATLAB scripts are used to generate analysis and figures of the data, such as the trajectory plot of force versus position as well as the bond counts versus time. The forvmd file is used exclusively with the molecular visualization program VMD for more interactive and visualization purposes.

2.2.6 VMD Visualization of the AFM experimentA Python script is used to convert the forvmd output file into a large series of PDB files

for the molecular visualization program VMD. The PDB files are loaded into VMD and linked together into a movie, which can be played at various speeds. Bond formation and breakage can be observed through the color changes of the interacting molecules.

2.2.7 AFM pull experiments: trajectory analysisThe results from an AFM pulling experiment can be interpreted graphically by plotting

the tension force of the interaction as either a function of position or time. Two metrics, the max

Figure 5: VMD Visualization of a typical AFM experiment pull. The blue bead signifies a mannose bead while the white strands represent randomly stacked fimbriae created from the Fim_Fall MATLAB script.

Figure 6: Simulation of AFM cantilever being pulled in the y direction (after initial contact with fimbriated surface). The fimbriae are bound to mannose via FimH while the FimA uncoils, resulting in the elongation of the fimbrial structure

Page 16: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISrupture force and the work of adhesion, are used to evaluate overall adhesiveness of the interaction. Max rupture force gives the maximum magnitude of the force that the entire adhesion process withstood, while the work of adhesion gives a more holistic view of how many bonds are at work and for how long. Graphically, he max rupture force is simply the highest peak observed in the plot, while the work of adhesion is the area under the curve (with x-axis being position).

Figure 6: A typical AFM pull experiment trajectory plot, with force being either as a function of time or position of the cantilever.

Page 17: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

3. RESULTS & DISCUSSIONS

3.1 Research Data & Design ProcessThe most important process in designing the best parameter value sets for fimbrial

adhesion to consider the problem in the context of the following three questions:

1) What state transition rates results in the highest adhesive force? 2) What coiling parameters result in the highest adhesive force? 3) How does the pull speed affect the adhesion?

These three questions relate directly back to the two mechanisms that drive the adhesion behavior of fimbria: catch bonds and uncoiling. The on and off rates are crucial for catch-bond formation while the coiling/uncoiling “dissociation rates” ka,b and kb,a decide the degree of coiling that occurs in the process. Both processes are velocity and force dependent, therefore the interaction can also be interpreted in the context of energy barriers, as illustrated in figure 7.

The velocity at which the adhesive is pulled is the third factor that affects the uncoiling process immensely. Recall equation 8 from Forero et al relates the extension velocity to the force on a bond, and the entire expression is an evaluation of the relative contributions by the uncoiling components versus the coiling components. It has been found that fimbria uncoils at above 60 pN of force while the fimbria coils back when the force drops down to 25 pN at wild type k1,2 and k2,1 conditions5. Therefore it is appropriate to consider a pull speed that will result in the minimum of 60 pN needed to activate uncoiling.

In addition, aside from the intrinsic parameters, one should consider the physiological condition the simulation should focus on, and in the case of designing an adhesive through simulation AFM experiments, the pulling speed is crucial in determining the behavior of the adhesion process (See Figure 8). The sigmoidal shape of the data suggests that max rupture force is less dependent on pulling speed once the pull velocity reaches a threshold of about 100 microns/s, but the max rupture force is highly sensitive to velocity at much lower velocities,

Page 18: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISwhere the max rupture force rises rapidly with a small increase in pulling velocity. Similar trend is observed for the work of adhesion as velocity increases.

In designing an adhesive and picking parameter values conducive to creating maximum adhesive strength, it seems that the 100 microns/s range is ideal as the default pull speed to further optimize the parameters on. However, a particular roadblock to this approach is that AFM experiments in real life are not reliable beyond the 10 microns/s range as viscous forces of the experiment (as a result of the high pull velocity) overtakes the actual forces from bond formation and breakage, therefore creating too much noise in the force data gathered. Therefore, a choice was made to continue explore the adhesive properties at the speed of 10 microns/s, for at 10 microns/s the maximum rupture force and work of adhesion are still statistically insignificantly different from those at 100 microns, but it is within the threshold where simulation data could be realistically evaluated with real life AFM experiments.

For the transition state rates, only k1,2 and k2,1 are easily modified via mutants while the k1,0 and k2,0 mutant variants are not as easy to achieve, therefore it is prudent to start exploring the range of values for the state 1 and 2 transition rates first. As for the coiling parameters, Ka,b and Kb,a are of much importance as well, however the effective distances for both the transitional bond rates and the coiling rates are not variables suited for varying in a simulation as they are usually functions of the other variables and is determined by the force exerted.

Lastly, of the simulation parameters, none should be modified with the exception of the radius of the bead, but at the moment the simulation is limited by computational power and is prone to errors beyond a binding surface of greater than 16 microns. Therefore, most of the work done will be on the 1.5 μm range for the mannose bead.

Page 19: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

3.1.1 Figure 8: Effect of Pulling Speed on Maximum Rupture Force and Work of Adhesion. Using default k12 type I fimbria parameters

0.1 1 10 100 10000

2

4

6

8

10

12

0

5000

10000

15000

20000

25000

30000

adhesion behavior as a function of pull speed

Max Rupture Force

Work of Adhesion

microns/s

pN

Wor

k o

f Ad

hes

ion

Next, the adhesion properties are observed for varying the transition rate k1,2 at a pull speed of 10 microns/s. The wild type has a k1,2 value of 3*10-5, with a maximum rupture force of about ~2000 pN. The highest force however is reached at around 1.5*105 with a max rupture force of ~3300 pN. It makes sense that the max rupture force and work of adhesion maxes out at

k1,2 = 1010, as the exponent portion of the equation

TkFx

kkB

bijoijij exp

becomes constant (x1,2 is bound to 15*10-10). Similarly, in the case of k2,1, because x2,1 is a negative number, no matter how high the force gets the exponent portion of the rate equation will go toward a limit of exp(-1) which is fixed around 0, which explains why changing the k2,1 has little effect on the max rupture force.

Page 20: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

3.1.2 Figure 9: Effect of varying k1,2 on-rate and k2,1 off-rate

10000 10000000 1000000000010000000000000 1E+0162.60E+03

2.70E+03

2.80E+03

2.90E+03

3.00E+03

3.10E+03

3.20E+03

3.30E+03

3.40E+03

3.50E+03

2.60E+04

2.70E+04

2.80E+04

2.90E+04

3.00E+04

3.10E+04

3.20E+04

3.30E+04

3.40E+04

Varying k1,2: max rupture force and work of adhesion.

n = 10 for each point

Max Rupture Force

Work of Ad-hesion

Microns/s

pN

WO

A

3.91E-11 7.81E-10 1.56E-08 3.13E-07 6.25E-06 1.25E-04 2.50E-03 5.00E-02 1.00E+000.00E+00

5.00E+02

1.00E+03

1.50E+03

2.00E+03

2.50E+03

3.00E+03

Max Rupture Force, k1,2=3e-5, varying k2,1

Page 21: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

1.00E-200 1.00E-150 1.00E-100 1.00E-50 1.00E+002.80E+03

2.90E+03

3.00E+03

3.10E+03

3.20E+03

3.30E+03

3.40E+03

3.50E+03

Max Rupture Force: k1,2 = 3e5, varying k2,1

k2,1

pN

Similarly, the effects of altering ka,b, the coiling on-rate, is explored. The resulting data has extreme peaks in maximum rupture force and work of adhesion near the wild type default values, which strongly suggests that uncoiling behavior of E. coli has been strongly selected by evolution and optimized naturally to have the maximum adhesive strength (See Figure 10). However, no such salient peaks were observed for varying kb,a as the max rupture force and work of adhesion remained steady at wild type values regardless of the change in kb,a (see red, Figure 11).

Page 22: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS3.1.3. Figure 10: Effects of Varying Coiling Parameter Ka,b

3.70E-11

1.11E-07

3.33E-04

1.00E+00

3.00E+03

9.00E+06

2.70E+10

8.10E+130

500

1000

1500

2000

2500

Max Rupture Force as a Function of Ka,b

ka,b

pN

3.33E-04 1.00E+00 3.00E+030.00E+00

2.00E+03

4.00E+03

6.00E+03

8.00E+03

1.00E+04

1.20E+04

1.40E+04

1.60E+04

1.80E+04

2.00E+04

Work of Adhesion as a Function of Ka,b (subset of interest)

Page 23: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

3.1.4 Figure 11: Effects of Varying Coiling Parameter kb,a

1.00E+00 1.00E+200

500

1000

1500

2000

2500

Max Rupture Force vs Kb,a (k1,2=3e-5)

pN

1.00E-100 1.00E-80 1.00E-60 1.00E-40 1.00E-20 1.00E+00 1.00E+20 1.00E+40 1.00E+600.00E+00

5.00E+03

1.00E+04

1.50E+04

2.00E+04

2.50E+04

WOA vs Kb,a (k1,2=3e-5)

Finally, drawing conclusion from the adhesive behavior according to aforementioned parameters, a stronger E. coli adhesive could be obtained by pulling at around 10 microns per second from a fimbriated surface of density 240 FimH/square microns, and changing the k1,2

transition rate from weak to strong binding from 3*10-5 to 3*105, while maintain all other parameters to their default wild type values (k2,1 = 0.11, ka,b = 0.688, kb,a = 4.3*106), in particular the coiling parameters as they are already optimized, the resulting comparison of adhesion improvement can be seen in Figure 3.1.5. The mean maximum rupture force for the design was 3390 pN +/- standard deviation of 246.3 (n=10), above the mean maximum rupture force for the wild type (n=10) of 1989 pN +/- standard deviation of 425.52 pN. Similar differences can be observed for work of adhesion as well.

Page 24: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS3.1.5: Final Design & Improvements in Adhesiveness

0.1 1 10 1000

50010001500200025003000350040004500

MRF: design vs wild type

design MRFwild type MRF

pull speed

MR

F (P

N)

1 100.00E+00

2.00E+00

4.00E+00

6.00E+00

8.00E+00

1.00E+01

1.20E+01

WOA: design vs wild type

designwild type

pull speed

Wor

of a

dh

esio

n

Figure 12: Comparison of Design parameters and wild type parameters over different pull speeds

3.1.6 Statistical AnalysisThe error bars for standard deviation do not overlap, which indicates that the difference in mean between the two groups is possibly significant. Therefore we proceed to a t-test for each of the pull speeds. Null hypothesis: no difference between design and wild type in adhesive strength*α=0.5 *unpaired t-testn= 15

Speed (microns/s)

0.1 0.5 2.5 10 100

P values <0.0001significant

< 0.0001significant

<0.0001significant

< 0.0001significant

< 0.0001significant

Page 25: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISThe design choice of increasing the k1,2 parameter and maintaining the wild type value for the uncoiling parameters increased the max rupture force and work of adhesion across a large range of pull speeds.

We follow up the statistical analysis by examining the number of bonds forming at any given time as well as the uncoiling forces with the variations in ka,b values.

Figure 13: Bond Activation Diagrams for the improved parameters versus wild type at three pull speeds: medium (2.5 microns/s), fast (10 microns/s) and extremely fast (100 microns/s). All activities before 1 seconds represent the cantilever moving towards the

Page 26: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISfimbrial surface, blue line indicates the formation and breakage of state 1 (low affinity) bonds, red line indicates the formation and breakage of state 2 (high affinity) bonds. Green is the total number of bonds showing binding activity (purely as reference, as blue and red totals should always add up to the green value at any time point).

Several conclusions can be implicated from the bond state diagrams in Figure 12. First, is that the design model has a higher number of state 2 bonds than the wild type counterpart of the same speed group. This is consistent given the boost from the increased transition rate from state 1 to 2, making the catch bond formation happen more frequently. In addition, it is curious to see that state 2 bonds start forming much earlier for the design parameters( even while the cantilever is still approaching surface), while the wild type generally must all transition into state 1 bonds first before transitioning into state 2 bonds, as seen by the fact that almost no state 2 bonds ever form until after the 1 second point where the cantilever starts to move away from the fimbrial surface.

Using Equation #8, the calculated uncoiling forces for the three speeds are 82 pN, 94 pN and 115 pN respectively. As all three of these force values are greater than 60 pN, we can assume that uncoiling dominates coiling in these experiments and that uncoiling occurs at these pull speeds. In addition, it is also worth noting that the calculated theoretical uncoiling force for wild type fimbria is 91 pN, very close to the 85 ± 4 pN uncoiling force observed previously in the Thomas lab4. However, when the coiling parameters are changed so that it is about ten magnitudes higher than its wild type value, the coiling force dropped to near zero and the ultimate result was that state 2 bond formation was severely hindered (Figure 14, 15a). In turn, the lack of state 2 bonds meant the maximum rupture force was capped rather short as well as seen from the blue line in the trajectory plot in Figure 14b. On the other hand, lowering the uncoiling parameter well below the wild type value results in extremely high uncoiling forces that would certainly break the catch bonds prematurely, as a single catch bond can only withstand about 130 pN of force before breaking 4 (Figure 14). This is indeed the case as seen in the trajectory plot where the green line spikes but falls in a very swift pattern (Figure 15b). The logarithmic nature of the uncoiling force in relation to the uncoiling parameter reaffirms the notion that the uncoiling is highly sensitive to change, and even a magnitude of change results in an uncoiling force that either breaks the catch bond prematurely or does not activate catch bonds at all. Perhaps the sensitivity is due to the process of evolution finely selecting for an uncoiling behavior that best complements catch bond formation.

Page 27: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

1.00E-12 1.00E-09 1.00E-06 1.00E-03 1.00E+00 1.00E+03 1.00E+06 1.00E+090

50

100

150

200

250

300

350

011.3

91

194

296

Uncoiling Force vs. Ka,b

Ka,b values

Un

coil

ing

Forc

e (p

N)

Figure 14: Uncoiling force drops with increase in ka,b (note the logarithmic scale), pull speed = 10 microns/s. Red data dot signifies uncoiling force for wild type k a,b value of 0.0688.

Figure 15 a) the lack of state 2 bond formation due to the increased ka,b value (which resulted in an extremely low uncoiling force calculated with equation 8 mentioned previously). The formation of catch bonds occur in the reverse case when ka,b is low and uncoiling force is high, but the catch bonds all tend to break prematurely which also hindered adhesiveness

Page 28: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

Figure 15 b) corresponding results in maximum rupture force plots. Low uncoiling parameter leads to high uncoiling force and therefore immediate bond ruptures (green) whereas high uncoiling parameter leads to low uncoiling force that meant low catch bond bond formation. *Red line is wild type reference

CONCLUSION & FUTURE DIRECTIONSWith the current design modifications, the adhesion capacity of the E. coli has been

increased by about 1400 pN (~75%) by increasing k1,2 to 3*105 and maintaining the coiling parameter ka,b at the wild type value, as data suggests that evolution has already optimized coiling to achieve the maximum adhesive strength. Although varying the off-rates k2,1 and kb,a had little effects on increasing the maximum adhesive force, there are still many areas to be explored for potential to increase the adhesive strength.

For example, the behavior of the other coiling parameter, kb,c and kc,b (for the worm-like chain segments of FimA) has not been explored in depth. It is worth exploring all of the aforementioned parameters and velocity at different bead radiuses, as scaling of the adhesive force still remains an obstacle to creating a wet reversible adhesive at the micro-scale. Lastly, all of the simulation experiments were performed on a single variation of the fimbrial mesh file, while it makes sense to perform all experiments in a pair-wise manner on different fimbriated surfaces to observe the effect of the random variations of fimbriae surface on the adhesive behavior.

Page 29: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISKEY PERSONNEL & RESOURCES

Key PersonnelThis project would not be possible without the generous mentoring of Professor Wendy Thomas, graduate student Matt Whitfield, and my immediate graduate student mentor, Keith Johnson. Assistance from Gianluca Interlandi in the technical use of all the lab resources is also crucial to the completion of this capstone thesis. During the duration of the project, help and morale support is also greatly appreciated from fellow teammate on the bio-adhesive project, junior Nichole Tyler.

ResourcesThis project is supported by a NSF Career Award funding. The workspace where this project takes place is within the Bioengineering department at the University of Washington, with the utilization of on-site computers and servers as well as personal laptops. The project is able to proceed with the availability of publications for reference as well as software such as MATLAB and C++ and a laboratory capable of performing AFM experiments, parallel-plate flow chamber experiments and E. Coli culturing. The simulation aspects of this project do not involve any contact with bio-hazardous materials, but the real life implementation of the design involves contact with biological material and requires short courses on dealing with blood-borne pathogens.

Page 30: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

Works Citedx

[1] Kellar Autumn, Yiching A. Liang, Tonia Hsieh, and Robert J Full, "Adhesive force of a single gecko foot-hair," Nature, vol. 405, pp. 681-685, June 2000.

[2] C. Menon, M. Murphy, and M. Sitti, "Waalbot: An Agile Small-Scale Wall Climbing Robot Utilizing Dry Elastomer Adhesives," IEEE/ASME Transactions on Mechatronics, vol. 12, no. 3, June 2007.

[3] Wendy Thomas et al., "Catch-Bond Model Derived From Allostery Explains Force Activated Bacterial Adhesion," Biophysical Journal, vol. 90, no. 3, pp. 753-764, February 2006.

[4] Matthew Whitfield and Wendy Thomas, "A Nanoadhesive Composed Of Receptor-Ligand Bonds," The Journal of Adhesion, vol. 87, no. 5, May 2011.

[5] Manu Forero, Olga Yakovenko, Evgeni Sokurenko, Wendy Thomas, and Viola Vogel, "Uncoiling Mechanics of Escherichia coli Type I Fimbriae Are Optimized For Catch Bonds," vol. 4, no. 9, September 2006.

[6] Haeshin Lee, Norbert Scherer, and Phillip Messersmith, "Single-molecule mechanics of mussel adhesion," Proc Natl Acad Sci, vol. 103, no. 35, pp. 12999-13003, August 2006.

[7] G Murat, D Brass, Messersmith, and K Shull, "Adhesion of DOPA-Functionalized Model Membranes to Hard and Soft Surfaces," The Journal of Adhesion, vol. 85, no. 9, pp. 631-645, 2009.

[8] Haeshin Lee, Bruce Lee, and P. Messensmith, "A Reversible Wet/dry Adhesive Inspired By Mussels and Geckos," Nature, vol. 448, pp. 328-341.

[9] Tia Ghose, Wendy Thomas, and Matthew Whitfield, "Shear-stabilized rolling behavior of E. coli examined with simulations," Biophysical Journal, vol. 99, pp. 2470-2478, 2010.

[10] O Bjornham and O Axner, "Multipili attachment of bacteria with helixlike pili exposed to stress," Journal of Chemical Physics, vol. 130, no. 23, 2009.

[11] D Hammer and S Apte, "Simulations of cell rolling and adhesion on surfaces in shear flow: general results and analysis of selectin-mediated neutrophil adhesion ," Biophysical Journal, vol. 63, 1992.

[12] NSF. National Science Foundation. [Online]. NSF.gov

[13] Noel M Lee and Glenn M Eisen, "10 Years of Capsule Endoscopy: An Update," Expert Rev Gastroenterol Hepatol, vol. 4, no. 4, pp. 503-512, 2010.

Page 31: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS[14] C Hassan, A. Zullo, S. Winn, and S. Morini, "Cost-Effectiveness of Capsule Endoscopy in

Screening for Colorectal Cancer," Endoscopy, vol. 40, pp. 414-421, January 2008.

x

Page 32: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISAPPENDIX

Code Used: version AllSims_N.cpp#include "commonEcoli3D.h"#include <time.h>#include <math.h>#include <string>#include <iostream>#include <iomanip>#include <complex>#include <cmath>#include <unistd.h>using namespace std;

#ifdef _MSC_VER#include "gsl/gsl_sf_erf.h"#endif

//This program was changed heavily during December 2011 to improve the AFM type cimulations KCJ 12/2011//This program can now only be used for AFM simulations. For FLOW simulations, use allsims_v1 KCJ 1/2012

double randomn() {/* The random function generates a random number between 0 and 1. The distribution is UNIFORM.The resolution for the random function is 1/RAND_MAX most of the time; if the generator comes up with either 0 or 1 as the random number, then the functionis implemented recursively to get very small random numbers, it is implemented recursively. */double randomTemp= 0;randomTemp = (double) rand()/RAND_MAX;if (randomTemp == 0) {

randomTemp = randomn()/RAND_MAX;}if (randomTemp == 1) {

randomTemp = 1 - randomn()/RAND_MAX;}return randomTemp;

}

double simpleRand() {double randTemp = (double) rand()/RAND_MAX;return randTemp;

}

double ExponentialRandom(double lambda) {double randpick = randomn();double Exponential = -log(randpick)/lambda;return Exponential;

}

#ifdef _MSC_VERdouble erfc(double Z) {

return gsl_sf_erfc(Z);}#endif

/* Declares all variables that are globally accessible within all functions*/

// OUTPUT FILE HANDLESFILE *fid1;FILE *fid2; FILE *fid4;FILE *fid7;FILE *fid9;FILE *fid39;FILE *fid40;FILE *fid5;string filename1;string filename4;string filename5;string filename7;string filename9;string filename39;string filename40;string filename2;string x_start_name;string y_start_name;string z_start_name;string x_end_name;string y_end_name;string z_end_name;

//////////////////////////////////////////////// Parameters read in from input file /////////////////////////////////////////////////string TYPE;double TMAX; int fast;

Page 33: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISdouble TIMESTEP; long long PRINTSPERSECOND;int numfim;double fluid_shear;double cell_density; double cell_radius;double cellE;double viscosity;double equilib_fim_length; double fim_stiffness;double fimbrialE;double kbT;double K01;double K02;double K10;double K12;double K20;double K21;double deltaL10;double deltaL12;double deltaL20;double deltaL21;int naming;double torsional_stiffness;int usecoil;double ku;double kc;int maxstate2;double holdforce;int interp;double Retract;

//////////////////////////////////////////////// GENERIC VARIABLES /////////////////////////////////////////////////double time1 = 0;double t = 0;int recordyn=0;int print=1;int stopped=0;int bentsum=0;double bucklesum=0;double contactsum=0;double scn;double mominertia;double Inertia;double eff_drag_radius;double closestTip;double Km;double fluid_velocity; double xrmsbound;double dCrit;long long PRINTFACTOR; double cell_mass;double drag_coeff;double length;std::valarray<double> Fbuckling;std::valarray<double> fim_length;std::valarray<double> equilib_fimL;std::valarray<int> buckle;std::valarray<double> k;std::valarray<int> bent;std::valarray<double> bound_factor;

//////////////////////////////////////////////// BOND TRANSITION VARIABLES /////////////////////////////////////////////////double timeToTransition=0;double nextTransitionTime=0;double stateSum=0;double state2Sum=0;double sqrt2=sqrt(2.0);int nextState=0;int transitionIndex=1;std::valarray<double> bondrate;std::valarray<double> bondrate01;std::valarray<double> bondrate02;std::valarray<double> bondrate12;std::valarray<double> bondrate21;std::valarray<double> bondrate20;std::valarray<double> bondrate10;std::valarray<int> state;std::valarray<int> prev_state;

//////////////////////////////////////////////// FORCE CALCULATION VARIABLES /////////////////////////////////////////////////double axial_torqueM, side3, att,atf,rotateforceM;double force;

Page 34: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISdouble thetazx;Point tottorque;Point atM;Point tensionSum;Point change_in_ten;std::valarray<double> totten;std::valarray<Point> tension;std::valarray<Point> torque;std::valarray<Point> rotateforce;std::valarray<double> anglediff;std::valarray<Point> tip;std::valarray<Point> normaltip;std::valarray<Point> attach;std::valarray<double> tether_anglet2;std::valarray<double> tether_anglef2;std::valarray<Point> current_attach_angle;

//////////////////////////////////////////////// ERMAK & ROTATION VARIABLES /////////////////////////////////////////////////double position_gap=0;int posjump;double Tys,ah;Point accel, vel, velo;Point aaccel, avel, avelo;Point center, ocenter;Point change_in_pos;Point position;double c0,c1,c2,beta;double c0r,c1r,c2r,betar;

//////////////////////////////////////////////// COILING PARAMETERS /////////////////////////////////////////////////double dxc=-1.9e-9;double dxu=4.61e-10;double kbc=2.63e5;double kcb=2.19e5;double dxbc=6.4e-10;double dxcb=3e-10;double xLc=.7e-9;double xLu=8.2e-9;double xL2=6.1e-9;double xL3=8.2e-9; double Lp2=3.35e-9;double Lp3=.516e-9;

//////////////////////////////////////////////// COILING VARIABLES /////////////////////////////////////////////////double Ku,Kc,Kx,Ky,Nc,Nu,N2,N3;double a,a2,a3,b,b2,b3,e,e2,e3,d,d2,d3,Km2,Km3,xLc2,xLc3;double EQLc,EQLu;double C1,Lp;long double Lc;double force2;double sq3=sqrt(3.0);double statep;complex <double> halfpw=.5;complex <double> thirdpw=1.0/3;complex <double> L1;complex <double> L2;complex <double> Lcc;std::valarray<double> ratio;std::valarray<double> NUMc;std::valarray<double> NUMu;std::valarray<double> NUM2;std::valarray<double> NUM3;std::valarray<double> NUM2p;std::valarray<double> NUM3p;std::valarray<int> subunits;std::valarray<int> coiled;

//////////////////////////////////////////////// AFM VARIABLES /////////////////////////////////////////////////double xposition=0, yposition=0, zposition=0;double xsurface,ysurface, zsurface;double stopit=0;std::valarray<double> xmin;std::valarray<double> ymin;std::valarray<double> zmin;std::valarray<double> Dmin;std::valarray<double> u_vect_x;std::valarray<double> u_vect_y;std::valarray<double> u_vect_z;std::valarray<double> part_xmin;std::valarray<double> part_ymin;std::valarray<double> part_zmin;std::valarray<double> new_xmin;

Page 35: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESISstd::valarray<double> new_ymin;std::valarray<double> new_zmin;std::valarray<double> current_length;std::valarray<double> c_univect_x;std::valarray<double> c_univect_y;std::valarray<double> c_univect_z;std::valarray<double> new_tipx;std::valarray<double> new_tipy;std::valarray<double> new_tipz;std::valarray<double> tip_angle;std::valarray<double> Dmin_angle;std::valarray<Point> uni_fully;std::valarray<Point> tip_full;std::valarray<Point> uni_tips;std::valarray<double> normal_full;std::valarray<double> length_min;std::valarray<Point> dummy_tip;std::valarray<Point> uni_force;std::valarray<Point> uni_dummy_full;std::valarray<Point> dummy_tip_full;double orig_center;double floor_k;double xmin_g;double tip_diff;double attach_diff;double testing;double tottensum;double rotatesum;int increment;int partial=0;std::valarray<double> xdw(numfim);std::valarray<double> ydw(numfim);std::valarray<double> zdw(numfim);std::valarray<double> fxs(numfim);std::valarray<double> fys(numfim);std::valarray<double> fzs(numfim);std::valarray<double> fxe(numfim);std::valarray<double> fye(numfim);std::valarray<double> fze(numfim);ifstream::pos_type size;char * memblock;

void globals() {/* The globals function reads in the parameters that are input in a separate file. This allows for changing input parameters without directly changing the code. See globals.h for a full description*/

cin>>TYPE; // AFM or FLOWcin>>TMAX; // Runtime of the simulation, (s)cin>>fast; // Flag that changes the amount of outputs of simulation 0=all outputs, 1=subset

of outputscin>>TIMESTEP; // Time step of the Simulation, (s)cin>>PRINTSPERSECOND; // How many times per sec outputs are written to output files cin>>numfim; // The total number of fimbriaecin>>fluid_shear; // The fluid shear rate, (1/s)cin>>cell_density; // Density of cell, (kg/m^3)cin>>cell_radius; // Radius of cell, (m)cin>>cellE; // Young's Modulus of cell, (Pa)cin>>viscosity; // Viscosity of fluid, (Pa*s)cin>>equilib_fim_length; // Mean fimbrial length, (m) was 0.572e-6 mcin>>fim_stiffness; // Effective stiffness of fimbriae and linkage to cell, (N/m) 2.06 pN/nm according to Matts

dissertationcin>>fimbrialE; // Young's Modulus of fimbriae, (Pa)cin>>kbT; // Thermal Energy: Boltzmann's constant x Temperature, (J)cin>>K01; // State 1 on-rate, (1/s) KB91: 3cin>>K10; // State 1 off-rate, (1/s) KB91: 6cin>>K12; // Transition rate from state 1 to 2, (1/s) KB91: .00125cin>>K20; // State 2 off-rate, (1/s) KB91: 5e-6cin>>K21; // Transition rate from state 2 to 1, (1/s) KB91: .025cin>>deltaL10; // Transition distance for state 1 unbinding, (m) KB91: 4.52e-10cin>>deltaL12; // Transition distance for state 1-2 transition, (m) KB91: 12e-10cin>>deltaL20; // Transition distance for state 2 unbinding, (m) KB91: 4.52e-10cin>>deltaL21; // Transition distance for state 2-1 transition, (m) KB91: -12e-10 cin>>naming; // What number to start appending to file namecin>>torsional_stiffness; // Allows scaling of torsional stiffness from assumed valuecin>>usecoil; // Flag for allowing uncoiling (1 yes, 0 no)

cin>>ku; //kb,a (uncoiling) cin>>kc; //ka,b (uncoiling)

cin>>maxstate2; // Sets the maximum number of bonds that are allowed to form in state 2if (TYPE.compare("AFM")==0) {

cin>>Retract; //was the velocity of retraction, now defined by driver wave. cin>>interp; // if (1/Timestep) = pps (from driver file), then interp = 1.cin>>holdforce;

}} //End globals

void setvariables() {

// Sets the initial values of all of the variables that could not be set before input variables collected

Page 36: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

// Inital Calculations

PRINTFACTOR = (long long) (1/(PRINTSPERSECOND *TIMESTEP)); // Calculates how many iterations between outputs

K02 = K12*K20/(K21*K10 + K12*K20)*K01; // State 2 on-rate (essentially 0)

cell_mass = PI * 4/3 * pow(cell_radius,3) * cell_density; // Mass of cell based on radius and density and neglecting fimbraie

Inertia = PI/4*(pow(3.45e-9,4)-pow(1.25e-9,4))*torsional_stiffness; // Howard book equation hahn paper for the inner and outer diameterseff_drag_radius=cell_radius+equilib_fim_length; // Effective drag radius taking

average fimbrial length into accountmominertia=0.4*cell_mass*eff_drag_radius*eff_drag_radius; // moment of inertia for rotation of celldrag_coeff = PI*6 * viscosity * eff_drag_radius; // Drag coefficient of cellscn = fimbrialE*Inertia*3;// Bending stiffness spring constant numerator from Howard bookbeta = drag_coeff/cell_mass;// Ermak equations - translation component betar = PI*8*viscosity*pow(cell_radius,3)/mominertia; // Ermak equations - rotational componentxrmsbound = sqrt(kbT/fim_stiffness); // Describes expected

deviation of axial distance the tip of the fimbriae given its stiffnessdCrit = xrmsbound*5;

// Defines a cutoff where fimbrial tip is considered to far from surface to bind that time stepKm=fim_stiffness;

Km2=Km*Km;Km3=Km*Km*Km;xLc2=xLc*xLc;xLc3=xLc*xLc*xLc;

// Sets the size of the valarrays based on the number of fimbriaefim_length.resize(numfim);tip.resize(numfim);normaltip.resize(numfim);attach.resize(numfim);tether_anglet2.resize(numfim);tether_anglef2.resize(numfim);state.resize(numfim);prev_state.resize(numfim);current_attach_angle.resize(numfim);tension.resize(numfim);bondrate.resize(2*numfim);equilib_fimL.resize(numfim);Fbuckling.resize(numfim);totten.resize(numfim);buckle.resize(numfim);k.resize(numfim);torque.resize(numfim);rotateforce.resize(numfim);anglediff.resize(numfim);bondrate01.resize(numfim);bondrate02.resize(numfim);bondrate12.resize(numfim);bondrate21.resize(numfim);bondrate10.resize(numfim);bondrate20.resize(numfim);bent.resize(numfim);bound_factor.resize(numfim);NUMc.resize(numfim);NUMu.resize(numfim);NUM2.resize(numfim);NUM3.resize(numfim);NUM2p.resize(numfim);NUM3p.resize(numfim);ratio.resize(numfim);subunits.resize(numfim);coiled.resize(numfim);xmin.resize(numfim);ymin.resize(numfim);zmin.resize(numfim);Dmin.resize(numfim);u_vect_x.resize(numfim);u_vect_y.resize(numfim);u_vect_z.resize(numfim);part_xmin.resize(numfim);part_ymin.resize(numfim);part_zmin.resize(numfim);new_xmin.resize(numfim);new_ymin.resize(numfim);new_zmin.resize(numfim);c_univect_x.resize(numfim);c_univect_y.resize(numfim);c_univect_z.resize(numfim);current_length.resize(numfim);new_tipx.resize(numfim);new_tipy.resize(numfim);new_tipz.resize(numfim);uni_fully.resize(numfim);tip_full.resize(numfim);uni_tips.resize(numfim);

Page 37: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

dummy_tip.resize(numfim);uni_force.resize(numfim);uni_dummy_full.resize(numfim);dummy_tip_full.resize(numfim);normal_full.resize(numfim);tip_angle.resize(numfim);Dmin_angle.resize(numfim);length_min.resize(numfim);

//shouldn't need now that fimbriae start and end points are imported. for (int n = 0; n < numfim; n++) {

//USED FOR TESTING//equilib_fimL[n] = sqrt((.5e-6)*(0.5e-6)+(2e-6)*(2e-6)+(1.2e-6)*(1.2e-6));

//Normal stuff to runequilib_fimL[n] = sqrt((fxe[n]-fxs[n])*(fxe[n]-fxs[n])+(fye[n]-fys[n])*(fye[n]-fys[n])+(fze[n]-fzs[n])*(fze[n]-fzs[n]));fim_length[n]=equilib_fimL[n];k[n]=0; // Torsional spring constant (Howard book spring constant = 3*E*I/L^3 * L^2)bound_factor[n]=(20.191-4.6516*exp(-.048714*k[n]/(kbT))-5.6621*exp(-.30302*k[n]/(kbT)));subunits[n]=int(equilib_fimL[n]/xLc); // Calculates the # of subunits to the nearest whole numberequilib_fimL[n]=subunits[n]*xLc; // Changes the fim length based on # of subunits NUMc[n]=subunits[n]; // Fimbriae start fully coiled

}

// Set the position of the centroid of the cellcenter.x = 0;center.y = 3.50e-6;center.z = 0;ocenter.x = center.x;ocenter.y = center.y;ocenter.z = center.z;

//Used when bead hits the surfaceorig_center = center.y;floor_k = .020; //20 pN/nm; roughly the typical spring constant of the cantilever

// Sets the starting values of variables stored for each fimbriaefor (int n = 0; n < numfim; n++) {

Fbuckling[n] = fimbrialE * Inertia/(equilib_fimL[n]*equilib_fimL[n])*torsional_stiffness;attach[n].x = fxs[n];attach[n].y = fys[n];attach[n].z = fzs[n];tip[n].x = fxe[n];tip[n].y = fye[n];tip[n].z = fze[n];

//use to set fimbria start and end points manually, USED FOR TESTING/*attach[n].x = -.5e-6;attach[n].y = 0;attach[n].z = -0.7e-6;tip[n].x = 0;tip[n].y = 2e-6;tip[n].z = .5e-6;normaltip[n].x = tip[n].x;normaltip[n].y = tip[n].y;normaltip[n].z = tip[n].z;*/

normaltip[n].x = fxe[n]; normaltip[n].y = fye[n]; normaltip[n].z = fze[n];tension[n].x = 0; tension[n].y = 0; tension[n].z = 0;anglediff[n]=0;rotateforce[n].x=0; rotateforce[n].y=0; rotateforce[n].z=0;

xmin[n]=1;ymin[n]=1;zmin[n]=1;new_xmin[n]=1;new_ymin[n]=1;new_zmin[n]=1;part_ymin[n]=1;part_zmin[n]=1;part_xmin[n]=1;u_vect_x[n]=1;u_vect_y[n]=1;u_vect_z[n]=1;c_univect_x[n]=1;c_univect_y[n]=1;c_univect_z[n]=1;current_length[n]=equilib_fimL[n];new_tipx[n]=1;new_tipy[n]=1;new_tipz[n]=1;current_attach_angle[n].z = asin(tip[n].y-attach[n].y/equilib_fimL[n]);

Page 38: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

current_attach_angle[n].y = atan2(tip[n].z-attach[n].z,tip[n].x-attach[n].x);state[n] = 0;prev_state[n] = 0;bondrate[n]= 0;totten[n]=0;buckle[n]=0;bent[n]=0;bondrate01[n]=0; bondrate02[n]=0;bondrate12[n]=0; bondrate21[n]=0;bondrate10[n]=0; bondrate20[n]=0;NUMu[n]=0;NUM2[n]=0; NUM3[n]=0;NUM2p[n]=0; NUM3p[n]=0;ratio[n]=1;coiled[n]=0;

}

tottorque.x=0; tottorque.y=0; tottorque.z=0;atM.x=0; atM.y=0; atM.z=0;

//Get the minimum distance to center of bead for each fimrbiae (Dmin) and x-location on fimrbiae where this minimum distance occurs (xmin)//for each fimrbia, determine the y and z point corresponding to xmin, the unit vector between the minimum point and the center of the bead,

and then if Dmin is less//than the cell radius, pivot the fimbriae until the fimbriae contacts the surface of the bead along the extension of the unitvector. //Update the tip of each fimbriae based upon unit vectors between the attachment points and new min points.

for (int n = 0; n < numfim; n++) {

//solve for x-location on fimbriae which will have minimum distance to center of cell. double xmin_g = (2*center.x + (2*(attach[n].y - tip[n].y)*(center.y - attach[n].y + (attach[n].x*(attach[n].y - tip[n].y))/(attach[n].x -

tip[n].x)))/(attach[n].x - tip[n].x) + (2*(attach[n].z - tip[n].z)*(center.z - attach[n].z + (attach[n].x*(attach[n].z - tip[n].z))/(attach[n].x - tip[n].x)))/(attach[n].x - tip[n].x))/((2*(attach[n].y - tip[n].y)*(attach[n].y - tip[n].y))/(attach[n].x - tip[n].x)*(attach[n].x - tip[n].x) + (2*(attach[n].z - tip[n].z)*(attach[n].z - tip[n].z))/(attach[n].x - tip[n].x)*(attach[n].x - tip[n].x) + 2);

//if xmin_g is somewhere along the length of the fimbriae then the minimum distance is calculated at xminif (xmin_g>attach[n].x) {

if (xmin_g<tip[n].x) {xmin[n]=xmin_g;

}

}else if (xmin_g<attach[n].x) {

if (xmin_g>tip[n].x) {xmin[n]=xmin_g;

}}

//if xmin_g is not along the fimbriae, it is calculated as either the tip or attachment point. if (xmin_g>attach[n].x) {

if (xmin_g>tip[n].x) {tip_diff = abs(tip[n].x-xmin_g);attach_diff = abs(attach[n].x-xmin_g);

if(tip_diff>attach_diff) {xmin[n]=attach[n].x;

}else {

xmin[n]=tip[n].x;}

}}

if (xmin_g<attach[n].x) {if (xmin_g<tip[n].x) {

tip_diff = abs(tip[n].x-xmin_g);attach_diff = abs(attach[n].x-xmin_g);

if(tip_diff>attach_diff) {xmin[n]=attach[n].x;

}else {

xmin[n]=tip[n].x;}

}}

//Calculate the y and z coordinates at the mininimum distance point, and then the minimum distanceymin[n]=((tip[n].y-attach[n].y)/(tip[n].x-attach[n].x))*(xmin[n]-attach[n].x)+attach[n].y;zmin[n]=((tip[n].z-attach[n].z)/(tip[n].x-attach[n].x))*(xmin[n]-attach[n].x)+attach[n].z;Dmin[n]=sqrt((xmin[n]-center.x)*(xmin[n]-center.x)+(ymin[n]-center.y)*(ymin[n]-center.y)+(zmin[n]-center.z)*(zmin[n]-center.z));;

//If the minimum distance point is within the bead, then take small steps outward until it is just touching the surfaceif (Dmin[n]<cell_radius-dCrit) {

while (abs(Dmin[n]-cell_radius)>dCrit) {

//find direction of steepest descent (in terms of distance)part_xmin[n]=-(2*center.x - 2*xmin[n])/(2*sqrt((center.x - xmin[n])*(center.x-xmin[n]) + (center.y - ymin[n])*(center.y

- ymin[n]) + (center.z - zmin[n])*(center.z - zmin[n])));

Page 39: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

part_ymin[n]=-(2*center.y - 2*ymin[n])/(2*sqrt((center.x - xmin[n])*(center.x-xmin[n]) + (center.y - ymin[n])*(center.y - ymin[n]) + (center.z - zmin[n])*(center.z - zmin[n])));

part_zmin[n]=-(2*center.z - 2*zmin[n])/(2*sqrt((center.x - xmin[n])*(center.x-xmin[n]) + (center.y - ymin[n])*(center.y - ymin[n]) + (center.z - zmin[n])*(center.z - zmin[n])));

//Take small step towards edge of beadnew_xmin[n]=xmin[n]-part_xmin[n]*(Dmin[n]-cell_radius)*0.1;new_ymin[n]=ymin[n]-part_ymin[n]*(Dmin[n]-cell_radius)*0.1;new_zmin[n]=zmin[n]-part_zmin[n]*(Dmin[n]-cell_radius)*0.1;

//Get unit vector between new point and attach pointu_vect_x[n]=(new_xmin[n]-attach[n].x)/sqrt((new_xmin[n]-attach[n].x)*(new_xmin[n]-attach[n].x)+(new_ymin[n]-

attach[n].y)*(new_ymin[n]-attach[n].y)+(new_zmin[n]-attach[n].z)*(new_zmin[n]-attach[n].z));u_vect_y[n]=(new_ymin[n]-attach[n].y)/sqrt((new_xmin[n]-attach[n].x)*(new_xmin[n]-attach[n].x)+(new_ymin[n]-

attach[n].y)*(new_ymin[n]-attach[n].y)+(new_zmin[n]-attach[n].z)*(new_zmin[n]-attach[n].z));u_vect_z[n]=(new_zmin[n]-attach[n].z)/sqrt((new_xmin[n]-attach[n].x)*(new_xmin[n]-attach[n].x)+(new_ymin[n]-

attach[n].y)*(new_ymin[n]-attach[n].y)+(new_zmin[n]-attach[n].z)*(new_zmin[n]-attach[n].z));

//Determine new tip point using unit vectortip[n].x=attach[n].x+u_vect_x[n]*equilib_fimL[n];tip[n].y=attach[n].y+u_vect_y[n]*equilib_fimL[n];tip[n].z=attach[n].z+u_vect_z[n]*equilib_fimL[n];

//solve for x-location on fimbriae which will have minimum distance to center of cell. double xmin_g = (2*center.x + (2*(attach[n].y - tip[n].y)*(center.y - attach[n].y + (attach[n].x*(attach[n].y -

tip[n].y))/(attach[n].x - tip[n].x)))/(attach[n].x - tip[n].x) + (2*(attach[n].z - tip[n].z)*(center.z - attach[n].z + (attach[n].x*(attach[n].z - tip[n].z))/(attach[n].x - tip[n].x)))/(attach[n].x - tip[n].x))/((2*(attach[n].y - tip[n].y)*(attach[n].y - tip[n].y))/((attach[n].x - tip[n].x)*(attach[n].x - tip[n].x)) + (2*(attach[n].z - tip[n].z)*(attach[n].z - tip[n].z))/((attach[n].x - tip[n].x)*(attach[n].x - tip[n].x)) + 2);

//if xmin_g is somewhere along the length of the fimbriae then the minimum distance is calculated at xminif (xmin_g>attach[n].x) {

if (xmin_g<tip[n].x) {xmin[n]=xmin_g;

}

}else if (xmin_g<attach[n].x) {

if (xmin_g>tip[n].x) {xmin[n]=xmin_g;

}}

//if xmin_g is not along the fimbriae, it is calculated as either the tip or attachment point. if (xmin_g>attach[n].x) {

if (xmin_g>tip[n].x) {tip_diff = abs(tip[n].x-xmin_g);attach_diff = abs(attach[n].x-xmin_g);

if(tip_diff>attach_diff) {xmin[n]=attach[n].x;

}else {

xmin[n]=tip[n].x;}

}}

if (xmin_g<attach[n].x) {if (xmin_g<tip[n].x) {

tip_diff = abs(tip[n].x-xmin_g);attach_diff = abs(attach[n].x-xmin_g);

if(tip_diff>attach_diff) {xmin[n]=attach[n].x;

}else {

xmin[n]=tip[n].x;}

}}

//Calculate the y and z coordinates at the mininimum distance point, and then the minimum distanceymin[n]=((tip[n].y-attach[n].y)/(tip[n].x-attach[n].x))*(xmin[n]-attach[n].x)+attach[n].y;zmin[n]=((tip[n].z-attach[n].z)/(tip[n].x-attach[n].x))*(xmin[n]-attach[n].x)+attach[n].z;Dmin[n]=sqrt((xmin[n]-center.x)*(xmin[n]-center.x)+(ymin[n]-center.y)*(ymin[n]-center.y)+(zmin[n]-

center.z)*(zmin[n]-center.z));

}//end while loop}//end if statement

}//end for loop

}// End setvariables

void catchbond(int &state, int current_fim) {

Page 40: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

/*The catchbond function takes in the tension and current bond state of a fimbriae and uses the two-statecatch bond model to update the bond state*/double ratesum = 0;double force = totten[current_fim] ;if (force>=0) { force = 0; } //Here we assume that a compressive force on the fimbriae is equivalent to 0 force on the bondelse { force = abs(force); } //Tensile force is negative here, but needs to be postive for equations

if (state ==1) {bondrate10[current_fim] = K10*exp(force*deltaL10/kbT);bondrate12[current_fim] = K12*exp(force*deltaL12/kbT);ratesum = bondrate10[current_fim] + bondrate12[current_fim];double Pbond = 1 - exp(-ratesum*TIMESTEP);double randpick1 = randomn();if (randpick1 < Pbond) {

// if randpick less than Pbond, system leaves the current statedouble randpick02 = randomn();if (randpick02 < bondrate10[current_fim]/ratesum) {

state = 0;prev_state[current_fim] = 1;stateSum--;//the variable state returns 0 if the bacteria is unbound, returns 1 if//the bacteria is weakly bound and returns 2 if// E.coli is strongly bound,

}else {

state = 2;state2Sum++;prev_state[current_fim] = 1;

}nextTransitionTime=time1;fprintf(fid1, "%d\t%d\t%d\t%2.8f\t%10.10f\t%10.10f\t%10.10f\t%2.6f\t \r\n",current_fim, prev_state[current_fim],state, time1,

totten[current_fim]*1e12,fim_length[current_fim]*1e6,equilib_fimL[current_fim]*1e6,NUMu[current_fim]/(NUMc[current_fim]+NUMu[current_fim]));}else {

state = 1;}

}else if (state == 2) {

bondrate20[current_fim] = K20*exp(force*deltaL20/kbT);bondrate21[current_fim] = K21*exp(force*deltaL21/kbT);double ratesum = bondrate20[current_fim] + bondrate21[current_fim];double Pbond = 1 - exp(-ratesum*TIMESTEP);double randpick2 = randomn();if (randpick2 < Pbond) {

double randpick10 = randomn();if (randpick10 < bondrate20[current_fim]/ratesum) {

state =0;prev_state[current_fim] = 2;stateSum--;

}else {

state = 1;prev_state[current_fim] = 2;

}state2Sum--;nextTransitionTime=time1;fprintf(fid1, "%d\t%d\t%d\t%2.8f\t%10.10f\t%10.10f\t%10.10f\t%2.6f\t \r\n",current_fim, prev_state[current_fim],state, time1,

totten[current_fim]*1e12,fim_length[current_fim]*1e6,equilib_fimL[current_fim]*1e6,NUMu[current_fim]/(NUMc[current_fim]+NUMu[current_fim]));}else {

state = 2;}

}else if (state == 0) {

bondrate01[current_fim] = 0;bondrate02[current_fim] = 0;

//because only half the fimbriae (or so) will have the fimh at the "tip", only allow half of the "tips" to binddouble even = 2;double checkeven = fmod(current_fim,even);

if (checkeven>0.5) {if (xmin[current_fim]==tip[current_fim].x){

if (abs(Dmin[current_fim]-cell_radius < dCrit)) {double Zvalue = (Dmin[current_fim]-cell_radius)/xrmsbound;bondrate01[current_fim] = K01*(erfc(Zvalue/sqrt2));bondrate02[current_fim] = K02*(erfc(Zvalue/sqrt2));

}}}ratesum = bondrate01[current_fim] + bondrate02[current_fim];double Pbond = 1 - exp(-ratesum*TIMESTEP);double randpick0 = randomn();if (randpick0 < Pbond) {

double randpick12 = randomn();if (randpick12 < bondrate01[current_fim]/ratesum) {

state = 1;prev_state[current_fim] = 0;

}else {

state = 2;

Page 41: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

prev_state[current_fim] = 0;state2Sum++;

}nextTransitionTime=time1;fprintf(fid1, "%d\t%d\t%d\t%2.8f\t%10.10f\t%10.10f\t%10.10f\t%2.6f\t \r\n",current_fim, prev_state[current_fim],state, time1,

totten[current_fim]*1e12,fim_length[current_fim]*1e6,equilib_fimL[current_fim]*1e6,NUMu[current_fim]/(NUMc[current_fim]+NUMu[current_fim]));stateSum++;

}else {

state = 0;}

}bondrate01[current_fim]=0;bondrate02[current_fim]=0;bondrate12[current_fim]=0;bondrate21[current_fim]=0;bondrate10[current_fim]=0;bondrate20[current_fim]=0;

} // End catchbond

void coil(int n) {// Used to calculate percentage of fimbriae coiled and force on fimbriaetotten[n]=-totten[n];Ku=ku*exp(totten[n]*dxu/kbT);Kc=kc*exp(totten[n]*dxc/kbT);Ky=kbc*exp(totten[n]*dxbc/kbT);Kx=kcb*exp(-totten[n]*dxcb/kbT);

//jj=dsolve('DN1=KC-KU', 'DN2=-KC+KU','N1(0)=NUMc[n]','N2(0)=NUMu[n]')Nc=TIMESTEP*Kc-TIMESTEP*Ku+NUMc[n];Nu=-TIMESTEP*Kc+TIMESTEP*Ku+NUMu[n];

if (Nc>subunits[n]) { Nc=subunits[n];}else if (Nc<0) { Nc=0;}if (Nu>subunits[n]) { Nu=subunits[n]; }else if (Nu<0){ Nu=0;} NUMc[n]=Nc;NUMu[n]=Nu;

//jj=dsolve('DN1=KC*N2-KU*N1', 'DN2=-KC*N2+KU*N1','N1(0)=NUMxp[n]','N2(0)=NUMyp[n]')N2=(-(NUM3p[n]*Kx-NUM2p[n]*Ky)/(Kx+Ky)*exp((-Kx-Ky)*TIMESTEP)*Ky+Nu*Kx/(Kx+Ky)*Ky)/Ky;N3=Nu/(Kx+Ky)*Ky+(NUM3p[n]*Kx-NUM2p[n]*Ky)/(Kx+Ky)*exp((-Kx-Ky)*TIMESTEP);if (N2>Nu) { N2=Nu; } else if (N2<0) { N2=0;}if (N3>Nu) { N3=Nu; } else if (N3<0) { N3=0;}NUM3p[n]=N3;NUM2p[n]=N2;NUM2[n]=N2;NUM3[n]=N3;EQLc=Nc*xLc;EQLu=N2*xL2+N3*xL3;d=fim_length[n];

statep=N3/(N3+N2);Lp= -0.0000000154*statep*statep*statep*statep*statep + 0.0000000487*statep*statep*statep*statep - 0.0000000607*statep*statep*statep +

0.0000000387*statep*statep - 0.0000000143*statep + 0.0000000034;

if (Lp>Lp2) { Lp=Lp2; }if (Lp<Lp3) { Lp=Lp3; }

C1=kbT/Lp;b=C1;b2=C1*C1;b3=C1*C1*C1;

if (Nu<=0) {force2=Km*(d-equilib_fimL[n]);

}else {

a=EQLu;a2=EQLu*EQLu;a3=EQLu*EQLu*EQLu;d2=d*d;d3=d2*d;e=EQLc;e2=e*e;e3=e2*e;

L1=(b*(64.0*Km3*a3+192.0*Km3*a2*e-192.0*Km3*a2*d+252.0*b*a2*Km2-384.0*Km3*a*d*e+192.0*Km3*a*d2+192.0*Km3*a*e2+288.0*Km2*a*e*b-288.0*Km2*a*d*b+324.0*b2*a*Km+64.0*Km3*e3+192.0*Km3*d2*e-64.0*Km3*d3-192.0*Km3*e2*d+144.0*Km2*d2*b+144.0*Km2*e2*b-288.0*Km2*d*e*b+108.0*b2*Km*e-108.0*b2*d*Km+135.0*b3));

L2=360.0*b*a2*Km2+192.0*Km3*a*d2-192.0*Km3*a2*d+192.0*Km3*a*e2-64.0*Km3*d3+64.0*Km3*e3+540.0*b2*a*Km+192.0*Km3*a2*e-288.0*Km2*d*e*b+243.0*b3-108.0*b2*d*Km+108.0*b2*Km*e-384.0*Km3*a*d*e+192.0*Km3*d2*e-192.0*Km3*e2*d+144.0*Km2*d2*b-288.0*Km2*a*d*b+144.0*Km2*e2*b+288.0*Km2*a*e*b+64.0*Km3*a3;

Lcc=1.0/12.0*a/(b+Km*a)*pow((L2+12.0*sq3*pow(L1,halfpw)*b+12.0*sq3*pow(L1,halfpw)*Km*a),thirdpw)+1.0/12.0*a*(-32.0*Km2*a*d+16.0*Km2*e2+16.0*Km2*d2+24.0*b*a*Km+32.0*Km2*a*e-24.0*b*d*Km-32.0*Km2*e*d+24.0*Km*e*b+9.0*b2+16.0*Km2*a2)/(b+Km*a)/pow((L2+12.0*sq3*pow(L1,halfpw)*b+12.0*sq3*pow(L1,halfpw)*Km*a),thirdpw)-1.0/12.0*(9.0*b*a-12.0*b*d+8.0*Km*a2-8.0*Km*a*d-4.0*Km*a*e)/(b+Km*a);

Lc=real(Lcc);

Page 42: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

force2=Km*(Lc-EQLc);}totten[n]=-force2;if (print==1 && fast==0) {

if (state[n]==2) {fprintf(fid2, "%2.8f\t%d\t%d\t%2.8f\t%2.8f\t%2.8f\t%2.8f\t%2.8f\r\n", time1, n,

state[n],totten[n]*1e12,NUMc[n],NUMu[n],NUM2[n],NUM3[n]);}

}} // End Coil

void outputs(){

for (int n = 0; n< numfim; n++) {bucklesum+=buckle[n];if (NUMu[n]>1) {

ratio[n]=NUMu[n]/(NUMc[n]+NUMu[n]);}else {

ratio[n]=0;}

}if (TYPE.compare("AFM")==0) {

fprintf(fid4, "%2.9f\t%2.6f\t%2.6f\t%3f\t%2.6f\t%2.6f\r\n", time1, center.y*1e6, tensionSum.y*1e12,contactsum,tottensum*1e12,rotatesum*1e12);

}

if (recordyn==1) {fprintf(fid9, "%2.3f\t%2.3f\t%2.3f\t",center.x*1e6,center.y*1e6,center.z*1e6);for (int nf = 1;nf<=numfim-1; nf++){

fprintf(fid9, "%2.3f\t%2.3f\t%2.3f\t%2.3f\t%2.3f\t%2.3f\t%d\t%d\t%2.3f\t",attach[nf-1].x*1e6, attach[nf-1].y*1e6,attach[nf-1].z*1e6,tip[nf-1].x*1e6,tip[nf-1].y*1e6,tip[nf-1].z*1e6,state[nf-1],buckle[nf-1],ratio[nf-1]);

}fprintf(fid9, "%2.3f\t%2.3f\t%2.3f\t%2.3f\t%2.3f\t%2.3f\t%d\t%d\t%2.3f\r\n",attach[numfim-1].x*1e6, attach[numfim-1].y*1e6,attach[numfim-

1].z*1e6,tip[numfim-1].x*1e6,tip[numfim-1].y*1e6,tip[numfim-1].z*1e6,state[numfim-1],buckle[numfim-1],ratio[numfim-1]);}

} // End outputs

void drive(int increment) {//determines change in position of the bead center in x,y,z directionsxposition=(xdw[increment+1]-xdw[increment]);yposition=(ydw[increment+1]-ydw[increment]);zposition=(zdw[increment+1]-zdw[increment]);

} //End drive

void ErmakAFM(){

drive(increment);partial+=1;if (partial==interp) {

increment+=1;partial=0;

}

//ocenter = old centerocenter.y = center.y;ocenter.x = center.x;ocenter.z = center.z;center.y=center.y+yposition;center.x=center.x+xposition;center.z=center.z+zposition;orig_center=orig_center+yposition;

} // End ErmakAFM

void bound_fimbriaAFM(int n){

//Calculate new fim_length. The fimbriae are bound at the attach point, so only the tips should move. fim_length[n] = exp(.5*log(((attach[n].x -tip[n].x)*(attach[n].x - tip[n].x) + (attach[n].y-tip[n].y)*(attach[n].y-tip[n].y) + (attach[n].z -

tip[n].z)*(attach[n].z - tip[n].z))));contactsum+=1;buckle[n]=0;

//Angle the fimbria is currently attether_anglet2[n] = atan2(tip[n].y-attach[n].y,tip[n].x-attach[n].x); //phitether_anglef2[n] = acos((tip[n].z-attach[n].z)/fim_length[n]); //thetaif (isnan(tether_anglef2[n])){

tether_anglef2[n]=0;}

Page 43: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

if (isnan(tether_anglet2[n])){tether_anglet2[n]=0;

}

//using 'coil' requires a more complex calculation for tottenif (usecoil==1) { coil(n); }else { totten[n]= -fim_stiffness*(fim_length[n] -equilib_fimL[n]); }

//if totten is positive and above a threshold, then buckling occursif (totten[n]> bound_factor[n]*Fbuckling[n]) {

totten[n] = bound_factor[n]*Fbuckling[n];buckle[n]=1;

}

//determine angle between current fimbria position and original fimbria positionanglediff[n]=acos(((tip[n].x-attach[n].x)*(normaltip[n].x-attach[n].x)+(tip[n].y-attach[n].y)*(normaltip[n].y-attach[n].y)+(tip[n].z-

attach[n].z)*(normaltip[n].z-attach[n].z))/(fim_length[n]*equilib_fimL[n]));

if (isnan(anglediff[n])){anglediff[n]=0;

}if (abs(anglediff[n])>.001) {

bent[n]=1;}else {bent[n]=0;}

//Need to calculate forces on bead due to torional forces of fimbriae

//Determining where fimbrial tip would be if it was at its full length, calculate unit vector firstuni_fully[n].x=(tip[n].x-attach[n].x)/fim_length[n];uni_fully[n].y=(tip[n].y-attach[n].y)/fim_length[n];uni_fully[n].z=(tip[n].z-attach[n].z)/fim_length[n];

//now calculate tip location at full-extensiontip_full[n].x=attach[n].x+uni_fully[n].x*equilib_fimL[n];tip_full[n].y=attach[n].y+uni_fully[n].y*equilib_fimL[n];tip_full[n].z=attach[n].z+uni_fully[n].z*equilib_fimL[n];

//distance between normal tip and tip_fullnormal_full[n]=sqrt((normaltip[n].x-tip_full[n].x)*(normaltip[n].x-tip_full[n].x)+(normaltip[n].y-tip_full[n].y)*(normaltip[n].y-tip_full[n].y)+

(normaltip[n].z-tip_full[n].z)*(normaltip[n].z-tip_full[n].z));

//Determine distance from attach point to xmin,ymin,zminlength_min[n]=fim_length[n];

//Need so that we aren't dividing by zeroif (normal_full[n]<1e-9) {

rotateforce[n].x=0;rotateforce[n].y=0;rotateforce[n].z=0;

}

else {

//the force vector for the rotational force will be the vector between tip_full and normal tip, get unit vectors. uni_tips[n].x=(normaltip[n].x-tip_full[n].x)/normal_full[n];uni_tips[n].y=(normaltip[n].y-tip_full[n].y)/normal_full[n];uni_tips[n].z=(normaltip[n].z-tip_full[n].z)/normal_full[n];

//create dummy tip that is stepped a small amount towards normal tipdummy_tip[n].x = tip_full[n].x+uni_tips[n].x*(1e-8);dummy_tip[n].y = tip_full[n].y+uni_tips[n].y*(1e-8);dummy_tip[n].z = tip_full[n].z+uni_tips[n].z*(1e-8);

//find dummy fimbria lengthdouble dummy_tip_length= sqrt((dummy_tip[n].x-attach[n].x)*(dummy_tip[n].x-attach[n].x)+(dummy_tip[n].y-attach[n].y)*(dummy_tip[n].y-

attach[n].y)+(dummy_tip[n].z-attach[n].z)*(dummy_tip[n].z-attach[n].z));

//determine dummy fimbria unit vectoruni_dummy_full[n].x = (dummy_tip[n].x-attach[n].x)/dummy_tip_length;uni_dummy_full[n].y = (dummy_tip[n].y-attach[n].y)/dummy_tip_length;uni_dummy_full[n].z = (dummy_tip[n].z-attach[n].z)/dummy_tip_length;

//extend dummy tip out to equilibrium fim lengthdummy_tip_full[n].x = attach[n].x+uni_dummy_full[n].x*equilib_fimL[n];dummy_tip_full[n].y = attach[n].y+uni_dummy_full[n].y*equilib_fimL[n];dummy_tip_full[n].z = attach[n].z+uni_dummy_full[n].z*equilib_fimL[n];

//Determine unit vector between dummy_tip_full and tip_fulldouble tip_full_tip_dummy_length = sqrt((dummy_tip_full[n].x-tip_full[n].x)*(dummy_tip_full[n].x-tip_full[n].x)+(dummy_tip_full[n].y-

tip_full[n].y)*(dummy_tip_full[n].y-tip_full[n].y)+(dummy_tip_full[n].z-tip_full[n].z)*(dummy_tip_full[n].z-tip_full[n].z));

//force unit vector will be vector between dummy_tip_full and tip_fulluni_force[n].x = (dummy_tip_full[n].x-tip_full[n].x)/tip_full_tip_dummy_length;uni_force[n].y = (dummy_tip_full[n].y-tip_full[n].y)/tip_full_tip_dummy_length;uni_force[n].z = (dummy_tip_full[n].z-tip_full[n].z)/tip_full_tip_dummy_length;

Page 44: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

//rotateforce is the force mulitplied by the force vector (uni_force)rotateforce[n].x=-uni_force[n].x*anglediff[n]*k[n]/fim_length[n];rotateforce[n].y=-uni_force[n].y*anglediff[n]*k[n]/fim_length[n];rotateforce[n].z=-uni_force[n].z*anglediff[n]*k[n]/fim_length[n];

}

//'tension' is sum of tension and rotate forces if there is not bucklingif (buckle[n]==0) {

tension[n].x = -totten[n]*sin(tether_anglef2[n])*cos(tether_anglet2[n])+rotateforce[n].x;tension[n].y = -totten[n]*sin(tether_anglef2[n])*sin(tether_anglet2[n])+rotateforce[n].y;tension[n].z = -totten[n]*cos(tether_anglef2[n])+rotateforce[n].z;

}//if buckling has occured, then there are not rotation forceselse {

tension[n].x = -totten[n]*sin(tether_anglef2[n])*cos(tether_anglet2[n]);tension[n].y = -totten[n]*sin(tether_anglef2[n])*sin(tether_anglet2[n]);tension[n].z = -totten[n]*cos(tether_anglef2[n]);

}

prev_state[n]=1;

} //End bound_fimbriaAFM

void unbound_fimbriaAFM(int n) {fim_length[n] = equilib_fimL[n];tension[n].x = 0;tension[n].y = 0;tension[n].z = 0;totten[n]=0;rotateforce[n].x=0;rotateforce[n].y=0;rotateforce[n].z=0;buckle[n]=0;//////Reset coiling parametersif (coiled[n]==1) {

NUMc[n]=subunits[n];NUMu[n]=0;NUM3p[n]=0;NUM2p[n]=0;

}//end if statement

//Determine current length of fimbriacurrent_length[n]=sqrt((tip[n].x-attach[n].x)*(tip[n].x-attach[n].x)+(tip[n].y-attach[n].y)*(tip[n].y-attach[n].y)+(tip[n].z-attach[n].z)*(tip[n].z-

attach[n].z));

//Extend fimbrial length out to its equilibrium fim lengthc_univect_x[n]=(tip[n].x-attach[n].x)/current_length[n];c_univect_y[n]=(tip[n].y-attach[n].y)/current_length[n];c_univect_z[n]=(tip[n].z-attach[n].z)/current_length[n];

tip[n].x=attach[n].x+fim_length[n]*c_univect_x[n];tip[n].y=attach[n].y+fim_length[n]*c_univect_y[n];tip[n].z=attach[n].z+fim_length[n]*c_univect_z[n];

//solve for x-location on fimbriae which will have minimum distance to center of cell. xmin_g = (2*center.x + (2*(attach[n].y - tip[n].y)*(center.y - attach[n].y + (attach[n].x*(attach[n].y - tip[n].y))/(attach[n].x -

tip[n].x)))/(attach[n].x - tip[n].x) + (2*(attach[n].z - tip[n].z)*(center.z - attach[n].z + (attach[n].x*(attach[n].z - tip[n].z))/(attach[n].x - tip[n].x)))/(attach[n].x - tip[n].x))/((2*(attach[n].y - tip[n].y)*(attach[n].y - tip[n].y))/((attach[n].x - tip[n].x)*(attach[n].x - tip[n].x)) + (2*(attach[n].z - tip[n].z)*(attach[n].z - tip[n].z))/((attach[n].x - tip[n].x)*(attach[n].x - tip[n].x)) + 2);

//if xmin_g is somewhere along the length of the fimbriae then the minimum distance is calculated at xminif (xmin_g>attach[n].x) {

if (xmin_g<tip[n].x) {xmin[n]=xmin_g;

}

}else if (xmin_g<attach[n].x) {

if (xmin_g>tip[n].x) {xmin[n]=xmin_g;

}}

//if xmin_g is not along the fimbriae, it is calculated as either the tip or attachment point. if (xmin_g>attach[n].x) {

if (xmin_g>tip[n].x) {tip_diff = abs(tip[n].x-xmin_g);attach_diff = abs(attach[n].x-xmin_g);

if(tip_diff>attach_diff) {xmin[n]=attach[n].x;

}

Page 45: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

else {xmin[n]=tip[n].x;

}}

}

if (xmin_g<attach[n].x) {if (xmin_g<tip[n].x) {

tip_diff = abs(tip[n].x-xmin_g);attach_diff = abs(attach[n].x-xmin_g);

if(tip_diff>attach_diff) {xmin[n]=attach[n].x;

}else {

xmin[n]=tip[n].x;}

}}

//Calculate the y and z coordinates at the mininimum distance point, and then the minimum distanceymin[n]=((tip[n].y-attach[n].y)/(tip[n].x-attach[n].x))*(xmin[n]-attach[n].x)+attach[n].y;zmin[n]=((tip[n].z-attach[n].z)/(tip[n].x-attach[n].x))*(xmin[n]-attach[n].x)+attach[n].z;Dmin[n]=sqrt((xmin[n]-center.x)*(xmin[n]-center.x)+(ymin[n]-center.y)*(ymin[n]-center.y)+(zmin[n]-center.z)*(zmin[n]-center.z));;double xmincheck=xmin[n];double ymincheck=ymin[n];double zmincheck=zmin[n];

//If the minimum distance point is within the bead, then take small steps outward until it is just touching the surfaceif (Dmin[n]<cell_radius-dCrit) {

while (Dmin[n]<cell_radius-dCrit) {

part_xmin[n]=-(2*center.x - 2*xmin[n])/(2*sqrt((center.x - xmin[n])*(center.x-xmin[n]) + (center.y - ymin[n])*(center.y - ymin[n]) + (center.z - zmin[n])*(center.z - zmin[n])));

part_ymin[n]=-(2*center.y - 2*ymin[n])/(2*sqrt((center.x - xmin[n])*(center.x-xmin[n]) + (center.y - ymin[n])*(center.y - ymin[n]) + (center.z - zmin[n])*(center.z - zmin[n])));

part_zmin[n]=-(2*center.z - 2*zmin[n])/(2*sqrt((center.x - xmin[n])*(center.x-xmin[n]) + (center.y - ymin[n])*(center.y - ymin[n]) + (center.z - zmin[n])*(center.z - zmin[n])));

new_xmin[n]=xmin[n]-part_xmin[n]*(Dmin[n]-cell_radius)*0.1;new_ymin[n]=ymin[n]-part_ymin[n]*(Dmin[n]-cell_radius)*0.1;new_zmin[n]=zmin[n]-part_zmin[n]*(Dmin[n]-cell_radius)*0.1;

u_vect_x[n]=(new_xmin[n]-attach[n].x)/sqrt((new_xmin[n]-attach[n].x)*(new_xmin[n]-attach[n].x)+(new_ymin[n]-attach[n].y)*(new_ymin[n]-attach[n].y)+(new_zmin[n]-attach[n].z)*(new_zmin[n]-attach[n].z));

u_vect_y[n]=(new_ymin[n]-attach[n].y)/sqrt((new_xmin[n]-attach[n].x)*(new_xmin[n]-attach[n].x)+(new_ymin[n]-attach[n].y)*(new_ymin[n]-attach[n].y)+(new_zmin[n]-attach[n].z)*(new_zmin[n]-attach[n].z));

u_vect_z[n]=(new_zmin[n]-attach[n].z)/sqrt((new_xmin[n]-attach[n].x)*(new_xmin[n]-attach[n].x)+(new_ymin[n]-attach[n].y)*(new_ymin[n]-attach[n].y)+(new_zmin[n]-attach[n].z)*(new_zmin[n]-attach[n].z));

tip[n].x=attach[n].x+u_vect_x[n]*equilib_fimL[n];tip[n].y=attach[n].y+u_vect_y[n]*equilib_fimL[n];tip[n].z=attach[n].z+u_vect_z[n]*equilib_fimL[n];

//solve for x-location on fimbriae which will have minimum distance to center of cell. xmin_g = (2*center.x + (2*(attach[n].y - tip[n].y)*(center.y - attach[n].y + (attach[n].x*(attach[n].y - tip[n].y))/(attach[n].x -

tip[n].x)))/(attach[n].x - tip[n].x) + (2*(attach[n].z - tip[n].z)*(center.z - attach[n].z + (attach[n].x*(attach[n].z - tip[n].z))/(attach[n].x - tip[n].x)))/(attach[n].x - tip[n].x))/((2*(attach[n].y - tip[n].y)*(attach[n].y - tip[n].y))/((attach[n].x - tip[n].x)*(attach[n].x - tip[n].x)) + (2*(attach[n].z - tip[n].z)*(attach[n].z - tip[n].z))/((attach[n].x - tip[n].x)*(attach[n].x - tip[n].x)) + 2);

//if xmin_g is somewhere along the length of the fimbriae then the minimum distance is calculated at xminif (xmin_g>attach[n].x) {

if (xmin_g<tip[n].x) {xmin[n]=xmin_g;

}

}else if (xmin_g<attach[n].x) {

if (xmin_g>tip[n].x) {xmin[n]=xmin_g;

}}

//if xmin_g is not along the fimbriae, it is calculated as either the tip or attachment point. if (xmin_g>attach[n].x) {

if (xmin_g>tip[n].x) {tip_diff = abs(tip[n].x-xmin_g);attach_diff = abs(attach[n].x-xmin_g);

if(tip_diff>attach_diff) {xmin[n]=attach[n].x;

}else {

xmin[n]=tip[n].x;}

}}

if (xmin_g<attach[n].x) {

Page 46: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

if (xmin_g<tip[n].x) {tip_diff = abs(tip[n].x-xmin_g);attach_diff = abs(attach[n].x-xmin_g);

if(tip_diff>attach_diff) {xmin[n]=attach[n].x;

}else {

xmin[n]=tip[n].x;}

}}

//Calculate the y and z coordinates at the mininimum distance point, and then the minimum distanceymin[n]=((tip[n].y-attach[n].y)/(tip[n].x-attach[n].x))*(xmin[n]-attach[n].x)+attach[n].y;zmin[n]=((tip[n].z-attach[n].z)/(tip[n].x-attach[n].x))*(xmin[n]-attach[n].x)+attach[n].z;Dmin[n]=sqrt((xmin[n]-center.x)*(xmin[n]-center.x)+(ymin[n]-center.y)*(ymin[n]-center.y)+(zmin[n]-center.z)*(zmin[n]-center.z));

}//end while loop}//end if statement////Need fimbria to "rebound" after being compressed.if (Dmin[n]>cell_radius+dCrit) {

//tip_dist is current distance between tip and normal tipdouble tip_dist = sqrt((tip[n].x-normaltip[n].x)*(tip[n].x-normaltip[n].x)+(tip[n].y-normaltip[n].y)*(tip[n].y-normaltip[n].y)+(tip[n].z-

normaltip[n].z)*(tip[n].z-normaltip[n].z));double distance_prime = fmin(tip_dist,abs(Dmin[n]-cell_radius));

//if distance_prime is greater than dCrit, than the tip will move towards normal_tipif (distance_prime > 1e-9) {

//Step fimbria toward normal tip until min(tip_dist, Dmin) < dCritwhile (distance_prime > 1e-9) {

//determine distance between tip and normal tipnormal_full[n]=sqrt((normaltip[n].x-tip[n].x)*(normaltip[n].x-tip[n].x)+(normaltip[n].y-tip[n].y)*(normaltip[n].y-tip[n].y)

+(normaltip[n].z-tip[n].z)*(normaltip[n].z-tip[n].z));

//get unit vectors between tip and normal tipuni_tips[n].x=(normaltip[n].x-tip[n].x)/normal_full[n];uni_tips[n].y=(normaltip[n].y-tip[n].y)/normal_full[n];uni_tips[n].z=(normaltip[n].z-tip[n].z)/normal_full[n];

//take small step towards normal tipnew_tipx[n]=tip[n].x+uni_tips[n].x*distance_prime*0.1;new_tipy[n]=tip[n].y+uni_tips[n].y*distance_prime*0.1;new_tipz[n]=tip[n].z+uni_tips[n].z*distance_prime*0.1;

//determine unit vector between new tip and attachment pointu_vect_x[n]=(new_tipx[n]-attach[n].x)/sqrt((new_tipx[n]-attach[n].x)*(new_tipx[n]-attach[n].x)+(new_tipy[n]-

attach[n].y)*(new_tipy[n]-attach[n].y)+(new_tipz[n]-attach[n].z)*(new_tipz[n]-attach[n].z));u_vect_y[n]=(new_tipy[n]-attach[n].y)/sqrt((new_tipx[n]-attach[n].x)*(new_tipx[n]-attach[n].x)+(new_tipy[n]-

attach[n].y)*(new_tipy[n]-attach[n].y)+(new_tipz[n]-attach[n].z)*(new_tipz[n]-attach[n].z));u_vect_z[n]=(new_tipz[n]-attach[n].z)/sqrt((new_tipx[n]-attach[n].x)*(new_tipx[n]-attach[n].x)+(new_tipy[n]-

attach[n].y)*(new_tipy[n]-attach[n].y)+(new_tipz[n]-attach[n].z)*(new_tipz[n]-attach[n].z));

//extend out new tip so that fim length is equal to equilibrium fim lengthtip[n].x=attach[n].x+u_vect_x[n]*equilib_fimL[n];tip[n].y=attach[n].y+u_vect_y[n]*equilib_fimL[n];tip[n].z=attach[n].z+u_vect_z[n]*equilib_fimL[n];

//solve for x-location on fimbriae which will have minimum distance to center of cell. xmin_g = (2*center.x + (2*(attach[n].y - tip[n].y)*(center.y - attach[n].y + (attach[n].x*(attach[n].y -

tip[n].y))/(attach[n].x - tip[n].x)))/(attach[n].x - tip[n].x) + (2*(attach[n].z - tip[n].z)*(center.z - attach[n].z + (attach[n].x*(attach[n].z - tip[n].z))/(attach[n].x - tip[n].x)))/(attach[n].x - tip[n].x))/((2*(attach[n].y - tip[n].y)*(attach[n].y - tip[n].y))/((attach[n].x - tip[n].x)*(attach[n].x - tip[n].x)) + (2*(attach[n].z - tip[n].z)*(attach[n].z - tip[n].z))/((attach[n].x - tip[n].x)*(attach[n].x - tip[n].x)) + 2);

//if xmin_g is somewhere along the length of the fimbriae then the minimum distance is calculated at xminif (xmin_g>attach[n].x) {

if (xmin_g<tip[n].x) {xmin[n]=xmin_g;

}

}else if (xmin_g<attach[n].x) {

if (xmin_g>tip[n].x) {xmin[n]=xmin_g;

}}

//if xmin_g is not along the fimbriae, it is calculated as either the tip or attachment point. if (xmin_g>attach[n].x) {

if (xmin_g>tip[n].x) {tip_diff = abs(tip[n].x-xmin_g);attach_diff = abs(attach[n].x-xmin_g);

if(tip_diff>attach_diff) {xmin[n]=attach[n].x;

}

Page 47: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

else {xmin[n]=tip[n].x;

}}

}

if (xmin_g<attach[n].x) {if (xmin_g<tip[n].x) {

tip_diff = abs(tip[n].x-xmin_g);attach_diff = abs(attach[n].x-xmin_g);

if(tip_diff>attach_diff) {xmin[n]=attach[n].x;

}else {

xmin[n]=tip[n].x;}

}}

//Calculate the y and z coordinates at the mininimum distance point, and then the minimum distanceymin[n]=((tip[n].y-attach[n].y)/(tip[n].x-attach[n].x))*(xmin[n]-attach[n].x)+attach[n].y;zmin[n]=((tip[n].z-attach[n].z)/(tip[n].x-attach[n].x))*(xmin[n]-attach[n].x)+attach[n].z;Dmin[n]=sqrt((xmin[n]-center.x)*(xmin[n]-center.x)+(ymin[n]-center.y)*(ymin[n]-center.y)+(zmin[n]-

center.z)*(zmin[n]-center.z));tip_dist = sqrt((tip[n].x-normaltip[n].x)*(tip[n].x-normaltip[n].x)+(tip[n].y-normaltip[n].y)*(tip[n].y-normaltip[n].y)+

(tip[n].z-normaltip[n].z)*(tip[n].z-normaltip[n].z));distance_prime = fmin(tip_dist,abs(Dmin[n]-cell_radius-dCrit));

}//end while loop}// end if statement

} //end if statement////change in angle of the fimbriae because of fimbriae tip being below surfaceanglediff[n]=acos(((tip[n].x-attach[n].x)*(normaltip[n].x-attach[n].x)+(-attach[n].y+tip[n].y)*(normaltip[n].y-attach[n].y)+(-

attach[n].z+tip[n].z)*(normaltip[n].z-attach[n].z))/(fim_length[n]*fim_length[n]));

if (isnan(anglediff[n])){anglediff[n]=0;

}if (abs(anglediff[n])>.001) {

bent[n]=1;}else {bent[n]=0;}

//Need to calculate forces on bead due to torional forces of fimbriae

//Determining where fimbrial tip would be if it was at its full length, calculate unit vector firstuni_fully[n].x=(tip[n].x-attach[n].x)/fim_length[n];uni_fully[n].y=(tip[n].y-attach[n].y)/fim_length[n];uni_fully[n].z=(tip[n].z-attach[n].z)/fim_length[n];

//now calculate tip location at full-extensiontip_full[n].x=attach[n].x+uni_fully[n].x*equilib_fimL[n];tip_full[n].y=attach[n].y+uni_fully[n].y*equilib_fimL[n];tip_full[n].z=attach[n].z+uni_fully[n].z*equilib_fimL[n];

//distance between normal tip and tip_fullnormal_full[n]=sqrt((normaltip[n].x-tip_full[n].x)*(normaltip[n].x-tip_full[n].x)+(normaltip[n].y-tip_full[n].y)*(normaltip[n].y-tip_full[n].y)+

(normaltip[n].z-tip_full[n].z)*(normaltip[n].z-tip_full[n].z));

//Determine distance from attach point to xmin,ymin,zminlength_min[n]=sqrt((xmin[n]-attach[n].x)*(xmin[n]-attach[n].x)+(ymin[n]-attach[n].y)*(ymin[n]-attach[n].y)+(zmin[n]-attach[n].z)*(zmin[n]-

attach[n].z));

//need so that we aren't dividing by zeroif (normal_full[n]<1e-9) {

rotateforce[n].x=0;rotateforce[n].y=0;rotateforce[n].z=0;

}else {

//the force vector for the rotational force will be the vector between tip_full and normal tip, get univectors. uni_tips[n].x=(normaltip[n].x-tip_full[n].x)/normal_full[n];uni_tips[n].y=(normaltip[n].y-tip_full[n].y)/normal_full[n];uni_tips[n].z=(normaltip[n].z-tip_full[n].z)/normal_full[n];

//create dummy tip that is stepped a small amount towards normal tipdummy_tip[n].x = tip_full[n].x+uni_tips[n].x*(1e-8);dummy_tip[n].y = tip_full[n].y+uni_tips[n].y*(1e-8);dummy_tip[n].z = tip_full[n].z+uni_tips[n].z*(1e-8);

//find dummy fimbria lengthdouble dummy_tip_length= sqrt((dummy_tip[n].x-attach[n].x)*(dummy_tip[n].x-attach[n].x)+(dummy_tip[n].y-attach[n].y)*(dummy_tip[n].y-

attach[n].y)+(dummy_tip[n].z-attach[n].z)*(dummy_tip[n].z-attach[n].z));

//determine dummy fimbria unit vectoruni_dummy_full[n].x = (dummy_tip[n].x-attach[n].x)/dummy_tip_length;uni_dummy_full[n].y = (dummy_tip[n].y-attach[n].y)/dummy_tip_length;uni_dummy_full[n].z = (dummy_tip[n].z-attach[n].z)/dummy_tip_length;

Page 48: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

//extend dummy tip out to equilibrium fim lengthdummy_tip_full[n].x = attach[n].x+uni_dummy_full[n].x*equilib_fimL[n];dummy_tip_full[n].y = attach[n].y+uni_dummy_full[n].y*equilib_fimL[n];dummy_tip_full[n].z = attach[n].z+uni_dummy_full[n].z*equilib_fimL[n];

//Determine unit vector between dummy_tip_full and tip_fulldouble tip_full_tip_dummy_length = sqrt((dummy_tip_full[n].x-tip_full[n].x)*(dummy_tip_full[n].x-tip_full[n].x)+(dummy_tip_full[n].y-

tip_full[n].y)*(dummy_tip_full[n].y-tip_full[n].y)+(dummy_tip_full[n].z-tip_full[n].z)*(dummy_tip_full[n].z-tip_full[n].z));

//force unit vector will be vector between dummy_tip_full and tip_fulluni_force[n].x = (dummy_tip_full[n].x-tip_full[n].x)/tip_full_tip_dummy_length;uni_force[n].y = (dummy_tip_full[n].y-tip_full[n].y)/tip_full_tip_dummy_length;uni_force[n].z = (dummy_tip_full[n].z-tip_full[n].z)/tip_full_tip_dummy_length;

//rotateforce is the force mulitplied by the force vector (uni_force)rotateforce[n].x=-uni_force[n].x*anglediff[n]*k[n]/length_min[n];rotateforce[n].y=-uni_force[n].y*anglediff[n]*k[n]/length_min[n];rotateforce[n].z=-uni_force[n].z*anglediff[n]*k[n]/length_min[n];

}

//no tension forces on cell if there is the fimbriae is not boundtension[n].x = rotateforce[n].x;tension[n].y = rotateforce[n].y;tension[n].z = rotateforce[n].z;

prev_state[n]=0;

} // End unbound_fimbriaAFM

void Fimbriae_Locations() {

//Read fimbriae locations in...//Z-coordinates need to be read in as y-coordinates, since the vertical direction is y in the simulations//length of file must match number of fimbriae defined in "globals"

double dummy = randomn()*1;int p = ceil(dummy);printf("%03d \r\n",p);sleep(5);

char keithcounter[4] = {0};sprintf(keithcounter, "%03d",p);

x_start_name = string("fim_x_start_16_") + keithcounter + ".txt";

ifstream fim_x_start;fim_x_start.open (x_start_name.c_str());if(!fim_x_start) { // file couldn't be opened

cerr << "Error: file could not be opened" << endl;exit(1);

}

size=fim_x_start.tellg();memblock=new char [size];fxs.resize(numfim);

fim_x_start >> fxs[0];

int i=0;while ( i < (numfim+1) ) { // keep reading until end-of-file

i=i+1;fim_x_start >> fxs[i]; // sets EOF flag if no value found

}

fim_x_start.close();

///////////////////////////////////////////////////////////////////

z_start_name = string("fim_z_start_16_") + keithcounter + ".txt";

ifstream fim_y_start;fim_y_start.open (z_start_name.c_str());if(!fim_y_start) { // file couldn't be opened

cerr << "Error: file could not be opened" << endl;exit(1);

}size=fim_y_start.tellg();memblock=new char [size];fys.resize(numfim);fim_y_start >> fys[0];i=0;while ( i < (numfim+1) ) { // keep reading until end-of-file

i=i+1;fim_y_start >> fys[i]; // sets EOF flag if no value found

}

Page 49: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

fim_y_start.close();

///////////////////////////////////////////////////////////////////

y_start_name = string("fim_y_start_16_") + keithcounter + ".txt";

ifstream fim_z_start;fim_z_start.open (y_start_name.c_str());if(!fim_z_start) { // file couldn't be opened

cerr << "Error: file could not be opened" << endl;exit(1);

}size=fim_z_start.tellg();memblock=new char [size];fzs.resize(numfim+1);fim_z_start >> fzs[0];i=0;while ( i < (numfim+1) ) { // keep reading until end-of-file

i=i+1;fim_z_start >> fzs[i]; // sets EOF flag if no value found

}

fim_z_start.close();

/////////////////////////////////////////////////////////////////////

x_end_name = string("fim_x_end_16_") + keithcounter + ".txt";

ifstream fim_x_end;fim_x_end.open (x_end_name.c_str());if(!fim_x_end) { // file couldn't be opened

cerr << "Error: file could not be opened" << endl;exit(1);

}size=fim_x_end.tellg();memblock=new char [size];fxe.resize(numfim);fim_x_end >> fxe[0];i=0;while ( i < (numfim+1) ) { // keep reading until end-of-file

i=i+1;fim_x_end >> fxe[i]; // sets EOF flag if no value found

}

fim_x_end.close();

/////////////////////////////////////////////////////////////////////

z_end_name = string("fim_z_end_16_") + keithcounter + ".txt";

ifstream fim_y_end;fim_y_end.open (z_end_name.c_str());if(!fim_y_end) { // file couldn't be opened

cerr << "Error: file could not be opened" << endl;exit(1);

}size=fim_y_end.tellg();memblock=new char [size];fye.resize(numfim);fim_y_end >> fye[0];i=0;while ( i < (numfim+1) ) { // keep reading until end-of-file

i=i+1;fim_y_end >> fye[i]; // sets EOF flag if no value found

}

fim_y_end.close();

/////////////////////////////////////////////////////////////////////

y_end_name = string("fim_y_end_16_") + keithcounter + ".txt";

ifstream fim_z_end;fim_z_end.open (y_end_name.c_str());if(!fim_z_end) { // file couldn't be opened

cerr << "Error: file could not be opened" << endl;exit(1);

}size=fim_z_end.tellg();memblock=new char [size];fze.resize(numfim);fim_z_end >> fze[0];i=0;while ( i < (numfim+1) ) { // keep reading until end-of-file

i=i+1;fim_z_end >> fze[i]; // sets EOF flag if no value found

}

Page 50: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

fim_z_end.close();}

void AFM() {

//read drivewave files into dw files

ifstream drivewavex;drivewavex.open ("drivewavex.txt");if(!drivewavex) { // file couldn't be opened

cerr << "Error: file could not be opened" << endl;exit(1);

}size=drivewavex.tellg();memblock=new char [size];xdw.resize((TMAX/TIMESTEP)+1);drivewavex >> xdw[0];int i=0;while ( i < (TMAX*(1/TIMESTEP)+1) ) { // keep reading until end-of-file

i=i+1;drivewavex >> xdw[i]; // sets EOF flag if no value found

}

drivewavex.close();ifstream drivewavey;drivewavey.open ("drivewavey.txt");if(!drivewavey) { // file couldn't be opened

cerr << "Error: file could not be opened" << endl;exit(1);

}size=drivewavey.tellg();memblock=new char [size];ydw.resize((TMAX/TIMESTEP)+1);drivewavey >> ydw[0];i=0;//while ( !drivewavey.eof() ) { // keep reading until end-of-filewhile ( i < (TMAX*(1/TIMESTEP)+1) ){

i=i+1;drivewavey >> ydw[i]; // sets EOF flag if no value found//cout << ydw[i] << endl;

}drivewavey.close();ifstream drivewavez;drivewavez.open ("drivewavez.txt");if(!drivewavez) { // file couldn't be opened

cerr << "Error: file could not be opened" << endl;exit(1);

}size=drivewavez.tellg();memblock=new char [size];zdw.resize((TMAX/TIMESTEP)+1);drivewavez >> zdw[0];i=0;while ( i < (TMAX*(1/TIMESTEP)+1) ) { // keep reading until end-of-file

i=i+1;drivewavez >> zdw[i]; // sets EOF flag if no value found

}

drivewavez.close();double reverse=80;

//Continue running until time exceeds TMAXwhile (time1 < TMAX) {

if (time1>=t) {t=t+1.0/PRINTSPERSECOND;print=1;

}else {print=0;}

//determine bondstate for each fimbriaefor (int n = 0; n< numfim; n++) {

catchbond(state[n], n);}posjump=0;time1 = time1 + TIMESTEP;

//reset tensionSum and contactsumtensionSum.y = 0;tottensum = 0;contactsum=0;rotatesum = 0;

//if bead is below the surface, bead is actually at surfaceif (orig_center<cell_radius) {

center.y = cell_radius;}

for (int n = 0; n< numfim; n++) {

Page 51: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

if (state[n]>0) {//update tip coordinates if boundtip[n].x=(tip[n].x-ocenter.x)+center.x;tip[n].y=(tip[n].y-ocenter.y)+center.y;tip[n].z=(tip[n].z-ocenter.z)+center.z;

}//double keith = time1;//printf("%4.2f \n",keith);

//if state is 1 or 2 (and tip is thus bound), run bound_fimbriaAFMif (state[n] >0) {

bound_fimbriaAFM(n);}//run unbound_fimbriaAFM is fimbriae is not boundelse {

unbound_fimbriaAFM(n);}

//add each fimbriae's y-tension to get total tension on bead in y-directiontensionSum.y = tensionSum.y + tension[n].y;tottensum = tottensum + totten[n];rotatesum = rotatesum + rotateforce[n].y;

}

//if bead is "below" surface, then the bead is subjected to a force from the surfaceif (orig_center<cell_radius) {tensionSum.y = tensionSum.y-floor_k*(cell_radius-orig_center);}

//Run Ermak to get new bead center locationErmakAFM();

//print outputsif (print==1 || time1>= TMAX) {

outputs();}

} //end while loop

}

int main(){

cout<<"Fimbrial Simulation Started"<<endl;clock_t start = clock(); // Remember when the program started

//// Seeding the random number generator so that it creates a new random number every time randomn() is called.srand((unsigned)time(NULL));globals(); // Initialize the global parameters

// Following loop creates the output files with the lowest number that does not already exist// If the files already exist, the loop is repeated and the index is iterated and appended to // the file names until the program tries to open files that have not been created yet.bool alreadyExists;char stringcounter[4] = {0}; // Number that appears in output file namesfor (int i = naming; i<999; i ++) {

sprintf(stringcounter, "%03d", i);filename4 = string("trajectory") + stringcounter + ".txt";// since fprintf is a c command, need to convert the c++ filename strings into c type strings, using .c_str()fid4 = fopen(filename4.c_str(), "r");if (fid4 !=NULL ) {alreadyExists = true;} else{alreadyExists = false;}if (fid4) fclose(fid4);if (!alreadyExists) {break;}

}

filename1 = string("statechange") + stringcounter + ".txt";fid1 = fopen(filename1.c_str(), "w");fid4 = fopen(filename4.c_str(), "w");

//// Print Header line in Data output files, if this is changed then Matlab analysis files will also need to be changed

if (TYPE.compare("AFM")==0) {fprintf(fid4,"%s\t%s\t%s\t%s\t%s\t%s\r\n", "time1", "center.y*1e6","tensionSum.y*1e12","Contactsum","tottensum*1e12","rotatesumy*1e12");

}

fprintf(fid1,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\r\n","fim num", "state", "nextState", "time", "TotalTension","fim length","eql fim length","fraction uncoiled");

if (fast==0) {filename2 = string("coil") + stringcounter + ".txt";fid2 = fopen(filename2.c_str(), "w");

fprintf(fid2,"%s\t%s\t%s\t%s\t%s\t%s\t%s\r\n","Time","n","state[n]","NUMC[n]","NUM2[n]","NUM3[n]");

Page 52: 402 CAPSTONE THESIS

Ning ShuBIOEN402SENIOR YEAR CAPSTONE THESIS

}

if (TYPE.compare("AFM")==0) {filename7 = string("lifetime") + stringcounter + ".txt";fid7 = fopen(filename7.c_str(), "w");

}

//// Inorder to reduce output files, this is currently set only to produce large visualization files//// when index number ends with 0 char num []="0";char num2 []="9";string sc=stringcounter;int dovisual=sc.substr(2,1).compare(num);if (dovisual==0) {

filename9 = string("forvmd") +stringcounter + ".txt";recordyn=1;fid9 = fopen(filename9.c_str(), "w");

}

Fimbriae_Locations(); // set fimbriae locationssetvariables(); // Set many variables

if (TYPE.compare("AFM")==0) {AFM();

}

else {cout<<"PLEASE USE VALID INPUT FILE"<< 0 <<endl;

}

fclose(fid1);fclose(fid4);if (recordyn==1) { fclose(fid9);}if (fast==0) {

fclose(fid2);}if (TYPE.compare("AFM")==0) {

fclose(fid7);}

////Spits out how long the simulation took to run///*sleep(5);clock_t end = clock();cout << "time elapsed (seconds): " << (end - start)/CLOCKS_PER_SEC << endl;cout << "Done!";return 0;

}