Author Topic: Problem about using export_file  (Read 42 times)

kaizhao

  • Newbie
  • *
  • Posts: 2
Problem about using export_file
« on: March 12, 2019, 11:35:16 AM »
Dear all,

I am trying to output the atom coordinates of selected group, and store them into .txt files labeled by time frames. However, it always fails to write these .txt files into the same path of import_file command.

Code: [Select]
# Import OVITO modules.
from ovito import dataset
from ovito.io import import_file, export_file
from ovito.modifiers import *
from ovito.data import *

# Import standard Python and NumPy modules.
import sys
import numpy
import os

# Load input data and create an ObjectNode with a data pipeline.
os.chdir("U:\\")
node = import_file('./r1/my_lammps.dump', multiple_frames = True)
# Select tip atoms (ParticleType = 1)
node.modifiers.append(SelectParticleTypeModifier(property='Particle Type', types={2, 3}))
node.modifiers.append(DeleteSelectedParticlesModifier())

# Export calculated contacted atoms to a text file and let OVITO's data pipeline do the rest:
export_file(node, "substrate.r1.*.txt", "xyz", columns = ["Position.X", "Position.Y"], multiple_frames=True)

Now the substrate.r1.*.txt files are output in the root path of U:\\
However, if I write it as "./r1/substrate.r1.*.txt" in the last sentence, there will be an error like cannot find the path "U:/r1/./r1/substrate.r1.0.txt".

Can you guys kindly help me to solve this problem?

Best regards,
Kai
« Last Edit: March 15, 2019, 09:37:01 AM by Alexander Stukowski »

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 208
Re: Problem about using export_file
« Reply #1 on: March 12, 2019, 11:46:34 AM »
Dear Kai,

what's the operating system that you're using? Also could you please copy and paste the exact error message here.

-Constanze
« Last Edit: March 12, 2019, 12:12:32 PM by Constanze Kalcher »

kaizhao

  • Newbie
  • *
  • Posts: 2
Re: Problem about using export_file
« Reply #2 on: March 12, 2019, 12:56:26 PM »
Dear Constanze,

Thank you for your swift reply  :)

I am playing with simple 2D LJ system, and using OVITO in Windows10.

And surprisingly, it works now if I write as:

Code: [Select]
os.chdir("U:\\")
node = import_file("./r1/my_lammps.dump", multiple_frames = True)
# Select tip atoms (ParticleType = 1)
node.modifiers.append(SelectParticleTypeModifier(property='Particle Type', types={2, 3}))
node.modifiers.append(DeleteSelectedParticlesModifier())

# Export calculated contacted atoms to a text file and let OVITO's data pipeline do the rest:
export_file(node, "/r1/substrate.*.txt",
            format = "xyz",
            columns = ["Position.X", "Position.Y"],
            multiple_frames=True)

I do not know whether it has influence, if I change ' into " in the command sentence.
Perhaps the error also origins from the wrong writing "./r1/substrate.*.txt" in the export_file command.
It means that ./ and / lead to different results in the execution.

Best regards,
Kai

« Last Edit: March 15, 2019, 09:37:19 AM by Alexander Stukowski »