Example: Adding library structures

This example demonstrates how to add library structures via the atomicrex Python interface.

Location

examples/python_interface

Input files

  • adding_structures_library.py: main input file

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    from __future__ import print_function, division
    import atomicrex
    
    print('Create job object')
    job = atomicrex.Job()
    
    print('Parse XML input file with input parameters'
          ' and potential information.')
    job.parse_input_file('main.xml')
    
    print('Switch verbosity to "medium"')
    job.set_verbosity(2)
    
    print('Adding a structure from the library')
    structure = job.add_library_structure('Al-fcc',
                                          'fcc',
                                          {'alat': 4.032, 'type': 'Al'})
    structure.modify_property('atomic-energy', -3.36, 200.0)
    structure.modify_property('bulk-modulus', 80.9, 0.1)
    structure.modify_property('C11', 114.0, 100.0)
    structure.modify_property('C12', 61.9)
    structure.modify_property('C44', 31.6)
    print('')
    
    print('Testing some ASE like method calls')
    print('.positions: ', structure.positions)
    print('.get_positions: ', structure.get_positions())
    print('.get_cell:')
    print(structure.get_cell())
    print('.get_number_of_atoms: ', structure.get_number_of_atoms())
    print('')
    
    print('Computing properties.')
    structure.compute_properties()
    print('')
    
    print('Printing properties.')
    structure.print_properties()
    print('')
    
    print('Adding another structure from the library')
    structure = job.add_library_structure('Al-bcc',
                                          'body-centered cubic',
                                          {'alat': 4.032, 'type': 'Al'})
    print('')
    
    print('Demonstrating the conversion to an ASE atoms object.')
    conf = structure.get_atoms(job)
    print(' cell')
    print(conf.cell)
    print(' atoms')
    for k, atom in enumerate(conf, start=1):
        print(' {:3}'.format(k))
        print(atom)
    print('')
    
    print('Adding more structures from the library')
    structure = job.add_library_structure('my-simple-cubic',
                                          'sc',
                                          {'alat': 3.0, 'type': 'Al'})
    print(' id: {} (nat = {})'.format(structure.id,
                                      structure.get_number_of_atoms()))
    print(structure.cell)
    structure = job.add_library_structure('my-diamond',
                                          'dia',
                                          {'alat': 1.0, 'type': 'Al'})
    print(' id: {} (nat = {})'.format(structure.id,
                                      structure.get_number_of_atoms()))
    print(structure.cell)
    structure = job.add_library_structure('my-hcp',
                                          'hcp',
                                          {'alat': 2.5,
                                           'clat': 4.0,
                                           'type': 'Al'})
    print(' id: {} (nat = {})'.format(structure.id,
                                      structure.get_number_of_atoms()))
    print(structure.cell)
    structure = job.add_library_structure('my-omega',
                                          'omega',
                                          {'alat': 2.5,
                                           'ca_ratio': 0.69,
                                           'type': 'Al'})
    print(' id: {} (nat = {})'.format(structure.id,
                                      structure.get_number_of_atoms()))
    print(structure.cell)
    structure = job.add_library_structure('my-L10',
                                          'L10',
                                          {'alat': 2.5,
                                           'ca_ratio': 0.69,
                                           'type_A': 'Al',
                                           'type_B': 'Al'})
    print(' id: {} (nat = {})'.format(structure.id,
                                      structure.get_number_of_atoms()))
    print(structure.cell)
    print('')
    
  • main.xml: file with definition of potential

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    <?xml version='1.0' encoding='iso-8859-1'?>
    <job>
      <name>EAM potential</name>
    
      <atom-types>
        <species>Al</species>
      </atom-types>
    
      <potentials>
        <xi:include href='potential.xml' xmlns:xi='http://www.w3.org/2003/XInclude' />
      </potentials>
    
      <structures>
      </structures>
    
    </job>
    
  • potential.xml: definition of potential form and parameters

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    <eam id='Al potential' species-a='*' species-b='*'>
    
      <mapping>
        <pair-interaction species-a='*' species-b='*' function='V' />
        <electron-density species-a='*' species-b='*' function='rho' />
        <embedding-energy species='*' function='F' />
      </mapping>
      
      <functions>
    
        <user-function id='V'>
          <input-var>r</input-var>
          <expression>
    	A * exp(-lambda * r)
          </expression>
          <derivative>
    	-lambda * A * exp(-lambda * r)
          </derivative>
          <param name='A'>500</param>
          <param name='lambda'>2.73</param>
          <fit-dof>
    	<A/>
    	<lambda/>
          </fit-dof>
          <screening>
    	<user-function id='rho_screening'>
    	  <cutoff>6.5</cutoff>
    	  <input-var>r</input-var>
    	  <expression>
    	    1 - 1/(1 + ((r - cutoff) / h)^4)
    	  </expression>
    	  <derivative>
    	    4 * h^4 * (r - cutoff)^3 / ((h^4 + (r - cutoff)^4)^2)
    	  </derivative>
    	  <param name='h'>3</param>
    	</user-function>
          </screening>
        </user-function>
    
        <user-function id='rho'>
          <input-var>r</input-var>
          <expression>
    	exp(-twomu * r)
          </expression>
          <derivative>
    	-twomu * exp(-twomu * r)
          </derivative>
          <param name='twomu'>1.14</param>
          <fit-dof>
    	<twomu/>
          </fit-dof>
          <screening>
    	<user-function id='rho_screening'>
    	  <cutoff>6.5</cutoff>
    	  <input-var>r</input-var>
    	  <expression>
    	    1 - 1/(1 + ((r - cutoff) / h)^4)
    	  </expression>
    	  <derivative>
    	    4 * h^4 * (r - cutoff)^3 / ((h^4 + (r - cutoff)^4)^2)
    	  </derivative>
    	  <param name='h'>3</param>
    	</user-function>
          </screening>
        </user-function>
    
        <user-function id='F'>
          <input-var>rho</input-var>
          <expression>
    	-D * sqrt(rho)
          </expression>
          <derivative>
            -D / (2 * sqrt(rho))
          </derivative>
          <param name='D'>8</param>
          <fit-dof>
    	<D/>
          </fit-dof>
        </user-function>
        
      </functions>
      
    </eam>
    

Output (files)

  • The properties (as well as parameters) are written to standard output.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    -- Create job object
    -- Parse XML input file with input parameters and potential information.
    -- Switch verbosity to "medium"
    -- Adding a structure from the library
    
    -- Testing some ASE like method calls
    ('.positions: ', array([[ 0.,  0.,  0.]]))
    ('.get_positions: ', array([[ 0.,  0.,  0.]]))
    .get_cell:
    [[ 0.     2.016  2.016]
     [ 2.016  0.     2.016]
     [ 2.016  2.016  0.   ]]
    ('.get_number_of_atoms: ', 1)
    
    -- Computing properties.
    
    -- Printing properties.
    total-energy: -3.82797 eV
    atomic-energy: -3.82797 eV/atom (target: -3.36 eV/atom) Rel. weight: 200; Abs. weight: 1; Weighted residual: 0.218993
    total-volume: 16.3871 A^3
    atomic-volume: 16.3871 A^3/atom
    bulk-modulus: 35.5454 GPa (target: 80.9 GPa) Rel. weight: 0.1; Abs. weight: 1; Weighted residual: 2057.04
    C11: 43.1185 GPa (target: 114 GPa) Rel. weight: 100; Abs. weight: 1; Weighted residual: 5024.19
    C12: 31.7592 GPa (target: 61.9 GPa) Rel. weight: 1; Abs. weight: 1; Weighted residual: 908.47
    C44: 25.7187 GPa (target: 31.6 GPa) Rel. weight: 1; Abs. weight: 1; Weighted residual: 34.5897
    
    -- Adding another structure from the library
    
    -- Demonstrating the conversion to an ASE atoms object.
    --- cell
    [[-2.016  2.016  2.016]
     [ 2.016 -2.016  2.016]
     [ 2.016  2.016 -2.016]]
    --- atoms
      1 Atom('Al', [0.0, 0.0, 0.0], index=0)
    
    -- Adding more structures from the library
    --- id: my-simple-cubic (nat = 1)
    [[ 3.  0.  0.]
     [ 0.  3.  0.]
     [ 0.  0.  3.]]
    --- id: my-diamond (nat = 2)
    [[ 0.   0.5  0.5]
     [ 0.5  0.   0.5]
     [ 0.5  0.5  0. ]]
    --- id: my-hcp (nat = 2)
    [[  2.50000000e+00  -2.22044605e-16   0.00000000e+00]
     [ -1.25000000e+00   2.16506351e+00   0.00000000e+00]
     [  0.00000000e+00   0.00000000e+00   4.00000000e+00]]
    --- id: my-omega (nat = 3)
    [[  2.50000000e+00  -2.22044605e-16   0.00000000e+00]
     [ -1.25000000e+00   2.16506351e+00   0.00000000e+00]
     [  0.00000000e+00   0.00000000e+00   1.72500000e+00]]
    --- id: my-L10 (nat = 4)
    [[ 2.5    0.     0.   ]
     [ 0.     2.5    0.   ]
     [ 0.     0.     1.725]]