Exercise 5: Development of our own mudule for Gamma surface calculationsΒΆ

# This is necessary for higher levels of 
%config Completer.use_jedi = False
import numpy as np
import matplotlib.pylab as plt
from pyiron import Project
pr = Project("Gamma")
### pr.remove_jobs()
class GammaSurface:
    def __init__(self, ref_job, potential=None, n_mesh=(10,10)):
        self._project = ref_job.project
        self._mesh_x = n_mesh[0]
        self._mesh_y = n_mesh[1]
        self._ref_job = ref_job
        self.surface = ref_job.structure
        self._potential = potential
        
    def get_structure(self, x, y):
        Al = self.surface.copy()
        z = Al.positions[:, 2]
        z_0 = np.mean(z)
        Al.positions[z < z_0, 0] += x
        Al.positions[z < z_0, 1] += y
        Al.add_tag(selective_dynamics=[False, False, True])
        Al.pbc[2] = True
        return Al   
    
    def run_gamma(self):
        ref = self.get_structure(0,0)
        x_max = ref.cell[0, 0]
        y_max = ref.cell[1, 1]
        x_vec = np.linspace(0, x_max, self._mesh_x)
        y_vec = np.linspace(0, y_max, self._mesh_y)
        for x in x_vec:
            for y in y_vec:
                job_name = 'x_{:.4}_y_{:.4}'.format(x, y).replace('.', '_')
                if job_name not in self._project.list_nodes():    
                    job = self._project.create_job(self._project.job_type.Lammps, job_name)
                    job.structure = self.get_structure(x, y)
                    if self._potential is not None:
                        job.potential = self._potential
                    job.calc_minimize()
                    job.run()    

    def _collect(self):
        x_lst, y_lst, e_lst = [], [], []
        ref = self.get_structure(0,0)
        x_max = ref.cell[0, 0]
        y_max = ref.cell[1, 1]
        x_vec = np.linspace(0, x_max, self._mesh_x)
        y_vec = np.linspace(0, y_max, self._mesh_y)
        for x in x_vec:
            for y in y_vec:
                job_name = 'x_{:.4}_y_{:.4}'.format(x, y).replace('.', '_')
                job = self._project.inspect(job_name)
                e_lst.append(job['output/generic/energy_tot'][-1])
                x_lst.append(x)
                y_lst.append(y)
        self.x_lst = np.array(x_lst)  
        self.y_lst = np.array(y_lst)
        self.e_lst = np.array(e_lst)
        
    def plot(self):
        plt.plot(self.y_lst, self.e_lst, 'x-'); 
        
    def plot2d(self):
        plt.imshow(np.reshape(self.e_lst, (self._mesh_x,-1)))
surface_list = ['fcc111', 'fcc100']
fig, ax_list = plt.subplots(ncols=2, nrows=1, sharex=True)

potential = 'Al_Mg_Mendelev_eam'
for i, surf in enumerate(surface_list):
    with pr.open(surf) as pr_test:
        ax= ax_list[i]
        Al = pr_test.create_surface('Al', surf, (1,2,12), vacuum=10, orthogonal=True)
        ref_job = pr_test.create_job(pr_test.job_type.Lammps, 'ref_job')
        ref_job.structure = Al
        ref_job.potential = potential
        ref_job.calc_minimize()
        gs = GammaSurface(ref_job, potential, n_mesh=(5,19))
        gs.run_gamma()
        gs._collect()
        ax.contourf(np.reshape(gs.e_lst, (gs._mesh_x,-1)))
The job x_0_0_y_0_0 was saved and received the ID: 1
The job x_0_0_y_0_2756 was saved and received the ID: 2
The job x_0_0_y_0_5511 was saved and received the ID: 3
The job x_0_0_y_0_8267 was saved and received the ID: 4
The job x_0_0_y_1_102 was saved and received the ID: 5
The job x_0_0_y_1_378 was saved and received the ID: 6
The job x_0_0_y_1_653 was saved and received the ID: 7
The job x_0_0_y_1_929 was saved and received the ID: 8
The job x_0_0_y_2_205 was saved and received the ID: 9
The job x_0_0_y_2_48 was saved and received the ID: 10
The job x_0_0_y_2_756 was saved and received the ID: 11
The job x_0_0_y_3_031 was saved and received the ID: 12
The job x_0_0_y_3_307 was saved and received the ID: 13
The job x_0_0_y_3_582 was saved and received the ID: 14
The job x_0_0_y_3_858 was saved and received the ID: 15
The job x_0_0_y_4_134 was saved and received the ID: 16
The job x_0_0_y_4_409 was saved and received the ID: 17
The job x_0_0_y_4_685 was saved and received the ID: 18
The job x_0_0_y_4_96 was saved and received the ID: 19
The job x_0_7159_y_0_0 was saved and received the ID: 20
The job x_0_7159_y_0_2756 was saved and received the ID: 21
The job x_0_7159_y_0_5511 was saved and received the ID: 22
The job x_0_7159_y_0_8267 was saved and received the ID: 23
The job x_0_7159_y_1_102 was saved and received the ID: 24
The job x_0_7159_y_1_378 was saved and received the ID: 25
The job x_0_7159_y_1_653 was saved and received the ID: 26
The job x_0_7159_y_1_929 was saved and received the ID: 27
The job x_0_7159_y_2_205 was saved and received the ID: 28
The job x_0_7159_y_2_48 was saved and received the ID: 29
The job x_0_7159_y_2_756 was saved and received the ID: 30
The job x_0_7159_y_3_031 was saved and received the ID: 31
The job x_0_7159_y_3_307 was saved and received the ID: 32
The job x_0_7159_y_3_582 was saved and received the ID: 33
The job x_0_7159_y_3_858 was saved and received the ID: 34
The job x_0_7159_y_4_134 was saved and received the ID: 35
The job x_0_7159_y_4_409 was saved and received the ID: 36
The job x_0_7159_y_4_685 was saved and received the ID: 37
The job x_0_7159_y_4_96 was saved and received the ID: 38
The job x_1_432_y_0_0 was saved and received the ID: 39
The job x_1_432_y_0_2756 was saved and received the ID: 40
The job x_1_432_y_0_5511 was saved and received the ID: 41
The job x_1_432_y_0_8267 was saved and received the ID: 42
The job x_1_432_y_1_102 was saved and received the ID: 43
The job x_1_432_y_1_378 was saved and received the ID: 44
The job x_1_432_y_1_653 was saved and received the ID: 45
The job x_1_432_y_1_929 was saved and received the ID: 46
The job x_1_432_y_2_205 was saved and received the ID: 47
The job x_1_432_y_2_48 was saved and received the ID: 48
The job x_1_432_y_2_756 was saved and received the ID: 49
The job x_1_432_y_3_031 was saved and received the ID: 50
The job x_1_432_y_3_307 was saved and received the ID: 51
The job x_1_432_y_3_582 was saved and received the ID: 52
The job x_1_432_y_3_858 was saved and received the ID: 53
The job x_1_432_y_4_134 was saved and received the ID: 54
The job x_1_432_y_4_409 was saved and received the ID: 55
The job x_1_432_y_4_685 was saved and received the ID: 56
The job x_1_432_y_4_96 was saved and received the ID: 57
The job x_2_148_y_0_0 was saved and received the ID: 58
The job x_2_148_y_0_2756 was saved and received the ID: 59
The job x_2_148_y_0_5511 was saved and received the ID: 60
The job x_2_148_y_0_8267 was saved and received the ID: 61
The job x_2_148_y_1_102 was saved and received the ID: 62
The job x_2_148_y_1_378 was saved and received the ID: 63
The job x_2_148_y_1_653 was saved and received the ID: 64
The job x_2_148_y_1_929 was saved and received the ID: 65
The job x_2_148_y_2_205 was saved and received the ID: 66
The job x_2_148_y_2_48 was saved and received the ID: 67
The job x_2_148_y_2_756 was saved and received the ID: 68
The job x_2_148_y_3_031 was saved and received the ID: 69
The job x_2_148_y_3_307 was saved and received the ID: 70
The job x_2_148_y_3_582 was saved and received the ID: 71
The job x_2_148_y_3_858 was saved and received the ID: 72
The job x_2_148_y_4_134 was saved and received the ID: 73
The job x_2_148_y_4_409 was saved and received the ID: 74
The job x_2_148_y_4_685 was saved and received the ID: 75
The job x_2_148_y_4_96 was saved and received the ID: 76
The job x_2_864_y_0_0 was saved and received the ID: 77
The job x_2_864_y_0_2756 was saved and received the ID: 78
The job x_2_864_y_0_5511 was saved and received the ID: 79
The job x_2_864_y_0_8267 was saved and received the ID: 80
The job x_2_864_y_1_102 was saved and received the ID: 81
The job x_2_864_y_1_378 was saved and received the ID: 82
The job x_2_864_y_1_653 was saved and received the ID: 83
The job x_2_864_y_1_929 was saved and received the ID: 84
The job x_2_864_y_2_205 was saved and received the ID: 85
The job x_2_864_y_2_48 was saved and received the ID: 86
The job x_2_864_y_2_756 was saved and received the ID: 87
The job x_2_864_y_3_031 was saved and received the ID: 88
The job x_2_864_y_3_307 was saved and received the ID: 89
The job x_2_864_y_3_582 was saved and received the ID: 90
The job x_2_864_y_3_858 was saved and received the ID: 91
The job x_2_864_y_4_134 was saved and received the ID: 92
The job x_2_864_y_4_409 was saved and received the ID: 93
The job x_2_864_y_4_685 was saved and received the ID: 94
The job x_2_864_y_4_96 was saved and received the ID: 95
The job x_0_0_y_0_0 was saved and received the ID: 96
The job x_0_0_y_0_3182 was saved and received the ID: 97
The job x_0_0_y_0_6364 was saved and received the ID: 98
The job x_0_0_y_0_9546 was saved and received the ID: 99
The job x_0_0_y_1_273 was saved and received the ID: 100
The job x_0_0_y_1_591 was saved and received the ID: 101
The job x_0_0_y_1_909 was saved and received the ID: 102
The job x_0_0_y_2_227 was saved and received the ID: 103
The job x_0_0_y_2_546 was saved and received the ID: 104
The job x_0_0_y_2_864 was saved and received the ID: 105
The job x_0_0_y_3_182 was saved and received the ID: 106
The job x_0_0_y_3_5 was saved and received the ID: 107
The job x_0_0_y_3_818 was saved and received the ID: 108
The job x_0_0_y_4_137 was saved and received the ID: 109
The job x_0_0_y_4_455 was saved and received the ID: 110
The job x_0_0_y_4_773 was saved and received the ID: 111
The job x_0_0_y_5_091 was saved and received the ID: 112
The job x_0_0_y_5_409 was saved and received the ID: 113
The job x_0_0_y_5_728 was saved and received the ID: 114
The job x_0_7159_y_0_0 was saved and received the ID: 115
The job x_0_7159_y_0_3182 was saved and received the ID: 116
The job x_0_7159_y_0_6364 was saved and received the ID: 117
The job x_0_7159_y_0_9546 was saved and received the ID: 118
The job x_0_7159_y_1_273 was saved and received the ID: 119
The job x_0_7159_y_1_591 was saved and received the ID: 120
The job x_0_7159_y_1_909 was saved and received the ID: 121
The job x_0_7159_y_2_227 was saved and received the ID: 122
The job x_0_7159_y_2_546 was saved and received the ID: 123
The job x_0_7159_y_2_864 was saved and received the ID: 124
The job x_0_7159_y_3_182 was saved and received the ID: 125
The job x_0_7159_y_3_5 was saved and received the ID: 126
The job x_0_7159_y_3_818 was saved and received the ID: 128
The job x_0_7159_y_4_137 was saved and received the ID: 129
The job x_0_7159_y_4_455 was saved and received the ID: 130
The job x_0_7159_y_4_773 was saved and received the ID: 132
The job x_0_7159_y_5_091 was saved and received the ID: 133
The job x_0_7159_y_5_409 was saved and received the ID: 134
The job x_0_7159_y_5_728 was saved and received the ID: 136
The job x_1_432_y_0_0 was saved and received the ID: 137
The job x_1_432_y_0_3182 was saved and received the ID: 138
The job x_1_432_y_0_6364 was saved and received the ID: 139
The job x_1_432_y_0_9546 was saved and received the ID: 140
The job x_1_432_y_1_273 was saved and received the ID: 142
The job x_1_432_y_1_591 was saved and received the ID: 143
The job x_1_432_y_1_909 was saved and received the ID: 144
The job x_1_432_y_2_227 was saved and received the ID: 146
The job x_1_432_y_2_546 was saved and received the ID: 147
The job x_1_432_y_2_864 was saved and received the ID: 148
The job x_1_432_y_3_182 was saved and received the ID: 149
The job x_1_432_y_3_5 was saved and received the ID: 151
The job x_1_432_y_3_818 was saved and received the ID: 154
The job x_1_432_y_4_137 was saved and received the ID: 156
The job x_1_432_y_4_455 was saved and received the ID: 159
The job x_1_432_y_4_773 was saved and received the ID: 161
The job x_1_432_y_5_091 was saved and received the ID: 164
The job x_1_432_y_5_409 was saved and received the ID: 166
The job x_1_432_y_5_728 was saved and received the ID: 168
The job x_2_148_y_0_0 was saved and received the ID: 170
The job x_2_148_y_0_3182 was saved and received the ID: 172
The job x_2_148_y_0_6364 was saved and received the ID: 174
The job x_2_148_y_0_9546 was saved and received the ID: 176
The job x_2_148_y_1_273 was saved and received the ID: 178
The job x_2_148_y_1_591 was saved and received the ID: 181
The job x_2_148_y_1_909 was saved and received the ID: 183
The job x_2_148_y_2_227 was saved and received the ID: 185
The job x_2_148_y_2_546 was saved and received the ID: 187
The job x_2_148_y_2_864 was saved and received the ID: 189
The job x_2_148_y_3_182 was saved and received the ID: 191
The job x_2_148_y_3_5 was saved and received the ID: 192
The job x_2_148_y_3_818 was saved and received the ID: 195
The job x_2_148_y_4_137 was saved and received the ID: 198
The job x_2_148_y_4_455 was saved and received the ID: 199
The job x_2_148_y_4_773 was saved and received the ID: 202
The job x_2_148_y_5_091 was saved and received the ID: 204
The job x_2_148_y_5_409 was saved and received the ID: 206
The job x_2_148_y_5_728 was saved and received the ID: 207
The job x_2_864_y_0_0 was saved and received the ID: 209
The job x_2_864_y_0_3182 was saved and received the ID: 212
The job x_2_864_y_0_6364 was saved and received the ID: 213
The job x_2_864_y_0_9546 was saved and received the ID: 215
The job x_2_864_y_1_273 was saved and received the ID: 217
The job x_2_864_y_1_591 was saved and received the ID: 218
The job x_2_864_y_1_909 was saved and received the ID: 221
The job x_2_864_y_2_227 was saved and received the ID: 223
The job x_2_864_y_2_546 was saved and received the ID: 225
The job x_2_864_y_2_864 was saved and received the ID: 227
The job x_2_864_y_3_182 was saved and received the ID: 230
The job x_2_864_y_3_5 was saved and received the ID: 231
The job x_2_864_y_3_818 was saved and received the ID: 233
The job x_2_864_y_4_137 was saved and received the ID: 235
The job x_2_864_y_4_455 was saved and received the ID: 237
The job x_2_864_y_4_773 was saved and received the ID: 240
The job x_2_864_y_5_091 was saved and received the ID: 242
The job x_2_864_y_5_409 was saved and received the ID: 243
The job x_2_864_y_5_728 was saved and received the ID: 245
../_images/sol_5_gamma_surface_6_2.png