From 19826537c05a8af132b6ca6a415de471d52d65b7 Mon Sep 17 00:00:00 2001 From: Sarath Date: Tue, 16 Jul 2024 13:44:46 +0200 Subject: [PATCH 1/9] add aimsgb --- environment.yml | 1 + setup.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index d248c6f..0401680 100644 --- a/environment.yml +++ b/environment.yml @@ -18,5 +18,6 @@ dependencies: #- atomman - mp-api - sqlalchemy + - aimsgb - pip: - "git+https://github.com/RDFLib/rdflib-sqlalchemy.git@develop" diff --git a/setup.py b/setup.py index ddf1700..a21d9a7 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ install_requires=['numpy', 'ase', 'rdflib', 'pyyaml', 'graphviz', 'networkx', 'pyscal3', 'spglib', 'pandas', 'owlready2', - 'atomman', 'mp-api'], + 'atomman', 'mp-api', 'aimsgb'], classifiers=[ 'Programming Language :: Python :: 3' ], From ca983fa96d60135ed70a882432b062377fabb5c8 Mon Sep 17 00:00:00 2001 From: Sarath Date: Tue, 16 Jul 2024 13:49:51 +0200 Subject: [PATCH 2/9] add pymatgen --- environment.yml | 1 + setup.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 0401680..8ef40d9 100644 --- a/environment.yml +++ b/environment.yml @@ -19,5 +19,6 @@ dependencies: - mp-api - sqlalchemy - aimsgb + - pymatgen - pip: - "git+https://github.com/RDFLib/rdflib-sqlalchemy.git@develop" diff --git a/setup.py b/setup.py index a21d9a7..8a5b520 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ install_requires=['numpy', 'ase', 'rdflib', 'pyyaml', 'graphviz', 'networkx', 'pyscal3', 'spglib', 'pandas', 'owlready2', - 'atomman', 'mp-api', 'aimsgb'], + 'atomman', 'mp-api', 'aimsgb', 'pymatgen'], classifiers=[ 'Programming Language :: Python :: 3' ], From 4d197d43519ed1113a59aa0cc9d33e9ab97ae074 Mon Sep 17 00:00:00 2001 From: Sarath Date: Wed, 17 Jul 2024 18:16:42 +0200 Subject: [PATCH 3/9] add aimsgb based gb creation --- atomrdf/structure.py | 140 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/atomrdf/structure.py b/atomrdf/structure.py index 2fa0a86..4f49ee0 100644 --- a/atomrdf/structure.py +++ b/atomrdf/structure.py @@ -382,8 +382,146 @@ def _make_dislocation( return output_structure, disc return output_structure - def _make_grain_boundary( + axis, + sigma, + gb_plane, + structure=None, + element=None, + lattice_constant=1, + ca_ratio=1.633, + repetitions=(1, 1, 1), + overlap=0.0, + vacuum=0.0, + delete_layer="0b0t0b0t", + tolerance= 0.25, + primitive=False, + uc_a=1, + uc_b=1, + graph=None, + names=False, + label=None, + backend='aimsgb' +): + if backend == 'aimsgb': + return _make_grain_boundary_aimsgb( + axis, + sigma, + gb_plane, + structure=structure, + element=element, + lattice_constant=lattice_constant, + ca_ratio=ca_ratio, + repetitions=repetitions, + overlap=overlap, + vacuum=vacuum, + delete_layer=delete_layer, + tolerance= tolerance, + primitive=primitive, + uc_a=uc_a, + uc_b=uc_b, + graph=graph, + names=names, + label=label, + ) + else: + return _make_grain_boundary_inbuilt( + axis, + sigma, + gb_plane, + structure=structure, + element=element, + lattice_constant=lattice_constant, + repetitions=repetitions, + overlap=overlap, + graph=graph, + names=names, + label=label, + ) + +def _make_grain_boundary_aimsgb( + axis, + sigma, + gb_plane, + structure=None, + element=None, + lattice_constant=1, + ca_ratio=1.633, + repetitions=(1, 1, 1), + overlap=0.0, + vacuum=0.0, + delete_layer="0b0t0b0t", + tolerance= 0.25, + primitive=False, + uc_a=1, + uc_b=1, + graph=None, + names=False, + label=None, +): + try: + from pymatgen.io.ase import AseAtomsAdaptor + from aimsgb import GrainBoundary, Grain + except ImportError: + raise ImportError("This function requires the aimsgb and pymatgen packages to be installed") + + + init_sys = _make_crystal( + structure, + lattice_constant=_declass(lattice_constant), + repetitions=repetitions, + ca_ratio=_declass(ca_ratio), + noise=0, + element=element, + primitive=False, + ) + + sdict = copy.deepcopy(init_sys._structure_dict) + + asesys = init_sys.write.ase() + pmsys = AseAtomsAdaptor().get_structure(atoms=asesys) + grain = Grain(pmsys.lattice, pmsys.species, pmsys.frac_coords) + gb = GrainBoundary(axis=axis, sigma=sigma, + plane=gb_plane, + initial_struct=grain, + uc_a=uc_a, + uc_b=uc_b) + gb_struct = Grain.stack_grains( + grain_a = gb.grain_a, + grain_b = gb.grain_b, + vacuum = vacuum, + gap=overlap, + direction = gb.direction, + delete_layer=delete_layer, + tol=tolerance, + to_primitive=primitive, + ) + asestruct = AseAtomsAdaptor().get_atoms(structure=gb_struct) + sys = System.read.ase(asestruct, graph=graph, names=names, label=label) + sys.atoms._lattice = structure + sys.atoms._lattice_constant = _declass(lattice_constant) + sys._structure_dict = sdict + sys.label = label + sys.to_graph() + sys.add_property_mappings(lattice_constant, mapping_quantity='lattice_constant') + sys.add_property_mappings(ca_ratio, mapping_quantity='lattice_constant') + + gb_inb = GrainBoundary() + gb_inb.create_grain_boundary(axis=axis, sigma=sigma, gb_plane=gb_plane) + + gb_dict = { + "GBPlane": " ".join(np.array(gb_plane).astype(str)), + "RotationAxis": axis, + "MisorientationAngle": gb.theta[0], + "GBType": gb_inb.find_gb_character(), + "sigma": gb.sigma, + } + sys.add_gb(gb_dict) + return sys + + + +def _make_grain_boundary_inbuilt( axis, sigma, gb_plane, From a66e17b86a644fc12e3ddb7bcf255a32c1be187a Mon Sep 17 00:00:00 2001 From: Sarath Date: Wed, 17 Jul 2024 18:22:41 +0200 Subject: [PATCH 4/9] fix structure in aimsgb --- atomrdf/structure.py | 37 +++++++++++++++++++++++++++--------- tests/test_structuregraph.py | 10 +++++++++- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/atomrdf/structure.py b/atomrdf/structure.py index 4f49ee0..5c39fc1 100644 --- a/atomrdf/structure.py +++ b/atomrdf/structure.py @@ -466,15 +466,34 @@ def _make_grain_boundary_aimsgb( raise ImportError("This function requires the aimsgb and pymatgen packages to be installed") - init_sys = _make_crystal( - structure, - lattice_constant=_declass(lattice_constant), - repetitions=repetitions, - ca_ratio=_declass(ca_ratio), - noise=0, - element=element, - primitive=False, - ) + if structure is not None: + # create a structure with the info + init_sys = _make_crystal( + structure, + lattice_constant=_declass(lattice_constant), + repetitions=repetitions, + ca_ratio=_declass(ca_ratio), + noise=0, + element=element, + primitive=primitive, + ) + elif element is not None: + if element in element_dict.keys(): + structure = element_dict[element]["structure"] + lattice_constant = element_dict[element]["lattice_constant"] + else: + raise ValueError("Please provide structure") + init_sys = _make_crystal( + structure, + lattice_constant=_declass(lattice_constant), + repetitions=repetitions, + ca_ratio=_declass(ca_ratio), + noise=0, + element=element, + primitive=primitive, + ) + else: + raise ValueError("Provide either structure or element") sdict = copy.deepcopy(init_sys._structure_dict) diff --git a/tests/test_structuregraph.py b/tests/test_structuregraph.py index d9ffe30..77fd81d 100644 --- a/tests/test_structuregraph.py +++ b/tests/test_structuregraph.py @@ -16,10 +16,18 @@ def test_structuregraph(): sigma=5, gb_plane=[3, -1, 0], element='Fe', - graph=s) + graph=s, + backend='inbuilt') assert(sys.sample != None) + sys = System.create.defect.grain_boundary(axis=[0,0,1], + sigma=5, + gb_plane=[3, -1, 0], + element='Fe', + graph=s, + backend='aimsgb') + assert(sys.sample != None) From f6c37cfa775ea7c5848a65aa8ed231bc92a4cb61 Mon Sep 17 00:00:00 2001 From: Sarath Date: Wed, 17 Jul 2024 18:24:55 +0200 Subject: [PATCH 5/9] fix conflicting imports --- atomrdf/structure.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/atomrdf/structure.py b/atomrdf/structure.py index 5c39fc1..5be0b10 100644 --- a/atomrdf/structure.py +++ b/atomrdf/structure.py @@ -461,7 +461,8 @@ def _make_grain_boundary_aimsgb( ): try: from pymatgen.io.ase import AseAtomsAdaptor - from aimsgb import GrainBoundary, Grain + from aimsgb import GrainBoundary as AIMSGrainBoundary + from aimsgb import Grain as AIMSGrain except ImportError: raise ImportError("This function requires the aimsgb and pymatgen packages to be installed") @@ -499,13 +500,13 @@ def _make_grain_boundary_aimsgb( asesys = init_sys.write.ase() pmsys = AseAtomsAdaptor().get_structure(atoms=asesys) - grain = Grain(pmsys.lattice, pmsys.species, pmsys.frac_coords) - gb = GrainBoundary(axis=axis, sigma=sigma, + grain = AIMSGrain(pmsys.lattice, pmsys.species, pmsys.frac_coords) + gb = AIMSGrainBoundary(axis=axis, sigma=sigma, plane=gb_plane, initial_struct=grain, uc_a=uc_a, uc_b=uc_b) - gb_struct = Grain.stack_grains( + gb_struct = AIMSGrain.stack_grains( grain_a = gb.grain_a, grain_b = gb.grain_b, vacuum = vacuum, From ceabd2d87a875e016c7c418fb2abb474d661eeb8 Mon Sep 17 00:00:00 2001 From: Sarath Date: Wed, 17 Jul 2024 18:35:51 +0200 Subject: [PATCH 6/9] make gb type optional --- atomrdf/structure.py | 10 +- examples/02_grain_boundaries.ipynb | 412 ++++++++++++++--------------- 2 files changed, 208 insertions(+), 214 deletions(-) diff --git a/atomrdf/structure.py b/atomrdf/structure.py index 5be0b10..7af7bbe 100644 --- a/atomrdf/structure.py +++ b/atomrdf/structure.py @@ -526,14 +526,18 @@ def _make_grain_boundary_aimsgb( sys.add_property_mappings(lattice_constant, mapping_quantity='lattice_constant') sys.add_property_mappings(ca_ratio, mapping_quantity='lattice_constant') - gb_inb = GrainBoundary() - gb_inb.create_grain_boundary(axis=axis, sigma=sigma, gb_plane=gb_plane) + try: + gb_inb = GrainBoundary() + gb_inb.create_grain_boundary(axis=axis, sigma=sigma, gb_plane=gb_plane) + gb_type = gb_inb.find_gb_character() + except: + gb_type = None gb_dict = { "GBPlane": " ".join(np.array(gb_plane).astype(str)), "RotationAxis": axis, "MisorientationAngle": gb.theta[0], - "GBType": gb_inb.find_gb_character(), + "GBType": gb_type, "sigma": gb.sigma, } sys.add_gb(gb_dict) diff --git a/examples/02_grain_boundaries.ipynb b/examples/02_grain_boundaries.ipynb index 14622db..76635ea 100644 --- a/examples/02_grain_boundaries.ipynb +++ b/examples/02_grain_boundaries.ipynb @@ -21,20 +21,7 @@ "execution_count": 1, "id": "f88eacd6-1bdc-4321-9e80-3d2720d318a1", "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "c4f616c028b447b58dfe55c7d388eeee", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "from atomrdf import KnowledgeGraph, System" ] @@ -134,23 +121,23 @@ "type": "scatter3d", "x": [ 0, - 18.15147376, - 18.15147376, - 0, + 18.151473769366497, + 18.151473769366497, + -5.557286062865456e-16, 0 ], "y": [ 0, 0, - 2.87, - 2.87, + 9.075736884683248, + 9.075736884683248, 0 ], "z": [ 0, - 0, - 0, - 0, + 1.1114572125730911e-15, + 1.6671858188596366e-15, + 5.557286062865456e-16, 0 ] }, @@ -165,24 +152,24 @@ "type": "scatter3d", "x": [ 0, - 18.15147376, - 18.15147376, - 0, + 18.151473769366497, + 18.151473769366497, + -5.557286062865456e-16, 0 ], "y": [ 0, 0, - 2.87, - 2.87, + 9.075736884683248, + 9.075736884683248, 0 ], "z": [ - 9.07573688, - 9.07573688, - 9.07573688, - 9.07573688, - 9.07573688 + 2.8699999999999997, + 2.870000000000001, + 2.8700000000000014, + 2.87, + 2.8699999999999997 ] }, { @@ -196,8 +183,8 @@ "type": "scatter3d", "x": [ 0, - 18.15147376, - 18.15147376, + 18.151473769366497, + 18.151473769366497, 0, 0 ], @@ -210,9 +197,9 @@ ], "z": [ 0, - 0, - 9.07573688, - 9.07573688, + 1.1114572125730911e-15, + 2.870000000000001, + 2.8699999999999997, 0 ] }, @@ -226,25 +213,25 @@ "showlegend": false, "type": "scatter3d", "x": [ - 0, - 18.15147376, - 18.15147376, - 0, - 0 + -5.557286062865456e-16, + 18.151473769366497, + 18.151473769366497, + -5.557286062865456e-16, + -5.557286062865456e-16 ], "y": [ - 2.87, - 2.87, - 2.87, - 2.87, - 2.87 + 9.075736884683248, + 9.075736884683248, + 9.075736884683248, + 9.075736884683248, + 9.075736884683248 ], "z": [ - 0, - 0, - 9.07573688, - 9.07573688, - 0 + 5.557286062865456e-16, + 1.6671858188596366e-15, + 2.8700000000000014, + 2.87, + 5.557286062865456e-16 ] }, { @@ -258,23 +245,23 @@ "type": "scatter3d", "x": [ 0, - 0, - 0, + -5.557286062865456e-16, + -5.557286062865456e-16, 0, 0 ], "y": [ 0, - 2.87, - 2.87, + 9.075736884683248, + 9.075736884683248, 0, 0 ], "z": [ 0, - 0, - 9.07573688, - 9.07573688, + 5.557286062865456e-16, + 2.87, + 2.8699999999999997, 0 ] }, @@ -288,25 +275,25 @@ "showlegend": false, "type": "scatter3d", "x": [ - 18.15147376, - 18.15147376, - 18.15147376, - 18.15147376, - 18.15147376 + 18.151473769366497, + 18.151473769366497, + 18.151473769366497, + 18.151473769366497, + 18.151473769366497 ], "y": [ 0, - 2.87, - 2.87, + 9.075736884683248, + 9.075736884683248, 0, 0 ], "z": [ - 0, - 0, - 9.07573688, - 9.07573688, - 0 + 1.1114572125730911e-15, + 1.6671858188596366e-15, + 2.8700000000000014, + 2.870000000000001, + 1.1114572125730911e-15 ] }, { @@ -325,130 +312,130 @@ "opacity": 1, "type": "scatter3d", "x": [ - 9.983310568468324, - 9.07573688, - 11.798457945404973, - 12.706031633873298, - 10.89088425693665, - 11.798457945404973, - 9.983310568468324, - 10.89088425693665, - 9.07573688, - 16.3363263877466, - 14.521179010809949, - 15.428752699278274, - 13.613605322341623, - 14.521179010809949, - 12.706031633873298, - 13.613605322341623, - 17.243900076214924, - 16.3363263877466, - 17.243900076214924, - 15.428752699278274, - -4.683251120241039e-9, - 0.9075736837850741, - -4.683251120241039e-9, - 1.8151473722533984, - 0.9075736837850741, - 2.7227210607217236, - 1.8151473722533984, - 3.630294749190049, - 2.7227210607217236, - 4.537868437658374, - 3.630294749190049, - 5.445442126126698, - 4.537868437658374, - 6.3530158145950235, - 5.445442126126698, - 7.260589503063349, - 6.353015814595023, - 8.168163191531672, - 7.260589503063348, - 8.168163191531672 - ], - "y": [ - 1.435, - 1.435, - 0, - 1.435, - 0, - 1.435, - 0, - 1.435, 0, - 1.435, - 0, - 1.435, - 0, - 1.435, - 0, - 1.435, - 0, - 0, - 1.435, - 0, - 1.435, - 1.435, - 0, - 1.435, - 0, - 1.435, - 0, - 1.435, - 0, - 1.435, - 0, - 1.435, - 0, - 1.435, - 0, - 1.435, - 0, - 1.435, - 0, - 0 - ], - "z": [ - 7.2605895077466, + 2.7227210654049743, + 1.8151473769366497, + 0.9075736884683242, + 5.4454421308099485, 4.537868442341624, - 8.168163196214923, - 6.353015819278275, - 5.445442130809949, - 3.6302947538733, - 2.7227210654049747, - 0.9075736884683248, - 0, - 8.168163196214923, - 7.2605895077466, - 5.445442130809949, + 3.6302947538732995, + 8.168163196214921, + 7.260589507746597, + 6.353015819278269, + 0.9075736884683249, + 3.630294753873299, + 2.722721065404974, + 1.8151473769366493, + 6.353015819278274, + 5.4454421308099485, 4.537868442341624, - 2.7227210654049747, - 1.8151473769366495, + -2.7786430314327274e-16, + 8.168163196214923, + 7.260589507746598, + 9.075736884683248, + 11.79845795008822, + 10.890884261619897, + 9.983310573151572, + 14.521179015493196, + 13.613605327024871, + 12.706031638556547, + 17.24390008089817, + 16.336326392429847, + 15.428752703961518, + 9.983310573151574, + 12.706031638556547, + 11.798457950088219, + 10.890884261619897, + 15.42875270396152, + 14.521179015493196, + 13.613605327024871, + 9.075736884683248, + 17.24390008089817, + 16.336326392429847 + ], + "y": [ 0, - 6.353015819278275, + 0.9075736884683246, 3.630294753873299, + 6.353015819278274, + 1.8151473769366493, + 4.537868442341623, + 7.260589507746598, + 2.722721065404974, + 5.445442130809948, + 8.168163196214921, 1.8151473769366495, - 0.9075736884683248, - 4.537868442341624, - 1.81514737693665, + 2.7227210654049743, + 5.4454421308099485, + 8.168163196214921, + 3.6302947538732986, + 6.353015819278274, + 0, + 4.537868442341623, + 7.260589507746598, + 0.9075736884683236, 0, 8.168163196214923, + 5.44544213080995, + 2.722721065404977, + 7.260589507746599, + 4.537868442341626, + 1.8151473769366524, + 6.3530158192782755, + 3.6302947538733017, + 0.9075736884683286, + 7.260589507746599, 6.353015819278275, - 5.445442130809949, - 3.6302947538733, - 2.7227210654049747, - 0.907573688468325, + 3.630294753873301, + 0.9075736884683286, + 5.445442130809951, + 2.722721065404977, 0, - 7.2605895077466, - 6.353015819278275, - 4.537868442341624, - 3.6302947538733, - 1.81514737693665, - 0.9075736884683251, - 8.168163196214923, - 7.2605895077466, - 5.445442130809949, - 2.7227210654049747 + 4.537868442341626, + 1.8151473769366524, + 8.168163196214925 + ], + "z": [ + 0, + 2.2229144251461833e-16, + 3.3343716377192744e-16, + 4.445828850292367e-16, + 4.445828850292367e-16, + 5.557286062865456e-16, + 6.668743275438549e-16, + 6.668743275438547e-16, + 7.780200488011639e-16, + 8.891657700584727e-16, + 1.435, + 1.4350000000000003, + 1.4350000000000003, + 1.4350000000000003, + 1.4350000000000005, + 1.4350000000000005, + 1.435, + 1.435, + 1.4350000000000007, + 1.4350000000000003, + 4.1194005516010735e-32, + 6.668743275438546e-16, + 7.766196792272548e-16, + 1.0812201355044231e-15, + 7.780200488011638e-16, + 6.929102958907959e-16, + 9.975107521679635e-16, + 8.891657700584731e-16, + 6.668743275438548e-16, + 9.13801368831505e-16, + 1.435000000000001, + 1.4350000000000003, + 1.4350000000000012, + 1.4350000000000016, + 1.4350000000000005, + 1.435000000000001, + 1.4349999999999996, + 1.435000000000001, + 1.435000000000001, + 1.4350000000000003 ] } ], @@ -1307,9 +1294,9 @@ } }, "text/html": [ - "