Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
blairlyons committed May 3, 2022
1 parent 57a4dfa commit 4d1997a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 59 deletions.
29 changes: 10 additions & 19 deletions vivarium_models/library/scan.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
from vivarium.core.engine import Engine, pf

class Scan():
def __init__(
self,
parameter_sets,
simulator_class,
total_time,
metrics=()):

class Scan:
def __init__(self, parameter_sets, simulator_class, total_time, metrics=()):

self.parameter_sets = parameter_sets
self.simulator_class = simulator_class
self.total_time = total_time
self.metrics = metrics

def run_simulation(self, parameters):
simulator = self.simulator_class(parameters['parameters']).generate()
simulator = self.simulator_class(parameters["parameters"]).generate()
engine = Engine(
processes=simulator['processes'],
topology=simulator['topology'],
initial_state=parameters['states'])
processes=simulator["processes"],
topology=simulator["topology"],
initial_state=parameters["states"],
)
engine.update(self.total_time)
return engine.emitter.get_data()

def run_scan(self):
results = {}
for id, parameter_set in self.parameter_sets.items():
data = self.run_simulation(parameter_set)
metrics = {
name: metric(data)
for name, metric in self.metrics.items()}
results[id] = {
'data': data,
'metrics': metrics}
metrics = {name: metric(data) for name, metric in self.metrics.items()}
results[id] = {"data": data, "metrics": metrics}
return results


72 changes: 32 additions & 40 deletions vivarium_models/processes/readdy_actin_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
ActinAnalyzer,
)
from simularium_models_util import ReaddyUtil
from vivarium_models.util import create_monomer_update
from vivarium_models.util import create_monomer_update, format_monomer_results
from vivarium_models.library.scan import Scan

Expand Down Expand Up @@ -249,7 +248,7 @@ def get_monomer_data():
monomer_data = ActinTestData.linear_actin_monomers()
monomer_data["box_center"] = np.array([3000.0, 1000.0, 1000.0])
monomer_data["box_size"] = 500.0
return {'monomers': monomer_data}
return {"monomers": monomer_data}


def test_readdy_actin_process():
Expand Down Expand Up @@ -278,47 +277,45 @@ def test_scan_readdy():
monomer_data = get_monomer_data()

parameters = {
'1': {
'parameters': {
'actin_concentration': 100.0,
'arp23_concentration': 5.0},
'states': monomer_data},
'2': {
'parameters': {
'actin_concentration': 200.0,
'arp23_concentration': 10.0},
'states': monomer_data},
'3': {
'parameters': {
'actin_concentration': 300.0,
'arp23_concentration': 20.0},
'states': monomer_data}}
"1": {
"parameters": {"actin_concentration": 100.0, "arp23_concentration": 5.0},
"states": monomer_data,
},
"2": {
"parameters": {"actin_concentration": 200.0, "arp23_concentration": 10.0},
"states": monomer_data,
},
"3": {
"parameters": {"actin_concentration": 300.0, "arp23_concentration": 20.0},
"states": monomer_data,
},
}

def count_monomers(results):
outcome = list(results.values())[-1]
return len(outcome['monomers']['particles'])
return len(outcome["monomers"]["particles"])

def count_monomer_types(results):
outcome = list(results.values())[-1]
monomer_types = {}
for particle in outcome['monomers']['particles'].values():
type_name = particle['type_name']

for particle in outcome["monomers"]["particles"].values():
type_name = particle["type_name"]
if type_name not in monomer_types:
monomer_types[type_name] = 0
monomer_types[type_name] += 1

return monomer_types

def filament_lengths(results):
outcome = list(results.values())[-1]
barbed = None
pointed = None
for particle in outcome['monomers']['particles'].values():
if 'barbed' in particle['type_name']:
barbed = np.array(particle['position'])
elif 'pointed' in particle['type_name']:
pointed = np.array(particle['position'])
for particle in outcome["monomers"]["particles"].values():
if "barbed" in particle["type_name"]:
barbed = np.array(particle["position"])
elif "pointed" in particle["type_name"]:
pointed = np.array(particle["position"])

difference = barbed - pointed
length = np.linalg.norm(difference)
Expand Down Expand Up @@ -384,9 +381,9 @@ def filament_straightness(results):
)

metrics = {
'count_monomers': count_monomers,
'count_monomer_types': count_monomer_types,
'filament_lengths': filament_lengths}
"count_monomers": count_monomers,
"count_monomer_types": count_monomer_types,
"filament_lengths": filament_lengths,
"percent_filamentous_actin": percent_filamentous_actin,
"percent_bound_arp23": percent_bound_arp23,
"percent_daughter_actin": percent_daughter_actin,
Expand All @@ -398,21 +395,16 @@ def filament_straightness(results):
"filament_straightness": filament_straightness,
}

scan = Scan(
parameters,
ReaddyActinProcess,
0.0000001,
metrics=metrics)
scan = Scan(parameters, ReaddyActinProcess, 0.0000001, metrics=metrics)

results = scan.run_scan()


import ipdb; ipdb.set_trace()
import ipdb

ipdb.set_trace()


library = {
'0': test_readdy_actin_process,
'1': test_scan_readdy}
library = {"0": test_readdy_actin_process, "1": test_scan_readdy}


if __name__ == "__main__":
Expand Down

0 comments on commit 4d1997a

Please sign in to comment.