Skip to content

Commit c24fd70

Browse files
committed
rm ase adapter function
1 parent f7f5466 commit c24fd70

File tree

1 file changed

+0
-96
lines changed

1 file changed

+0
-96
lines changed

src/diffpy/structure/structure.py

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import warnings
1919

2020
import numpy
21-
from ase import Atoms as ASEAtoms
2221

2322
from diffpy.structure.atom import Atom
2423
from diffpy.structure.lattice import Lattice
@@ -366,101 +365,6 @@ def get_lattice_vector_angles(self):
366365
gamma = self.lattice.angle(a, b)
367366
return numpy.array([alpha, beta, gamma])
368367

369-
def convert_ase_to_diffpy_structure(
370-
self,
371-
ase_atoms: ASEAtoms,
372-
lost_info: list[str] | None = None,
373-
) -> Structure | tuple[Structure, dict]: # noqa
374-
"""Convert ASE `Atoms` object to this `Structure` instance.
375-
376-
The conversion process involves extracting the lattice parameters, chemical symbols,
377-
and fractional coordinates from the ASE `Atoms` object and populating the corresponding
378-
attributes of this `Structure` instance. The `lattice` attribute is set based on the
379-
cell parameters of the ASE `Atoms` object, and each `Atom` in this `Structure` is created
380-
with the chemical symbol and fractional coordinates extracted from the ASE `Atoms`.
381-
382-
Parameters
383-
----------
384-
ase_structure : ase.Atoms
385-
The ASE `Atoms` object to be converted.
386-
lost_info : str or list of str, optional
387-
The method(s) or attribute(s) to extract from the ASE `Atoms`
388-
object that do not have a direct equivalent in the `Structure` class.
389-
This will be provided in a dictionary format where keys are the
390-
method/attribute name(s) and value(s) are the corresponding data
391-
extracted from the ASE `Atoms` object.
392-
Default is None. See `Examples` for usage.
393-
394-
Returns
395-
-------
396-
lost_info : dict, optional
397-
If specified, the dictionary containing any information from the ASE `Atoms`
398-
object that is not currently available in the `Structure` class.
399-
Default behavior is to return `None`.
400-
If `lost_info` is provided, a dictionary containing
401-
any information from the ASE `Atoms` will be returned.
402-
This may include information such as magnetic moments, charge states,
403-
or other ASE-specific properties that do not have a direct equivalent
404-
in the `Structure` class.
405-
406-
Raises
407-
------
408-
TypeError
409-
If the input `ase_structure` is not an instance of `ase.Atoms`.
410-
ValueError
411-
If any of the specified `lost_info` attributes are not present in the ASE `Atoms` object.
412-
413-
Examples
414-
--------
415-
An example of converting an `ASE.Atoms` instance to a `Structure` instance,
416-
417-
.. code-block:: python
418-
from ase import Atoms
419-
from diffpy.structure import Structure
420-
421-
# Create an ASE Atoms object
422-
ase_atoms = Atoms('H2O', positions=[[0, 0, 0], [0, 0, 1], [1, 0, 0]])
423-
424-
# Convert to a diffpy Structure object
425-
structure = Structure()
426-
structure.convert_ase_to_diffpy(ase_atoms)
427-
428-
429-
To extract additional information from the ASE `Atoms` object that is not
430-
directly represented in the `Structure` class, such as magnetic moments,
431-
you can specify an attribute or method of `ASE.Atoms` as
432-
a string or list of strings in `lost_info` list. For example,
433-
434-
.. code-block:: python
435-
lost_info = structure.convert_ase_to_diffpy(
436-
ase_atoms,
437-
lost_info='get_magnetic_moments'
438-
)
439-
440-
will return a dictionary with the magnetic moments of the atoms in the ASE `Atoms` object.
441-
"""
442-
# clear structure before populating it with new atoms
443-
del self[:]
444-
if not isinstance(ase_atoms, ASEAtoms):
445-
raise TypeError(f"Input must be an instance of ase.Atoms but got type {type(ase_atoms)}.")
446-
cell = ase_atoms.get_cell()
447-
self.lattice = Lattice(base=numpy.array(cell))
448-
symbols = ase_atoms.get_chemical_symbols()
449-
scaled_positions = ase_atoms.get_scaled_positions()
450-
for atom_symbol, frac_coord in zip(symbols, scaled_positions):
451-
self.append(Atom(atom_symbol, xyz=frac_coord))
452-
if lost_info is None:
453-
return
454-
extracted_info = {}
455-
if isinstance(lost_info, str):
456-
lost_info = [lost_info]
457-
for name in lost_info:
458-
if not hasattr(ase_atoms, name):
459-
raise ValueError(f"ASE.Atoms object has no attribute '{name}'.")
460-
attr = getattr(ase_atoms, name)
461-
extracted_info[name] = attr() if callable(attr) else attr
462-
return extracted_info
463-
464368
def assign_unique_labels(self):
465369
"""Set a unique label string for each `Atom` in this structure.
466370

0 commit comments

Comments
 (0)