Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not saved the atom after optimization #39

Open
kianpu34593 opened this issue May 24, 2024 · 3 comments
Open

can not saved the atom after optimization #39

kianpu34593 opened this issue May 24, 2024 · 3 comments

Comments

@kianpu34593
Copy link
Collaborator

Hi,

I was using image_array with optimize.

The optimization happened smoothly but at the last step it cannot save the optimized atoms to xyz file. Now, I temporarily change it to save as .traj file and it works.

image_file = 'image_output.xyz'
atoms.write(image_file, format='extxyz')

Here is the sim_input.yaml:

asimmodule: workflows.image_array
workdir: FeF2_CuF2/FeF2_subs_Cu_chgnet_relax
args:
  images:
    image_file: /home/kianpu/projects/afx/solid_solution/FeF2_CuF2/FeF2_subs_Cu/FeF2_222_subs_Cu.db
    index: 0
  subsim_input:
    asimmodule: geometry_optimization.optimize
    env_id: inline
    args:
      optimizer: BFGS
      optimizer_args: {}
      expcellfilter_args:
        mask: null
        hydrostatic_strain: false
        constant_volume: false
        scalar_pressure: 0.0
      fmax: 0.01
      calc_id: CHGNet_cpu
      image: 

Here is the stderr.txt:

/home/kianpu/softwares/asimtools/asimtools/asimmodules/geometry_optimization/optimize.py:46: FutureWarning: Import ExpCellFilter from ase.filters
  ecf = ExpCellFilter(atoms, **expcellfilter_args)
Traceback (most recent call last):
  File "/home/kianpu/.spack/opt/spack/gcc-10.3.0/miniconda3/22.11.1-6p6o/envs/asimtools/bin/asim-run", line 33, in <module>
    sys.exit(load_entry_point('asimtools', 'console_scripts', 'asim-run')())
  File "/home/kianpu/softwares/asimtools/asimtools/scripts/asim_run.py", line 137, in main
    results = sim_func(**sim_input.get('args', {}))
  File "/home/kianpu/softwares/asimtools/asimtools/asimmodules/geometry_optimization/optimize.py", line 64, in optimize
    atoms.write(image_file, format='extxyz')
  File "/home/kianpu/softwares/ase/ase/atoms.py", line 2012, in write
    write(filename, self, format, **kwargs)
  File "/home/kianpu/softwares/ase/ase/io/formats.py", line 692, in write
    return _write(filename, fd, format, io, images,
  File "/home/kianpu/softwares/ase/ase/parallel.py", line 271, in new_func
    return func(*args, **kwargs)
  File "/home/kianpu/softwares/ase/ase/io/formats.py", line 728, in _write
    return io.write(fd, images, **kwargs)
  File "/home/kianpu/softwares/ase/ase/io/formats.py", line 193, in _write_wrapper
    return function(*args, **kwargs)
  File "/home/kianpu/softwares/ase/ase/utils/__init__.py", line 577, in iofunc
    obj = func(fd, *args, **kwargs)
  File "/home/kianpu/softwares/ase/ase/io/extxyz.py", line 930, in write_xyz
    data[column] = np.squeeze(value)
ValueError: could not broadcast input array from shape (64,) into shape (48,)
@mkphuthi
Copy link
Collaborator

Is this also after you updated ASE to the latest development branch? We'd need to figure out the source of this error before changing formats. What is the property that can't be written to xyz?

@hancheng2000
Copy link
Collaborator

hancheng2000 commented May 27, 2024

I am using chgnet as well and I have been running into the same problem. I think the problem originates in chgnet saving the model features in atoms.arrays, which is not guaranteed to be in the same shape as len(atoms). In ase.extxyz.write_xyz, the property columns to save in xyz files are specified by the following codes:

     if columns is None:
            fr_cols = (['symbols', 'positions']
                       + [key for key in atoms.arrays if
                          key not in ['symbols', 'positions', 'numbers',
                                      'species', 'pos']])

and when we output the atoms.arrays after performing simulation with CHGNet it shows these keys:
['symbols', 'positions', 'initial_magmoms', 'forces', 'magmoms', 'crystal_fea']
I believe the 'crystal_fea' is the incompatible column. One way to work around is to ignore xyz and save as traj file. Another way is to manually specify columns=['forces', 'magmoms']. The latter solution might require a complete update of all the codes (and might be tricky because the properties given by different calculator might be different?)
P.S. To my knowledge this is only incompatible with latest ase-3.23.0b1, no incompatibility issue with ase 3.22 available from pip (although there are other problems like stress shape mismatch)

@mkphuthi
Copy link
Collaborator

@hancheng2000's case is more a bug in CHGNet/ASE than it is an issue with ASIMTools. We can handle this by provide a write_atoms function but this is not a priority. I would recommend using the ASE-3.22 or an earlier commit of ASE-3.23 for now. Every other developer has to wait for ASE to become stable to fix these inconsistencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants