Coverage for /builds/ericyuan00000/ase/ase/utils/abc.py: 78.26%

23 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2025-06-18 01:20 +0000

1# fmt: off 

2 

3import collections 

4from abc import abstractmethod 

5 

6import numpy as np 

7 

8# Due to the high prevalence of cyclic imports surrounding ase.optimize, 

9# we define the Optimizable ABC here in utils. 

10# Can we find a better way? 

11 

12 

13class Optimizable(collections.abc.Sized): 

14 @abstractmethod 

15 def get_positions(self): 

16 ... 

17 

18 @abstractmethod 

19 def set_positions(self, positions): 

20 ... 

21 

22 @abstractmethod 

23 def get_forces(self): 

24 ... 

25 

26 @abstractmethod 

27 def get_potential_energy(self): 

28 ... 

29 

30 @abstractmethod 

31 def iterimages(self): 

32 ... 

33 

34 def converged(self, forces, fmax): 

35 return np.linalg.norm(forces, axis=1).max() < fmax 

36 

37 def __ase_optimizable__(self): 

38 return self