Skip to content

Commit

Permalink
Moved some relevant examples to a better place
Browse files Browse the repository at this point in the history
Added more consistent extras_component_raw() in a way that doesn't break
stuff (although it's not super-consistent with everything else)
  • Loading branch information
ceriottm committed Apr 22, 2024
1 parent 831209e commit 1ad4fd2
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<trajectory filename='for' format='xyz' stride='2'> forces </trajectory>
<trajectory filename='kin' format='xyz' stride='2'> kinetic_cv </trajectory>
<trajectory filename='dip' stride='2' extra_type='dipole'> extras </trajectory>
<!-- these two output the extras for the contracted beads -->
<trajectory filename='dip_raw' stride='2' extra_type='dipole'> extras_component_raw(0) </trajectory>
<checkpoint stride='100' filename='chk' overwrite='true'/>
<checkpoint stride='2000' filename='restart' overwrite='false'/>
</output>
Expand Down
1 change: 0 additions & 1 deletion ipi/engine/forces.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,6 @@ def extras_component(self, index):
Does not attempt to apply weights or interpolate, always returns raw stuff.
"""

print("accessing extras ", self.mforces[index].extras)
return self.mforces[index].extras

def forcesvirs_4th_order(self, index):
Expand Down
30 changes: 23 additions & 7 deletions ipi/engine/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def open_stream(self, mode):
"velocities",
"forces",
"extras",
"extras_component_raw",
# "extras_component_raw", write out a single file as we don't know how to do contraction here
"extras_bias",
"forces_sc",
"momenta",
Expand All @@ -368,7 +368,10 @@ def open_stream(self, mode):
self.out.append(None)
else:
# open one file
filename = self.filename + "." + self.format
filename = self.filename
# prepare format string for file name
if getkey(self.what)[:6] != "extras":
filename += "." + self.format
self.out = open_backup(filename, mode)

def close_stream(self):
Expand Down Expand Up @@ -479,13 +482,26 @@ def write_traj(

key = getkey(what)
if key in ["extras", "extras_component_raw", "extras_bias"]:
stream.write(
" #%s(%s)# Step: %10d Bead: %5d \n"
% (key.upper(), self.extra_type, self.system.simul.step + 1, b)
)
if key == "extras_component_raw":
stream.write(
" #%s(%s)# Step: %10d Bead: %5d \n"
% (key.upper(), self.extra_type, self.system.simul.step + 1, b)
)
else:
stream.write(
" #%s(%s)# Step: %10d \n"
% (key.upper(), self.extra_type, self.system.simul.step + 1)
)
if self.extra_type in data:
try:
floatarray = np.asarray(data[self.extra_type][b], dtype=float)
if key == "extras_component_raw":
# don't partition into beads as there might be a different number when contracting
floatarray = np.asarray(
data[self.extra_type], dtype=float
).squeeze()
else:
# picks up the desired bead
floatarray = np.asarray(data[self.extra_type][b], dtype=float)
if floatarray.ndim == 2:
stream.write(
"\n".join(
Expand Down
6 changes: 4 additions & 2 deletions ipi/engine/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -2872,8 +2872,10 @@ def __init__(self):
"help": """The additional data returned by the client code, printed verbatim or expanded
as a dictionary. See "extras".
Fetches the extras from a specific force component, indicated in parentheses
[extras_component_raw(idx)]. Never applies weighting or contraction""",
"func": (lambda idx: self.system.forces.extras_component(int(idx))),
and a specific bead [extras_component_raw(idx; bead=0)].
Never applies weighting or contraction, and does not automatically sum
over beads as we don't know if the extras are numeric""",
"func": (lambda idx: (self.system.forces.extras_component(int(idx)))),
},
"extras_bias": {
"help": """The additional data returned by the bias forcefield, printed verbatim or expanded as a dictionary. See "extras". """,
Expand Down

0 comments on commit 1ad4fd2

Please sign in to comment.