Skip to content

Commit b984e42

Browse files
committed
still working on paths
1 parent 241032d commit b984e42

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

src/msad.jl

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,18 @@ MSADState{T}() where {T} = MSADState{T}([], [], [], [], [], false)
8383
########## ##########
8484

8585
mutable struct MSADTracker{T} <: AriannaAlgorithm
86-
states::Vector{MSADState{T}} # the states of the considered chain
87-
theta_T::T # threshold angle in radians
88-
compute_schedule::Vector{Int} # schedule for computing rotation for integral and threshold methods
89-
output_schedule::Vector{Int} # schedule for writing MSAD to disk
90-
path::Vector{String} # paths to store files
91-
files_integral::Vector{IOStream} # file to write rotation vector in integral method
92-
files_thresh::Vector{IOStream} # file to write rotation vector in threshold method
86+
states::Vector{MSADState{T}}
87+
theta_T::T
88+
compute_schedule::Vector{Int}
89+
output_schedule::Vector{Int}
90+
paths_integral::Vector{String}
91+
paths_thresh::Vector{String}
92+
files_integral::Vector{IOStream}
93+
files_thresh::Vector{IOStream}
9394
end
9495

9596
function MSADTracker(chains;
96-
theta_T::Float64,
97+
theta_T::Float64=π/4,
9798
output_schedule::Vector{Int}=Int[],
9899
path::String=".",
99100
scheduler::Vector{Int}=Int[],
@@ -110,12 +111,16 @@ function MSADTracker(chains;
110111

111112
n = length(chains)
112113
states = [MSADState{Float64}() for _ in 1:n]
114+
dirs = [joinpath(path, "chains", "$c") for c in 1:n]
115+
116+
paths_integral = [joinpath(d, "phi_integral.dat") for d in dirs]
117+
paths_thresh = [joinpath(d, "phi_thresh.dat") for d in dirs]
113118

114119
files_integral = Vector{IOStream}(undef, n)
115120
files_thresh = Vector{IOStream}(undef, n)
116121

117122
return MSADTracker{Float64}(states, theta_T, compute_schedule,
118-
output_schedule, path,
123+
output_schedule, paths_integral, paths_thresh,
119124
files_integral, files_thresh)
120125
end
121126

@@ -124,14 +129,14 @@ end
124129

125130
function write_phi_frame(file::IOStream, t::Int, N_mol::Int,
126131
phis::Vector{<:SVector})
132+
println(file, N_mol)
127133
println(file, "t=$t")
128134
for m in 1:N_mol
129135
println(file, "$m $(phis[m][1]) $(phis[m][2]) $(phis[m][3])")
130136
end
131137
flush(file)
132138
end
133139

134-
135140
##### Initialisation of the simulation #####
136141
# called once at t = 0, set the system, the mutable struct and the storing paths
137142
########## ##########
@@ -141,36 +146,36 @@ function Arianna.initialise(algorithm::MSADTracker, simulation::Simulation)
141146
for c in eachindex(simulation.chains)
142147
system = simulation.chains[c]
143148
state = algorithm.states[c]
144-
T = typeof(system.temperature) # get the float type from system so one can choose Float64 or 32 (generic)
149+
T = typeof(system.temperature)
145150

146151
# create output directory if it doesn't exist
147-
dir = joinpath(algrithm.path, "chains", "$c")
148-
mkpath(dir)
152+
mkpath(dirname(algorithm.paths_integral[c]))
149153

150-
# open output file — write header
151-
algorithm.files_integral[c] = open(joinpath(dir, "phi_integral.dat"), "w")
152-
algorithm.files_thresh[c] = open(joinpath(dir, "phi_thresh.dat"), "w")
154+
# open output files
155+
algorithm.files_integral[c] = open(algorithm.paths_integral[c], "w")
156+
algorithm.files_thresh[c] = open(algorithm.paths_thresh[c], "w")
153157

154158
# compute initial body frames
155159
R_all = get_all_body_frames(system)
156160
N_mol = system.Nmol
157161

158-
# fill state, copy. so they are different pointers!
162+
# fill state
159163
state.R0 = copy(R_all)
160164
state.R_prev = copy(R_all)
161165
state.phi_integral = [zero(SVector{3,T}) for _ in 1:N_mol]
162166
state.R_ref_thresh = copy(R_all)
163167
state.phi_acc = [zero(SVector{3,T}) for _ in 1:N_mol]
164168
state.initialized = true
165169

166-
# write t=0, all phi vectors
167-
write_phi_frame(algorithm.files_integral[c],0,N_mol,state.phi_integral)
168-
write_phi_frame(algorithm.files_thres[c],0,N_mol,state.phi_thresh)
170+
# write t=0, all phi vectors are zero
171+
write_phi_frame(algorithm.files_integral[c], 0, N_mol,
172+
state.phi_integral)
173+
write_phi_frame(algorithm.files_thresh[c], 0, N_mol,
174+
[zero(SVector{3,T}) for _ in 1:N_mol])
169175
end
170-
171176
end
172177

173-
##### Finalise th simulation #####
178+
##### Finalise the simulation #####
174179
# close output to not keep unwritten data in memory
175180
########## ##########
176181

@@ -180,7 +185,6 @@ function Arianna.finalise(tracker::MSADTracker, ::Simulation)
180185
close(tracker.files_thresh[c])
181186
end
182187
end
183-
184188
##### Make a step in simulation #####
185189
########## ##########
186190

0 commit comments

Comments
 (0)