Author Topic: How to export last position of the atoms in python script?  (Read 128 times)

dark_knight

  • Newbie
  • *
  • Posts: 2
How to export last position of the atoms in python script?
« on: April 22, 2018, 10:18:35 PM »
i have a dump file containing 35 time-steps and a reference file for W-S modifier. i created a script to have the defect positions just for the last time step *here # 35) but in output i receive no positions (0 atom). it seems that the first time-step is just considered for Export_data. here is my code:

Code: [Select]
    node = import_file("address",multiple_frames = True)
    mod = WignerSeitzAnalysisModifier()
    mod.reference.load("address")
    node.modifiers.append(mod)
    node.modifiers.append(SelectExpressionModifier(expression ='Occupancy==0&&ParticleType==1'))
    node.compute()
    print("Occupancy = %i" %node.output.attributes['SelectExpression.num_selected'])
    node.modifiers.append(InvertSelectionModifier())
    node.compute()
    node.modifiers.append(DeleteSelectedParticlesModifier())
    node.compute()
    export_file(node, "positions.txt", "lammps_dump", columns=
    ["Particle Identifier", "Particle Type", "Position.X", "Position.Y", "Position.Z"]
    )
what is wrong? another question:how can i export a specific time-step (not the first one, for example just time-step 5) to a txt file?
« Last Edit: April 24, 2018, 09:04:02 AM by Alexander Stukowski »

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 406
Re: How to export last position of the atoms in python script?
« Reply #1 on: April 24, 2018, 09:10:21 AM »
Hi Mehrdad,

As described in the docs for the export_file() function, you need to use the multiple_frames flag:
Code: [Select]
export_file(node, "positions.txt", "lammps_dump", columns=["Particle Identifier", "Particle Type", "Position.X", "Position.Y", "Position.Z"], multiple_frames=True)
Note that this writes a single dump file containing all output frames. If you use a * in the filename, you can also write a sequence of files, one for each frame.

If you want to export just one specific frame, use the frame keyword option, which is also mentioned in the docs of export_file().

-Alex

dark_knight

  • Newbie
  • *
  • Posts: 2
Re: How to export last position of the atoms in python script?
« Reply #2 on: April 24, 2018, 05:22:15 PM »
Hi dear Alexander
I appreciate your answering. That works great! Actually, i forgot this point(* and multiple frame syntax). However, "particle_properties.position.array" is also a good approach that i used, because in Ovito version 2.7 (that is the latter version of 32 bit) i could not use export_file (code begins to run but nothing happen, it sounds like repeating a infinite loop). This despite the fact that the code works without problem in Ovito 2.9.
Yours sincerely
Mehrdad