Skip to content

Commit d95a444

Browse files
author
Angelika Genya Hirsch
committed
Combining previous commits
1 parent 0a23692 commit d95a444

File tree

1,903 files changed

+3897
-337208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,903 files changed

+3897
-337208
lines changed

chromo/mc/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _polymer_in_field(
109109
(default = None)
110110
"""
111111
np.random.seed(random_seed)
112-
print("output init "+ str(output_dir))
112+
#print("output init "+ str(output_dir))
113113
#print(log_directory)
114114
if mc_move_controllers is None:
115115
mc_move_controllers = all_moves(
@@ -143,6 +143,8 @@ def _polymer_in_field(
143143
temperature_adjust_factor = temp_schedule.logarithmic_decrease(mc_count, num_saves)
144144
elif temperature_schedule == "decreasing stepwise":
145145
temperature_adjust_factor = temp_schedule.decreasing_stepwise(mc_count, num_saves)
146+
elif temperature_schedule == "sin decrease":
147+
temperature_adjust_factor = temp_schedule.sin_decrease(mc_count, num_saves)
146148
elif temperature_schedule == "no schedule":
147149
temperature_adjust_factor = temp_schedule.no_schedule()
148150
else:
@@ -153,10 +155,14 @@ def _polymer_in_field(
153155
if lt_schedule is not None:
154156
if lt_schedule == "logarithmic increase":
155157
lt_change = twist_schedule.logarithmic_increase(mc_count, num_saves)
158+
elif lt_schedule == "exponential increase":
159+
lt_change = twist_schedule.exponential_increase(mc_count, num_saves)
156160
elif lt_schedule == "linear increase":
157161
lt_change = twist_schedule.linear_increase(mc_count, num_saves)
158162
elif lt_schedule == "increasing stepwise":
159-
lt_change = twist_schedule.increasing_stepwise(mc_count, num_saves)
163+
lt_change = twist_schedule.step_wise_increase(mc_count, num_saves)
164+
elif lt_schedule == "increasing sawtooth":
165+
lt_change = twist_schedule.increasing_sawtooth(mc_count, num_saves)
160166
elif lt_schedule == "no schedule":
161167
lt_change = twist_schedule.no_schedule()
162168
else:

chromo/mc/mc_sim.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ cpdef void mc_sim(
7676
cdef long i, j, k, n_polymers
7777
cdef list active_fields
7878
cdef poly
79-
#cdef list accept_reject
8079
np.random.seed(random_seed)
8180
if field.confine_type == "":
8281
active_fields = [poly.is_field_active() for poly in polymers]
@@ -166,6 +165,7 @@ cpdef void mc_step(
166165
exp_dE = 1
167166

168167
if (<double>rand() / RAND_MAX) < exp_dE/temperature_adjust_factor: #temperature variation
168+
#print(<double>rand() / RAND_MAX)
169169
adaptible_move.accept(
170170
poly, dE, inds, n_inds, log_move=True, log_update=True
171171
)

chromo/polymers.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,8 +1162,8 @@ cdef class SSWLC(PolymerBase):
11621162

11631163
cdef double bead_pair_dE_poly_forward(
11641164
self,
1165-
double[:] r_0, #posoiton of first bead in move
1166-
double[:] r_1, # position of the escond bead in the move
1165+
double[:] r_0, #positon of first bead in move
1166+
double[:] r_1, # position of the second bead in the move
11671167
double[:] test_r_1,
11681168
double[:] t3_0,
11691169
double[:] t3_1,
@@ -2030,7 +2030,6 @@ cdef class SSTWLC(SSWLC):
20302030
0.5 * self.eps_perp[ind] * vec_dot3(dr_perp, dr_perp) +
20312031
0.5 * self.eps_twist[ind] * omega**2
20322032
)
2033-
#print("does E_pair_with_twist get used")
20342033
return E
20352034

20362035
cdef double bead_pair_dE_poly_forward_with_twist(

chromo/run_simulation.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
controller=ctrl.SimpleControl
112112
)
113113

114-
num_snapshots = 560
114+
num_snapshots = 200
115115
# num_snapshots = 1000 # try 1000 and average for each set of 100, depending on pre-equilibration steps
116116
# count number of accepted moves for different conditions
117117
mc_steps_per_snapshot = 40000
@@ -127,11 +127,10 @@
127127
num_saves = num_snapshots,
128128
bead_amp_bounds = amp_bead_bounds,
129129
move_amp_bounds = amp_move_bounds,
130-
#output_dir = '/scratch/users/ahirsch1', # for running on sherlock
131130
output_dir = 'output',
132131
mc_move_controllers = moves_to_use,
133-
temperature_schedule = "no schedule",
134-
lt_schedule = "linear increase"
132+
temperature_schedule = "logarithmic decrease",
133+
lt_schedule = "no schedule"
135134
)
136135

137136
output_files = os.listdir(latest_sim)

chromo/twist_schedule.py

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import numpy as np
2+
13

24
class Schedule:
35
"""Class representation of the simulated annealing schedule.
@@ -16,25 +18,90 @@ def to_file(self, path):
1618
with open(path, 'w') as f:
1719
f.write(self.name)
1820

19-
def increasing_stepwise(current_step, total_steps):
20-
step_size = (1 - 0.1) / total_steps
21-
value = max(0.1, 1 - step_size * current_step)
2221

23-
return value
22+
# dynamic structure factor
23+
# density correlation function at different length-scales
24+
# fourier transform of density-density correlation function
25+
# how much largest length-scale of polymer is changing
26+
# correlation function of radius of gyration
27+
# how density fluctuation within polymer correlate in time
28+
# plot rmsd for different twist values
29+
30+
2431
def logarithmic_increase(current_step, total_steps):
25-
#value = 5
26-
value = (current_step/total_steps) * 100
27-
return value
32+
if current_step == 0:
33+
return 0
34+
ratio = current_step / total_steps
35+
result = np.log(ratio / 2) / 5.5 * 100 + 113
36+
if result > 100:
37+
result = 100
38+
if result < 0:
39+
result = 0
40+
return result
2841

42+
def exponential_increase(current_step, total_steps):
43+
result = np.exp(current_step/total_steps) * 58
44+
return result - 58
45+
# for lp
2946
def linear_increase(current_step, total_steps):
30-
value = (current_step/total_steps) * 100
47+
max_value = 100
48+
slope = max_value / total_steps
49+
value = slope * current_step
3150
return value
51+
52+
53+
# for lp
54+
def step_wise_increase(current_step, total_steps):
55+
num_blocks = 25
56+
max_height = 100
57+
step_height = max_height / num_blocks # each step has a height of 10
58+
step_length = total_steps / num_blocks # so 20 is the length
59+
division = current_step / step_length # so if we are at snapshot 105 we get 5.11
60+
ceiling = np.ceil(division) # we are currently on the 6th step
61+
result = step_height * ceiling
62+
return result
63+
64+
65+
def increasing_sawtooth(current_step, total_steps):
66+
num_blocks = 10
67+
max_height = 100
68+
step_height = max_height / num_blocks # each step has a height of 10
69+
step_length = total_steps / num_blocks # so 20 is the length
70+
division = current_step / step_length # so if we are at snapshot 105 we get 5.11
71+
ceiling = np.ceil(division) # we are currently on the 6th step
72+
result = step_height * ceiling # this is the height we are at in the 6th block
73+
74+
num_sections = num_blocks * 2 # if we are at 105
75+
section_division = np.floor(
76+
current_step / (total_steps / num_sections)) # 10.5 is the section from 20 total sections
77+
if section_division % 2 == 0:
78+
result = result + (current_step % num_sections) * 4 - section_division - 14
79+
else:
80+
result = result - (current_step % num_sections) * 2.5 - section_division + 46
81+
if ceiling == num_blocks and section_division % 2 != 0:
82+
result = max_height
83+
if result > max_height:
84+
result = max_height
85+
if result < 0:
86+
result = 0
87+
return result
88+
89+
def increasing_sawtooth(current_step, total_steps):
90+
num_blocks = 10
91+
max_height = 100
92+
step_height = max_height/num_blocks # each step has a height of 10
93+
step_length = total_steps / num_blocks # so 20 is the length
94+
division = current_step/step_length # so if we are at snapshot 105 we get 5.11
95+
ceiling = np.ceil(division) # we are currently on the 6th step
96+
result = step_height * ceiling # this is the height we are at in the 6th block
97+
98+
num_sections = num_blocks * 2 #if we are at 105
99+
section_division = np.floor(current_step/(total_steps/num_sections)) # 10.5 is the section from 20 total sections
100+
if section_division%2 == 0:
101+
result = result + (current_step % num_sections) * 2 - section_division - 20
102+
else:
103+
result = result - (current_step%num_sections)*2 - section_division + 20
104+
return result
105+
32106
def no_schedule():
33107
return 100
34-
#dynamic structure factor
35-
#density correlation function at differnet lengthscales
36-
#fouirer transform of density density correlation function
37-
#how much largest lengthscale of polymer is changing
38-
#correleation function of radius of gyration
39-
#how density fluctluation within polymer correlate in time
40-
#plot rmsd for different twist values

chromo/util/mc_stat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def create_log_file(self, ind: int):
100100
Index with which to append log file name
101101
"""
102102
log_path = self.log_dir+"/"+self.log_file_prefix+str(ind)+".csv"
103-
print("log dir in mc_stat "+str(self.log_dir))
104-
print("prefix in mcstat " + str(self.log_file_prefix))
103+
#print("log dir in mc_stat "+str(self.log_dir))
104+
#print("prefix in mcstat " + str(self.log_file_prefix))
105105
column_labels = [
106106
"snapshot",
107107
"iteration",

chromo/util/temperature_schedule.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,34 @@ def to_file(self, path):
1818
with open(path, 'w') as f:
1919
f.write(self.name)
2020

21+
def sin_decrease(current_step, total_steps):
22+
slope = (-1.3) / total_steps
23+
linear_value = 1 + slope * current_step
24+
result = np.sin(current_step/total_steps *100)
25+
result = result *.1 + linear_value *.6 +.32
26+
if result > 1:
27+
result = 1
28+
if result < 0.1:
29+
result = 0.1
30+
return result * 10
31+
2132

2233
def decreasing_stepwise(current_step, total_steps):
23-
step_size = (1 - 0.1) / total_steps
24-
value = max(0.1, 1 - step_size * current_step)
34+
raw_fraction = 1 - current_step/(total_steps + 150)
35+
fraction = raw_fraction * 10
36+
step_fraction = np.floor(fraction)/10
37+
return step_fraction
2538

26-
return value
2739
def logarithmic_decrease(current_step, total_steps):
28-
value = 1 - (0.9 ** (current_step / total_steps))
29-
return value
40+
if current_step == 0:
41+
return 1
42+
ratio = current_step/total_steps
43+
result = -1 * np.log(ratio/2)/5.5 -0.1
44+
if result > 1:
45+
result = 1
46+
if result < 0:
47+
result = 0
48+
return result * 10
3049

3150
def linear_decrease(current_step, total_steps):
3251
slope = (0.1 - 1) / total_steps

0 commit comments

Comments
 (0)