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.

[1]:
import mdapy as mp
from time import time
import matplotlib.pyplot as plt
mp.init()
[Taichi] version 1.7.1, llvm 15.0.1, commit 0f143b2f, win, python 3.10.14
[Taichi] Starting on arch=x64
[2]:
mp.__version__
[2]:
'0.10.9'
[3]:
import ovito
ovito.version
[3]:
(3, 10, 4)

Prepare a Data, Dump, Dump.gz files

[4]:
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
[5]:
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

[6]:
start = time()
for _ in range(3):
    _ = mp.System('mdapy.dump')
end = time()
mdapy_time = (end - start)/3
print(mdapy_time, 's')
0.09816320737202962 s

Read a dump file in OVITO

[7]:
start = time()
for _ in range(3):
    _ = ovito.io.import_file('mdapy.dump')
end = time()
ovito_time = (end - start)/3
print(ovito_time, 's')
0.4527897040049235 s
[8]:
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.')
[8]:
Text(0.5, 1.0, 'Read dump with 4000000 atoms.')
../_images/gettingstarted_reading_and_saving_file_12_1.png

Read a data file in mdapy

[9]:
start = time()
for _ in range(3):
    _ = mp.System('mdapy.data')
end = time()
mdapy_time = (end - start)/3
print(mdapy_time, 's')
0.31754382451375324 s

Read a data file in ovito

[10]:
start = time()
for _ in range(3):
    _ = ovito.io.import_file('mdapy.data')
end = time()
ovito_time = (end - start)/3
print(ovito_time, 's')
1.372974157333374 s
[11]:
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.')
[11]:
Text(0.5, 1.0, 'Read data with 4000000 atoms.')
../_images/gettingstarted_reading_and_saving_file_17_1.png

Read a dump.gz file in mdapy

[12]:
start = time()
for _ in range(3):
    _ = mp.System('mdapy.dump.gz')
end = time()
mdapy_time = (end - start)/3
print(mdapy_time, 's')
0.25611209869384766 s

Read a dump.gz file in ovito

[13]:
start = time()
for _ in range(3):
    _ = ovito.io.import_file('mdapy.dump.gz')
end = time()
ovito_time = (end - start)/3
print(ovito_time, 's')
0.6650396188100179 s
[14]:
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.')
[14]:
Text(0.5, 1.0, 'Read dump.gz with 4000000 atoms.')
../_images/gettingstarted_reading_and_saving_file_22_1.png

Save a dump file in mdapy

[15]:
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.13341426849365234 s

Save a dump file in OVITO

[16]:
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')
2.2548699378967285 s
[17]:
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.')
[17]:
Text(0.5, 1.0, 'Save dump with 4000000 atoms.')
../_images/gettingstarted_reading_and_saving_file_27_1.png

Save a data file in mdapy

[18]:
start = time()
for _ in range(3):
    system.write_data()
end = time()
mdapy_time = (end - start)/3
print(mdapy_time, 's')
0.13344637552897134 s

Save a data file in ovito

[19]:
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')
2.232410430908203 s
[20]:
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.')
[20]:
Text(0.5, 1.0, 'Save data with 4000000 atoms.')
../_images/gettingstarted_reading_and_saving_file_32_1.png

Save a dump.gz file in mdapy

[21]:
start = time()
for _ in range(3):
    system.write_dump(compress=True)
end = time()
mdapy_time = (end - start)/3
print(mdapy_time, 's')
0.7206652959187826 s

Save a dump.gz file in ovito

[22]:
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')
4.918222665786743 s
[23]:
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.')
[23]:
Text(0.5, 1.0, 'Save dump.gz with 4000000 atoms.')
../_images/gettingstarted_reading_and_saving_file_37_1.png
[24]:
# 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