From 3cc3d228c15fe92ce96c1f3e710845d7763611fa Mon Sep 17 00:00:00 2001 From: Sam Waseda Date: Tue, 6 Dec 2022 08:26:53 +0100 Subject: [PATCH 01/21] remove default None --- pyiron_atomistics/atomistics/structure/atoms.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 134bed7ee..17e9d0479 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2561,7 +2561,7 @@ def get_initial_magnetic_moments(self): else: return np.zeros(len(self)) - def set_initial_magnetic_moments(self, magmoms=None): + def set_initial_magnetic_moments(self, magmoms): """ Set array of initial magnetic moments. @@ -2569,13 +2569,12 @@ def set_initial_magnetic_moments(self, magmoms=None): magmoms (numpy.ndarray/list): List of magneric moments """ # pyiron part - if magmoms is not None: - if len(magmoms) != len(self): - raise ValueError("magmons can be collinear or non-collinear.") - if "spin" not in self._tag_list._lists.keys(): - self.add_tag(spin=None) - for ind, spin in enumerate(magmoms): - self.spin[ind] = spin + if len(magmoms) != len(self): + raise ValueError("magmons can be collinear or non-collinear.") + if "spin" not in self._tag_list._lists.keys(): + self.add_tag(spin=None) + for ind, spin in enumerate(magmoms): + self.spin[ind] = spin self.spins = magmoms def rotate( From 68397bf3c0e8680f8f4b82734c8377bed03b5f1c Mon Sep 17 00:00:00 2001 From: Sam Waseda Date: Tue, 6 Dec 2022 08:33:58 +0100 Subject: [PATCH 02/21] allow single value and dict --- pyiron_atomistics/atomistics/structure/atoms.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 17e9d0479..658d1e512 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2569,13 +2569,21 @@ def set_initial_magnetic_moments(self, magmoms): magmoms (numpy.ndarray/list): List of magneric moments """ # pyiron part + if isinstance(magmoms, dict): + if set(self.get_chemical_symbols()) != set(magmoms.keys()): + raise ValueError('Dict input must contain all the chemical species') + magmoms = [magmoms[c] for c in self.get_chemical_symbols()] + elif not hasattr(magmoms, '__len__') or ( + len(magmoms) == 3 and len(self) != 3 + ): + magmoms = len(self) * [magmoms] if len(magmoms) != len(self): raise ValueError("magmons can be collinear or non-collinear.") if "spin" not in self._tag_list._lists.keys(): self.add_tag(spin=None) for ind, spin in enumerate(magmoms): self.spin[ind] = spin - self.spins = magmoms + def rotate( self, a=0.0, v=None, center=(0, 0, 0), rotate_cell=False, index_list=None From a47b3ab81f52738e3c2ac7467a6bc54cae7e1d37 Mon Sep 17 00:00:00 2001 From: Sam Waseda Date: Tue, 6 Dec 2022 08:44:07 +0100 Subject: [PATCH 03/21] add documentation --- .../atomistics/structure/atoms.py | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 658d1e512..ab2896543 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2566,7 +2566,44 @@ def set_initial_magnetic_moments(self, magmoms): Set array of initial magnetic moments. Args: - magmoms (numpy.ndarray/list): List of magneric moments + magmoms (numpy.ndarray/list/dict/float): List, dict or single value + of magneric moments + + + Example I: + + >>> from pyiron_atomistics import Project + >>> structure = Project('.').create.structure.bulk('Ni', cubic=True) + >>> structure[-1] = 'Fe' + >>> v_dict = {'Fe': 1, 'Ni': 2} + >>> structure.set_initial_magnetic_moments(v_dict) + >>> print(structure.get_initial_magnetic_moments()) + + Output: + + >>> array([2, 2, 2, 1]) + + + Example II: + + >>> from pyiron_atomistics import Project + >>> structure = Project('.').create.structure.bulk('Ni', cubic=True) + >>> structure[-1] = 'Fe' + >>> structure.set_initial_magnetic_moments(1) + >>> print(structure.get_initial_magnetic_moments()) + + Output: + + >>> array([1, 1, 1, 1]) + + If you want to make it non-magnetic, set `None`: + + >>> structure.set_initial_magnetic_moments(None) + + If a list or an array of length 3 (e.g. [1, 2, 3]) is set and the + number of atoms is not 3, it will be considered as a non-collinear + magnetic moments, and the values will be distributed to all the + atoms (like in Example II) """ # pyiron part if isinstance(magmoms, dict): From ec8457e1aeac9892fcb3337f45f241e04852cf61 Mon Sep 17 00:00:00 2001 From: Sam Waseda Date: Tue, 6 Dec 2022 08:46:23 +0100 Subject: [PATCH 04/21] Black --- pyiron_atomistics/atomistics/structure/atoms.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index ab2896543..95371758c 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2608,11 +2608,9 @@ def set_initial_magnetic_moments(self, magmoms): # pyiron part if isinstance(magmoms, dict): if set(self.get_chemical_symbols()) != set(magmoms.keys()): - raise ValueError('Dict input must contain all the chemical species') + raise ValueError("Dict input must contain all the chemical species") magmoms = [magmoms[c] for c in self.get_chemical_symbols()] - elif not hasattr(magmoms, '__len__') or ( - len(magmoms) == 3 and len(self) != 3 - ): + elif not hasattr(magmoms, '__len__') or (len(magmoms) == 3 and len(self) != 3): magmoms = len(self) * [magmoms] if len(magmoms) != len(self): raise ValueError("magmons can be collinear or non-collinear.") From 71fbd61d84c6b64f2dd90b197909d5800ee24b18 Mon Sep 17 00:00:00 2001 From: Sam Waseda Date: Tue, 6 Dec 2022 14:47:18 +0100 Subject: [PATCH 05/21] Restore case distinction for magmoms=None and add tests --- .../atomistics/structure/atoms.py | 30 +++++++++++-------- tests/atomistics/structure/test_atoms.py | 6 ++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 95371758c..f65154336 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2606,18 +2606,24 @@ def set_initial_magnetic_moments(self, magmoms): atoms (like in Example II) """ # pyiron part - if isinstance(magmoms, dict): - if set(self.get_chemical_symbols()) != set(magmoms.keys()): - raise ValueError("Dict input must contain all the chemical species") - magmoms = [magmoms[c] for c in self.get_chemical_symbols()] - elif not hasattr(magmoms, '__len__') or (len(magmoms) == 3 and len(self) != 3): - magmoms = len(self) * [magmoms] - if len(magmoms) != len(self): - raise ValueError("magmons can be collinear or non-collinear.") - if "spin" not in self._tag_list._lists.keys(): - self.add_tag(spin=None) - for ind, spin in enumerate(magmoms): - self.spin[ind] = spin + if magmoms is not None: + if isinstance(magmoms, dict): + if set(self.get_chemical_symbols()) != set(magmoms.keys()): + raise ValueError( + "Elements in structure {} not equal to those in dict {}".format( + set(self.get_chemical_symbols()), set(magmoms.keys()) + ) + ) + magmoms = [magmoms[c] for c in self.get_chemical_symbols()] + elif not hasattr(magmoms, '__len__') or (len(magmoms) == 3 and len(self) != 3): + magmoms = len(self) * [magmoms] + if len(magmoms) != len(self): + raise ValueError("magmons can be collinear or non-collinear.") + if "spin" not in self._tag_list._lists.keys(): + self.add_tag(spin=None) + for ind, spin in enumerate(magmoms): + self.spin[ind] = spin # For self._tag_list.spin + self.spins = magmoms # For self.array['initial_magmoms'] def rotate( diff --git a/tests/atomistics/structure/test_atoms.py b/tests/atomistics/structure/test_atoms.py index 7ce17729d..41eac1284 100644 --- a/tests/atomistics/structure/test_atoms.py +++ b/tests/atomistics/structure/test_atoms.py @@ -520,6 +520,12 @@ def test_set_initial_magnetic_moments(self): basis.set_repeat(2) self.assertTrue(np.array_equal(basis.spins, np.hstack([0.0, 2.0] * 8))) self.assertRaises(ValueError, basis.set_initial_magnetic_moments, magmoms=[4] * (len(basis) - 1)) + basis = Atoms(elements=3 * ["Ni"] + ["Fe"], positions=np.random.random((4, 3)), cell=np.eye(3)) + basis.set_initial_magnetic_moments({'Fe': 1, 'Ni': 2}) + self.assertEqual(basis.get_initial_magnetic_moments().tolist(), [2, 2, 2, 1]) + basis = Atoms(elements=3 * ["Ni"] + ["Fe"], positions=np.random.random((4, 3)), cell=np.eye(3)) + basis.set_initial_magnetic_moments(1) + self.assertEqual(basis.get_initial_magnetic_moments().tolist(), [1, 1, 1, 1]) def test_get_parent_basis(self): periodic_table = PeriodicTable() From b4ce6807a395afe1226e925ad8e54fe395221a9f Mon Sep 17 00:00:00 2001 From: pyiron-runner Date: Tue, 6 Dec 2022 13:48:37 +0000 Subject: [PATCH 06/21] Format black --- pyiron_atomistics/atomistics/structure/atoms.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index f65154336..aa4d6f3a9 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2597,7 +2597,7 @@ def set_initial_magnetic_moments(self, magmoms): >>> array([1, 1, 1, 1]) If you want to make it non-magnetic, set `None`: - + >>> structure.set_initial_magnetic_moments(None) If a list or an array of length 3 (e.g. [1, 2, 3]) is set and the @@ -2615,16 +2615,17 @@ def set_initial_magnetic_moments(self, magmoms): ) ) magmoms = [magmoms[c] for c in self.get_chemical_symbols()] - elif not hasattr(magmoms, '__len__') or (len(magmoms) == 3 and len(self) != 3): + elif not hasattr(magmoms, "__len__") or ( + len(magmoms) == 3 and len(self) != 3 + ): magmoms = len(self) * [magmoms] if len(magmoms) != len(self): raise ValueError("magmons can be collinear or non-collinear.") if "spin" not in self._tag_list._lists.keys(): self.add_tag(spin=None) for ind, spin in enumerate(magmoms): - self.spin[ind] = spin # For self._tag_list.spin - self.spins = magmoms # For self.array['initial_magmoms'] - + self.spin[ind] = spin # For self._tag_list.spin + self.spins = magmoms # For self.array['initial_magmoms'] def rotate( self, a=0.0, v=None, center=(0, 0, 0), rotate_cell=False, index_list=None From 6c1af1caa7a33c04dc1ab268a1c7cfe753c25a65 Mon Sep 17 00:00:00 2001 From: Sam Waseda Date: Tue, 6 Dec 2022 16:43:01 +0100 Subject: [PATCH 07/21] add test for ValueError --- tests/atomistics/structure/test_atoms.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/atomistics/structure/test_atoms.py b/tests/atomistics/structure/test_atoms.py index 41eac1284..c0b5f997b 100644 --- a/tests/atomistics/structure/test_atoms.py +++ b/tests/atomistics/structure/test_atoms.py @@ -523,6 +523,7 @@ def test_set_initial_magnetic_moments(self): basis = Atoms(elements=3 * ["Ni"] + ["Fe"], positions=np.random.random((4, 3)), cell=np.eye(3)) basis.set_initial_magnetic_moments({'Fe': 1, 'Ni': 2}) self.assertEqual(basis.get_initial_magnetic_moments().tolist(), [2, 2, 2, 1]) + self.assertRaises(ValueError, basis.set_initial_magnetic_moments, {'Fe': 1}) basis = Atoms(elements=3 * ["Ni"] + ["Fe"], positions=np.random.random((4, 3)), cell=np.eye(3)) basis.set_initial_magnetic_moments(1) self.assertEqual(basis.get_initial_magnetic_moments().tolist(), [1, 1, 1, 1]) From a5c785df37d9b21508c2fa6acb0bc56468fe9ff1 Mon Sep 17 00:00:00 2001 From: Sam Waseda Date: Tue, 6 Dec 2022 16:44:37 +0100 Subject: [PATCH 08/21] restore default None --- pyiron_atomistics/atomistics/structure/atoms.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index aa4d6f3a9..271bca4e1 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2561,13 +2561,13 @@ def get_initial_magnetic_moments(self): else: return np.zeros(len(self)) - def set_initial_magnetic_moments(self, magmoms): + def set_initial_magnetic_moments(self, magmoms=None): """ Set array of initial magnetic moments. Args: - magmoms (numpy.ndarray/list/dict/float): List, dict or single value - of magneric moments + magmoms (numpy.ndarray/list/dict/float/None): List, dict or single + value of magneric moments Example I: From fa8e90af391a66f4305a5deaf97e2217a5983001 Mon Sep 17 00:00:00 2001 From: Sam Dareska <37879103+samwaseda@users.noreply.github.com> Date: Tue, 6 Dec 2022 16:45:14 +0100 Subject: [PATCH 09/21] Update pyiron_atomistics/atomistics/structure/atoms.py Co-authored-by: Marvin Poul --- pyiron_atomistics/atomistics/structure/atoms.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 271bca4e1..9cda44a3f 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2577,11 +2577,8 @@ def set_initial_magnetic_moments(self, magmoms=None): >>> structure[-1] = 'Fe' >>> v_dict = {'Fe': 1, 'Ni': 2} >>> structure.set_initial_magnetic_moments(v_dict) - >>> print(structure.get_initial_magnetic_moments()) - - Output: - - >>> array([2, 2, 2, 1]) + >>> structure.get_initial_magnetic_moments() + array([2, 2, 2, 1]) Example II: From eac221672e7af0e6250c832d4a8ce073192cfa3e Mon Sep 17 00:00:00 2001 From: Sam Dareska <37879103+samwaseda@users.noreply.github.com> Date: Tue, 6 Dec 2022 16:45:56 +0100 Subject: [PATCH 10/21] Update pyiron_atomistics/atomistics/structure/atoms.py Co-authored-by: Marvin Poul --- pyiron_atomistics/atomistics/structure/atoms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 9cda44a3f..72e91c38f 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2605,7 +2605,7 @@ def set_initial_magnetic_moments(self, magmoms=None): # pyiron part if magmoms is not None: if isinstance(magmoms, dict): - if set(self.get_chemical_symbols()) != set(magmoms.keys()): + if set(self.get_species_symbols()) != set(magmoms.keys()): raise ValueError( "Elements in structure {} not equal to those in dict {}".format( set(self.get_chemical_symbols()), set(magmoms.keys()) From 4ac205bb8157e07997fb162f92c27011490eec43 Mon Sep 17 00:00:00 2001 From: Sam Dareska <37879103+samwaseda@users.noreply.github.com> Date: Tue, 6 Dec 2022 17:40:48 +0100 Subject: [PATCH 11/21] Update pyiron_atomistics/atomistics/structure/atoms.py Co-authored-by: Han <60923573+ligerzero-ai@users.noreply.github.com> --- pyiron_atomistics/atomistics/structure/atoms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 72e91c38f..5b823bbe9 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2567,7 +2567,7 @@ def set_initial_magnetic_moments(self, magmoms=None): Args: magmoms (numpy.ndarray/list/dict/float/None): List, dict or single - value of magneric moments + value of magnetic moments Example I: From acaf6b9c28af8f5dcfd43a60999719e02edcbcb5 Mon Sep 17 00:00:00 2001 From: Sam Waseda Date: Tue, 6 Dec 2022 17:46:35 +0100 Subject: [PATCH 12/21] remove repetition of collinear spin and update doc --- pyiron_atomistics/atomistics/structure/atoms.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 5b823bbe9..d350e4946 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2588,19 +2588,11 @@ def set_initial_magnetic_moments(self, magmoms=None): >>> structure[-1] = 'Fe' >>> structure.set_initial_magnetic_moments(1) >>> print(structure.get_initial_magnetic_moments()) - - Output: - - >>> array([1, 1, 1, 1]) + array([1, 1, 1, 1]) If you want to make it non-magnetic, set `None`: >>> structure.set_initial_magnetic_moments(None) - - If a list or an array of length 3 (e.g. [1, 2, 3]) is set and the - number of atoms is not 3, it will be considered as a non-collinear - magnetic moments, and the values will be distributed to all the - atoms (like in Example II) """ # pyiron part if magmoms is not None: @@ -2612,9 +2604,7 @@ def set_initial_magnetic_moments(self, magmoms=None): ) ) magmoms = [magmoms[c] for c in self.get_chemical_symbols()] - elif not hasattr(magmoms, "__len__") or ( - len(magmoms) == 3 and len(self) != 3 - ): + elif not hasattr(magmoms, "__len__"): magmoms = len(self) * [magmoms] if len(magmoms) != len(self): raise ValueError("magmons can be collinear or non-collinear.") From cf0cb90a046696f90998d3b2d2a45c84c4003d46 Mon Sep 17 00:00:00 2001 From: Sam Waseda Date: Tue, 6 Dec 2022 17:51:32 +0100 Subject: [PATCH 13/21] use Marvins Sequence --- pyiron_atomistics/atomistics/structure/atoms.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index d350e4946..fa3ad8969 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -29,6 +29,7 @@ from pyiron_base import state, deprecate, deprecate_soon from pyiron_atomistics.atomistics.structure.pyironase import publication from pymatgen.io.ase import AseAtomsAdaptor +from collections.abc import Sequence from scipy.spatial import cKDTree, Voronoi @@ -2604,7 +2605,7 @@ def set_initial_magnetic_moments(self, magmoms=None): ) ) magmoms = [magmoms[c] for c in self.get_chemical_symbols()] - elif not hasattr(magmoms, "__len__"): + elif not isinstance(magmoms, (np.ndarray, Sequence)): magmoms = len(self) * [magmoms] if len(magmoms) != len(self): raise ValueError("magmons can be collinear or non-collinear.") From dcab438ea18356a0b4b5f69f9db2378048934f6e Mon Sep 17 00:00:00 2001 From: Han Mai Date: Wed, 7 Dec 2022 13:33:52 +0100 Subject: [PATCH 14/21] docstring --- .../atomistics/structure/atoms.py | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index fa3ad8969..8d286bb5c 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2567,33 +2567,40 @@ def set_initial_magnetic_moments(self, magmoms=None): Set array of initial magnetic moments. Args: - magmoms (numpy.ndarray/list/dict/float/None): List, dict or single - value of magnetic moments + magmoms (None/numpy.ndarray/list/dict/float): Default value is None (non magnetic calc). + List, dict or single value assigning magnetic moments to the structure object. + If you want to make it non-magnetic, set `None` + >>> structure.set_initial_magnetic_moments(None) - Example I: - + Example I input: np.ndarray / List + Assigns site moments via corresponding list of same length as number of sites in structure + >>> from pyiron_atomistics import Project + >>> structure = Project('.').create.structure.bulk('Ni', cubic=True) + >>> structure[-1] = 'Fe' + >>> spin_list = [1, 2, 3, 4] + >>> structure.set_initial_magnetic_moments(spin_list) + >>> structure.get_initial_magnetic_moments() + array([1, 2, 3, 4]) + + Example II input: dict + Assigns species-specific magnetic moments species >>> from pyiron_atomistics import Project >>> structure = Project('.').create.structure.bulk('Ni', cubic=True) >>> structure[-1] = 'Fe' - >>> v_dict = {'Fe': 1, 'Ni': 2} - >>> structure.set_initial_magnetic_moments(v_dict) + >>> spin_dict = {'Fe': 1, 'Ni': 2} + >>> structure.set_initial_magnetic_moments(spin_dict) >>> structure.get_initial_magnetic_moments() array([2, 2, 2, 1]) - - Example II: - + Example III input: float + Assigns the same magnetic moment to all atoms in the structure >>> from pyiron_atomistics import Project >>> structure = Project('.').create.structure.bulk('Ni', cubic=True) >>> structure[-1] = 'Fe' >>> structure.set_initial_magnetic_moments(1) >>> print(structure.get_initial_magnetic_moments()) array([1, 1, 1, 1]) - - If you want to make it non-magnetic, set `None`: - - >>> structure.set_initial_magnetic_moments(None) """ # pyiron part if magmoms is not None: From c3344239a6cba3d0b8a67e94ba8e1ad9d33ddc57 Mon Sep 17 00:00:00 2001 From: pyiron-runner Date: Wed, 7 Dec 2022 12:35:26 +0000 Subject: [PATCH 15/21] Format black --- pyiron_atomistics/atomistics/structure/atoms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 8d286bb5c..e593ede9a 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2582,7 +2582,7 @@ def set_initial_magnetic_moments(self, magmoms=None): >>> structure.set_initial_magnetic_moments(spin_list) >>> structure.get_initial_magnetic_moments() array([1, 2, 3, 4]) - + Example II input: dict Assigns species-specific magnetic moments species >>> from pyiron_atomistics import Project From 9c7d1afd5b6e6f68b30d3f6f2f32e1efbcd3dd16 Mon Sep 17 00:00:00 2001 From: Han Mai Date: Wed, 7 Dec 2022 13:50:40 +0100 Subject: [PATCH 16/21] update docstring with non-coll --- .../atomistics/structure/atoms.py | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index e593ede9a..e618d6aa1 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2569,6 +2569,8 @@ def set_initial_magnetic_moments(self, magmoms=None): Args: magmoms (None/numpy.ndarray/list/dict/float): Default value is None (non magnetic calc). List, dict or single value assigning magnetic moments to the structure object. + + Non-collinear calculations may be specified through using a dict (see last example) If you want to make it non-magnetic, set `None` >>> structure.set_initial_magnetic_moments(None) @@ -2582,7 +2584,7 @@ def set_initial_magnetic_moments(self, magmoms=None): >>> structure.set_initial_magnetic_moments(spin_list) >>> structure.get_initial_magnetic_moments() array([1, 2, 3, 4]) - + Example II input: dict Assigns species-specific magnetic moments species >>> from pyiron_atomistics import Project @@ -2601,13 +2603,35 @@ def set_initial_magnetic_moments(self, magmoms=None): >>> structure.set_initial_magnetic_moments(1) >>> print(structure.get_initial_magnetic_moments()) array([1, 1, 1, 1]) + + Example IV input: dict/list for non-collinear magmoms. + Assigns non-collinear magnetic moments to the sites in structure + >>> from pyiron_atomistics import Project + >>> structure = Project('.').create.structure.bulk('Ni', cubic=True) + >>> structure[-1] = 'Fe' + + Option 1: List input sets vectors for each individual atom + >>> non_coll_magmom_vect = [[1, 2, 3] + [2, 3, 4], + [3, 4, 5], + [4, 5, 6]] + >>> structure.set_initial_magnetic_moments(non_coll_magmom_vect) + >>> print(structure.get_initial_magnetic_moments()) + array([[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]) + + Option 2: Dict input sets magmom vectors for individual species: + >>> print(structure.get_initial_magnetic_moments()) + >>> non_coll_spin_dict = {'Fe': [2, 3, 4], 'Ni': [1, 2, 3]} + >>> structure.set_initial_magnetic_moments(spin_dict) + >>> print(structure.get_initial_magnetic_moments()) + array([[1, 2, 3], [1, 2, 3], [1, 2, 3], [2, 3, 4]]) """ # pyiron part if magmoms is not None: if isinstance(magmoms, dict): if set(self.get_species_symbols()) != set(magmoms.keys()): raise ValueError( - "Elements in structure {} not equal to those in dict {}".format( + "Elements in structure {} not found in dict {}".format( set(self.get_chemical_symbols()), set(magmoms.keys()) ) ) @@ -2615,7 +2639,7 @@ def set_initial_magnetic_moments(self, magmoms=None): elif not isinstance(magmoms, (np.ndarray, Sequence)): magmoms = len(self) * [magmoms] if len(magmoms) != len(self): - raise ValueError("magmons can be collinear or non-collinear.") + raise ValueError("magmoms can be collinear or non-collinear.") if "spin" not in self._tag_list._lists.keys(): self.add_tag(spin=None) for ind, spin in enumerate(magmoms): From 53bb5d75292f61a5a3cf9b86724cc738010534d1 Mon Sep 17 00:00:00 2001 From: Han Mai Date: Wed, 7 Dec 2022 13:51:16 +0100 Subject: [PATCH 17/21] missed update --- pyiron_atomistics/atomistics/structure/atoms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index e618d6aa1..bb58bfde0 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2570,7 +2570,7 @@ def set_initial_magnetic_moments(self, magmoms=None): magmoms (None/numpy.ndarray/list/dict/float): Default value is None (non magnetic calc). List, dict or single value assigning magnetic moments to the structure object. - Non-collinear calculations may be specified through using a dict (see last example) + Non-collinear calculations may be specified through using a dict/list (see last example) If you want to make it non-magnetic, set `None` >>> structure.set_initial_magnetic_moments(None) From 73806f64b4d892b806bf1ba616cdab63d89650b1 Mon Sep 17 00:00:00 2001 From: Han Mai Date: Wed, 7 Dec 2022 13:52:13 +0100 Subject: [PATCH 18/21] consistent reference to site, not atom. --- pyiron_atomistics/atomistics/structure/atoms.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index bb58bfde0..1ce8d7950 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2586,7 +2586,7 @@ def set_initial_magnetic_moments(self, magmoms=None): array([1, 2, 3, 4]) Example II input: dict - Assigns species-specific magnetic moments species + Assigns species-specific magnetic moments >>> from pyiron_atomistics import Project >>> structure = Project('.').create.structure.bulk('Ni', cubic=True) >>> structure[-1] = 'Fe' @@ -2596,7 +2596,7 @@ def set_initial_magnetic_moments(self, magmoms=None): array([2, 2, 2, 1]) Example III input: float - Assigns the same magnetic moment to all atoms in the structure + Assigns the same magnetic moment to all sites in the structure >>> from pyiron_atomistics import Project >>> structure = Project('.').create.structure.bulk('Ni', cubic=True) >>> structure[-1] = 'Fe' @@ -2610,7 +2610,7 @@ def set_initial_magnetic_moments(self, magmoms=None): >>> structure = Project('.').create.structure.bulk('Ni', cubic=True) >>> structure[-1] = 'Fe' - Option 1: List input sets vectors for each individual atom + Option 1: List input sets vectors for each individual site >>> non_coll_magmom_vect = [[1, 2, 3] [2, 3, 4], [3, 4, 5], From 053a9ac590e07f83b4021694f09b2d5289f60f69 Mon Sep 17 00:00:00 2001 From: Han Mai Date: Wed, 7 Dec 2022 13:57:37 +0100 Subject: [PATCH 19/21] wrong variable name in docstring --- pyiron_atomistics/atomistics/structure/atoms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 1ce8d7950..455502049 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2622,7 +2622,7 @@ def set_initial_magnetic_moments(self, magmoms=None): Option 2: Dict input sets magmom vectors for individual species: >>> print(structure.get_initial_magnetic_moments()) >>> non_coll_spin_dict = {'Fe': [2, 3, 4], 'Ni': [1, 2, 3]} - >>> structure.set_initial_magnetic_moments(spin_dict) + >>> structure.set_initial_magnetic_moments(non_coll_spin_dict) >>> print(structure.get_initial_magnetic_moments()) array([[1, 2, 3], [1, 2, 3], [1, 2, 3], [2, 3, 4]]) """ From 5972678ebcc4f98bfa6dc460a28caa54601cf407 Mon Sep 17 00:00:00 2001 From: pyiron-runner Date: Wed, 7 Dec 2022 13:11:23 +0000 Subject: [PATCH 20/21] Format black --- pyiron_atomistics/atomistics/structure/atoms.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 455502049..9ab83b8eb 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2569,7 +2569,7 @@ def set_initial_magnetic_moments(self, magmoms=None): Args: magmoms (None/numpy.ndarray/list/dict/float): Default value is None (non magnetic calc). List, dict or single value assigning magnetic moments to the structure object. - + Non-collinear calculations may be specified through using a dict/list (see last example) If you want to make it non-magnetic, set `None` @@ -2584,7 +2584,7 @@ def set_initial_magnetic_moments(self, magmoms=None): >>> structure.set_initial_magnetic_moments(spin_list) >>> structure.get_initial_magnetic_moments() array([1, 2, 3, 4]) - + Example II input: dict Assigns species-specific magnetic moments >>> from pyiron_atomistics import Project @@ -2603,13 +2603,13 @@ def set_initial_magnetic_moments(self, magmoms=None): >>> structure.set_initial_magnetic_moments(1) >>> print(structure.get_initial_magnetic_moments()) array([1, 1, 1, 1]) - + Example IV input: dict/list for non-collinear magmoms. Assigns non-collinear magnetic moments to the sites in structure >>> from pyiron_atomistics import Project >>> structure = Project('.').create.structure.bulk('Ni', cubic=True) >>> structure[-1] = 'Fe' - + Option 1: List input sets vectors for each individual site >>> non_coll_magmom_vect = [[1, 2, 3] [2, 3, 4], @@ -2618,13 +2618,13 @@ def set_initial_magnetic_moments(self, magmoms=None): >>> structure.set_initial_magnetic_moments(non_coll_magmom_vect) >>> print(structure.get_initial_magnetic_moments()) array([[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]) - + Option 2: Dict input sets magmom vectors for individual species: >>> print(structure.get_initial_magnetic_moments()) >>> non_coll_spin_dict = {'Fe': [2, 3, 4], 'Ni': [1, 2, 3]} >>> structure.set_initial_magnetic_moments(non_coll_spin_dict) - >>> print(structure.get_initial_magnetic_moments()) - array([[1, 2, 3], [1, 2, 3], [1, 2, 3], [2, 3, 4]]) + >>> print(structure.get_initial_magnetic_moments()) + array([[1, 2, 3], [1, 2, 3], [1, 2, 3], [2, 3, 4]]) """ # pyiron part if magmoms is not None: From cb71b2622671324ef5095e5e6bfeede9fa558c1b Mon Sep 17 00:00:00 2001 From: Sam Waseda Date: Thu, 8 Dec 2022 09:30:26 +0100 Subject: [PATCH 21/21] formatting --- pyiron_atomistics/atomistics/structure/atoms.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pyiron_atomistics/atomistics/structure/atoms.py b/pyiron_atomistics/atomistics/structure/atoms.py index 9ab83b8eb..db7dce897 100644 --- a/pyiron_atomistics/atomistics/structure/atoms.py +++ b/pyiron_atomistics/atomistics/structure/atoms.py @@ -2567,16 +2567,19 @@ def set_initial_magnetic_moments(self, magmoms=None): Set array of initial magnetic moments. Args: - magmoms (None/numpy.ndarray/list/dict/float): Default value is None (non magnetic calc). - List, dict or single value assigning magnetic moments to the structure object. + magmoms (None/numpy.ndarray/list/dict/float): Default value is + None (non magnetic calc). List, dict or single value assigning + magnetic moments to the structure object. - Non-collinear calculations may be specified through using a dict/list (see last example) + Non-collinear calculations may be specified through using a dict/list + (see last example) If you want to make it non-magnetic, set `None` >>> structure.set_initial_magnetic_moments(None) Example I input: np.ndarray / List - Assigns site moments via corresponding list of same length as number of sites in structure + Assigns site moments via corresponding list of same length as number + of sites in structure >>> from pyiron_atomistics import Project >>> structure = Project('.').create.structure.bulk('Ni', cubic=True) >>> structure[-1] = 'Fe'