Skip to content

Commit

Permalink
Extend the ASE converter to support other trajectory formats
Browse files Browse the repository at this point in the history
  • Loading branch information
MBartkowiakSTFC committed Jan 23, 2024
1 parent 7268a67 commit f348b31
Show file tree
Hide file tree
Showing 3 changed files with 995 additions and 5 deletions.
22 changes: 17 additions & 5 deletions MDANSE/Src/MDANSE/Framework/Converters/ASE.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def initialize(self):
self._start = 0

if self.numberOfSteps < 1:
self.numberOfSteps = len(self._input)
self.numberOfSteps = self._total_number_of_steps

# A trajectory is opened for writing.
self._trajectory = TrajectoryWriter(
Expand All @@ -112,7 +112,7 @@ def initialize(self):
[(at.name, at.index) for at in self._trajectory.chemical_system.atom_list]
)

print(f"total steps: self.numberOfSteps")
print(f"total steps: {self.numberOfSteps}")

def run_step(self, index):
"""Runs a single step of the job.
Expand All @@ -123,7 +123,10 @@ def run_step(self, index):
@note: the argument index is the index of the loop note the index of the frame.
"""

frame = self._input[index]
try:
frame = self._input[index]
except TypeError:
frame = read(self.configuration["trajectory_file"]["value"], index=index)
time = self._timeaxis[index]

unitCell = frame.cell.array
Expand Down Expand Up @@ -183,9 +186,18 @@ def parse_first_step(self):
self._input = iread(
self.configuration["trajectory_file"]["value"], index="[:]"
)
first_frame = read(self.configuration["trajectory_file"]["value"], index=0)
last_iterator = 0
generator = iread(self.configuration["trajectory_file"]["value"])
for _ in generator:
last_iterator += 1
generator.close()
self._total_number_of_steps = last_iterator
else:
first_frame = self._input[0]
self._total_number_of_steps = len(self._input)

first_frame = self._input[0]
self._timeaxis = self._timestep * np.arange(len(self._input))
self._timeaxis = self._timestep * np.arange(self._total_number_of_steps)

self._fractionalCoordinates = np.all(first_frame.get_pbc())

Expand Down
Loading

0 comments on commit f348b31

Please sign in to comment.