Read and Save file
mdapy can read/save file very efficiently. Including Dump, Data and Dump.gz formats.
The performance of mdapy is around 2-7 times higher than ovito.
[11]:
import mdapy as mp
from time import time
import matplotlib.pyplot as plt
mp.init()
[Taichi] Starting on arch=x64
[12]:
mp.__version__
[12]:
'0.9.9'
[13]:
import ovito
ovito.version
[13]:
(3, 9, 2)
Prepare a Data, Dump, Dump.gz files
[14]:
def prepare():
FCC = mp.LatticeMaker(3.615, 'FCC', 100, 100, 100)
FCC.compute()
print(f'Atom number is {FCC.N}.')
print('Saving to mdapy.data.')
FCC.write_data(output_name='mdapy.data')
print('Saving to mdapy.dump')
FCC.write_dump(output_name='mdapy.dump')
print('Saving to mdapy.dump.gz')
FCC.write_dump(output_name='mdapy.dump.gz', compress=True)
return FCC.N
[15]:
N = prepare()
Atom number is 4000000.
Saving to mdapy.data.
Saving to mdapy.dump
Saving to mdapy.dump.gz
Read a dump file in mdapy
[16]:
start = time()
for _ in range(3):
_ = mp.System('mdapy.dump')
end = time()
mdapy_time = (end - start)/3
print(mdapy_time, 's')
0.22403152783711752 s
Read a dump file in OVITO
[17]:
start = time()
for _ in range(3):
_ = ovito.io.import_file('mdapy.dump')
end = time()
ovito_time = (end - start)/3
print(ovito_time, 's')
1.1576457023620605 s
[18]:
fig, _ = mp.set_figure(figsize=(10, 6), use_pltset=True)
plt.bar([0, 1], [mdapy_time, ovito_time])
plt.xticks([0, 1], ['mdapy', 'ovito'])
plt.ylabel('Time (s)')
plt.title(f'Read dump with {N} atoms.')
[18]:
Text(0.5, 1.0, 'Read dump with 4000000 atoms.')
Read a data file in mdapy
[19]:
start = time()
for _ in range(3):
_ = mp.System('mdapy.data')
end = time()
mdapy_time = (end - start)/3
print(mdapy_time, 's')
0.6062424182891846 s
Read a data file in ovito
[20]:
start = time()
for _ in range(3):
_ = ovito.io.import_file('mdapy.data')
end = time()
ovito_time = (end - start)/3
print(ovito_time, 's')
2.51231058438619 s
[21]:
fig, _ = mp.set_figure(figsize=(10, 6), use_pltset=True)
plt.bar([0, 1], [mdapy_time, ovito_time])
plt.xticks([0, 1], ['mdapy', 'ovito'])
plt.ylabel('Time (s)')
plt.title(f'Read data with {N} atoms.')
[21]:
Text(0.5, 1.0, 'Read data with 4000000 atoms.')
Read a dump.gz file in mdapy
[22]:
start = time()
for _ in range(3):
_ = mp.System('mdapy.dump.gz')
end = time()
mdapy_time = (end - start)/3
print(mdapy_time, 's')
0.6917309761047363 s
Read a dump.gz file in ovito
[23]:
start = time()
for _ in range(3):
_ = ovito.io.import_file('mdapy.dump.gz')
end = time()
ovito_time = (end - start)/3
print(ovito_time, 's')
1.7169297536214192 s
[24]:
fig, _ = mp.set_figure(figsize=(10, 6), use_pltset=True)
plt.bar([0, 1], [mdapy_time, ovito_time])
plt.xticks([0, 1], ['mdapy', 'ovito'])
plt.ylabel('Time (s)')
plt.title(f'Read dump.gz with {N} atoms.')
[24]:
Text(0.5, 1.0, 'Read dump.gz with 4000000 atoms.')
Save a dump file in mdapy
[25]:
system = mp.System('mdapy.dump')
start = time()
for _ in range(3):
system.write_dump()
end = time()
mdapy_time = (end - start)/3
print(mdapy_time, 's')
0.6115530331929525 s
Save a dump file in OVITO
[26]:
pipeline = ovito.io.import_file('mdapy.dump')
start = time()
for _ in range(3):
ovito.io.export_file(pipeline, 'ovito.dump', format='lammps/dump', columns=["Particle Identifier", "Particle Type", "Position.X", "Position.Y", "Position.Z"])
end = time()
ovito_time = (end - start)/3
print(ovito_time, 's')
4.530352512995402 s
[27]:
fig, _ = mp.set_figure(figsize=(10, 6), use_pltset=True)
plt.bar([0, 1], [mdapy_time, ovito_time])
plt.xticks([0, 1], ['mdapy', 'ovito'])
plt.ylabel('Time (s)')
plt.title(f'Save dump with {N} atoms.')
[27]:
Text(0.5, 1.0, 'Save dump with 4000000 atoms.')
Save a data file in mdapy
[28]:
start = time()
for _ in range(3):
system.write_data()
end = time()
mdapy_time = (end - start)/3
print(mdapy_time, 's')
0.5885759989420573 s
Save a data file in ovito
[29]:
start = time()
for _ in range(3):
ovito.io.export_file(pipeline, 'ovito.data', format='lammps/data', atom_style='atomic')
end = time()
ovito_time = (end - start)/3
print(ovito_time, 's')
4.610602299372355 s
[30]:
fig, _ = mp.set_figure(figsize=(10, 6), use_pltset=True)
plt.bar([0, 1], [mdapy_time, ovito_time])
plt.xticks([0, 1], ['mdapy', 'ovito'])
plt.ylabel('Time (s)')
plt.title(f'Save data with {N} atoms.')
[30]:
Text(0.5, 1.0, 'Save data with 4000000 atoms.')
Save a dump.gz file in mdapy
[31]:
start = time()
for _ in range(3):
system.write_dump(compress=True)
end = time()
mdapy_time = (end - start)/3
print(mdapy_time, 's')
1.5111037890116374 s
Save a dump.gz file in ovito
[32]:
start = time()
for _ in range(3):
ovito.io.export_file(pipeline, 'ovito.dump.gz', format='lammps/dump', columns=["Particle Identifier", "Particle Type", "Position.X", "Position.Y", "Position.Z"])
end = time()
ovito_time = (end - start)/3
print(ovito_time, 's')
10.900876919428507 s
[33]:
fig, _ = mp.set_figure(figsize=(10, 6), use_pltset=True)
plt.bar([0, 1], [mdapy_time, ovito_time])
plt.xticks([0, 1], ['mdapy', 'ovito'])
plt.ylabel('Time (s)')
plt.title(f'Save dump.gz with {N} atoms.')
[33]:
Text(0.5, 1.0, 'Save dump.gz with 4000000 atoms.')
[34]:
# Clear the output
import os
from glob import glob
file_list = glob('*dump*') + glob("*.data")
for file in file_list:
try:
os.remove(file)
except Exception:
pass