Skip to content

Commit

Permalink
support input without pdb file
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Sep 30, 2023
1 parent 5033358 commit 9e9f748
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/datastructures/Simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function show(io::IO, simulation::Simulation)
print(io, chomp("""
Simulation
Atom type: $(eltype(simulation.atoms))
PDB file: $(isnothing(simululation.pdb_file) ? "Nothin" : path_pdb(simulation))
PDB file: $(isnothing(simulation.pdb_file) ? "-" : path_pdb(simulation))
Trajectory file: $(path_trajectory(simulation))
Total number of frames: $(length(simulation))
Frame range: $(frame_range(simulation))
Expand Down Expand Up @@ -156,7 +156,7 @@ function Simulation(
frame = Chemfiles.read(trajectory)
read_lock = ReentrantLock()
frame_index = nothing
simulation = Simulation{AtomType}(pdb_file, atoms, frame_range, frame, frame_index, trajectory, read_lock)
simulation = Simulation(pdb_file, atoms, frame_range, frame, frame_index, trajectory, read_lock)
restart!(simulation)
return simulation
end
Expand Down Expand Up @@ -234,15 +234,15 @@ atoms(simulation::Simulation) = simulation.atoms
Returns the path to the pdb file of the simulation.
"""
path_pdb(simulation::Simulation) = simulation.pdb_file
path_pdb(simulation::Simulation) = isnothing(simulation.pdb_file) ? nothing : normpath(simulation.pdb_file)

"""
path_trajectory(simulation::Simulation)
Returns the path to the trajectory file of the simulation.
"""
path_trajectory(simulation::Simulation) = Chemfiles.path(simulation.trajectory)
path_trajectory(simulation::Simulation) = normpath(Chemfiles.path(simulation.trajectory))

"""
restart!(simulation::Simulation)
Expand Down Expand Up @@ -358,7 +358,7 @@ function set_frame_range!(simulation::Simulation; first=1, last=nothing, step=1)
restart!(simulation)
end

@testitem "Trajectory" begin
@testitem "Simulation" begin
import Chemfiles
using MolSimToolkit.Testing

Expand All @@ -384,8 +384,15 @@ end
push!(c2, positions(frame)[1].x)
end
close(simulation)

@test c == c2
end

@testitem "no-pdb construct" begin
import PDBTools
using MolSimToolkit.Testing
pdb = PDBTools.readPDB(Testing.namd_pdb)
simulation = Simulation(pdb, Testing.namd_traj)
@test positions(current_frame(simulation))[1].x == 5.912472724914551
@test isnothing(path_pdb(simulation))
end

0 comments on commit 9e9f748

Please sign in to comment.