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.0, llvm 15.0.1, commit 2fd24490, win, python 3.10.12
[Taichi] Starting on arch=x64
[2]:
mp.__version__
[2]:
'0.10.0'
[3]:
import ovito
ovito.version
[3]:
(3, 9, 2)

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.4905485312143962 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')
1.1865103244781494 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.6108060677846273 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')
2.593879063924154 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.6597364743550619 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')
1.727571725845337 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.7459139823913574 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')
4.843591292699178 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.5471723079681396 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')
4.687552769978841 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')
1.5231714248657227 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')
11.050355037053427 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