Author Topic: How to use " nlread() " to read the scf only ?  (Read 3582 times)

0 Members and 1 Guest are viewing this topic.

Offline fangyongxinxi

  • QuantumATK Guru
  • ****
  • Posts: 143
  • Reputation: 0
    • View Profile
How to use " nlread() " to read the scf only ?
« on: May 1, 2013, 07:40 »
Dear Sir,
we use "nlread()" to save scf time in calculation, now I have a problem:

eg: I want to get the H-H bond length through a loop calculation , and I build a script as below:

vector_a = [10.0, 0.0, 0.0]*Angstrom
vector_b = [0.0, 10.0, 0.0]*Angstrom
vector_c = [0.0, 0.0, 10.0]*Angstrom
lattice = UnitCell(vector_a, vector_b, vector_c)

# Define elements
elements = [Hydrogen]*2

for dis in (a1,a2,a3,a4):   # ai is the distance   
    fractional_coordinates = [[ 0.  ,  0.  ,  0.  ],
                                           [ 0.  ,  0.  ,  dis]]
    bulk_configuration = BulkConfiguration(
        bravais_lattice=lattice,
        elements=elements,
        fractional_coordinates=fractional_coordinates
        )

    calculator = LCAOCalculator()

    bulk_configuration.setCalculator(calculator)
    bulk_configuration.update()
    nlsave('energy.nc', bulk_configuration)

    total_energy = TotalEnergy(bulk_configuration)
    nlsave('energy.nc', total_energy)
    nlprint(total_energy)

In the above script, I hope to import the "a1-scf" as the initial scf guess, for the next  "a2-scf" calculation. Here, I just want to import the scf of a1, not the bulk_configuration of a1.
So, is there any method to change the above script to get that ?

Thanks~

FangYong

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: How to use " nlread() " to read the scf only ?
« Reply #1 on: May 1, 2013, 10:49 »
There are two ways to do it. First of all, note that the "scf" is not a separate thing from the configuration. When you have run the self-consistent loop, the scf is stored on the configuration itself. So, if you want to use the approach to read the scf from the NC file, you would do like normal,
Code: python
scf = nlread("energy.nc", BulkConfiguration)[-1]
...
bulk_configuration.setCalculator(calculator, initial_state=scf)
There is however a better way to do it in your case. Since you are looping in the same script, you can just remember the state for the next step, like so:
Code: python
vector_a = [10.0, 0.0, 0.0]*Angstrom
vector_b = [0.0, 10.0, 0.0]*Angstrom
vector_c = [0.0, 0.0, 10.0]*Angstrom
lattice = UnitCell(vector_a, vector_b, vector_c)

# Define elements
elements = [Hydrogen]*2

scf = None    # NEW
for dis in (a1,a2,a3,a4):   # ai is the distance   
    fractional_coordinates = [[ 0.  ,  0.  ,  0.  ],
                                           [ 0.  ,  0.  ,  dis]]
    bulk_configuration = BulkConfiguration(
        bravais_lattice=lattice,
        elements=elements,
        fractional_coordinates=fractional_coordinates
        )

    calculator = LCAOCalculator()

    bulk_configuration.setCalculator(calculator, initial_state=scf)    # NEW
    bulk_configuration.update()
    scf = bulk_configuration    # NEW
    nlsave('energy.nc', bulk_configuration)

    total_energy = TotalEnergy(bulk_configuration)
    nlsave('energy.nc', total_energy)
    nlprint(total_energy)
Only 3 lines were modified, indicated by "NEW" above.

Offline fangyongxinxi

  • QuantumATK Guru
  • ****
  • Posts: 143
  • Reputation: 0
    • View Profile
Re: How to use " nlread() " to read the scf only ?
« Reply #2 on: May 1, 2013, 15:56 »
Thanks for your help~
There are two ways to do it. First of all, note that the "scf" is not a separate thing from the configuration. When you have run the self-consistent loop, the scf is stored on the configuration itself. So, if you want to use the approach to read the scf from the NC file, you would do like normal,
Code: python
scf = nlread("energy.nc", BulkConfiguration)[-1]
...
bulk_configuration.setCalculator(calculator, initial_state=scf)
There is however a better way to do it in your case. Since you are looping in the same script, you can just remember the state for the next step, like so:
Code: python
vector_a = [10.0, 0.0, 0.0]*Angstrom
vector_b = [0.0, 10.0, 0.0]*Angstrom
vector_c = [0.0, 0.0, 10.0]*Angstrom
lattice = UnitCell(vector_a, vector_b, vector_c)

# Define elements
elements = [Hydrogen]*2

scf = None    # NEW
for dis in (a1,a2,a3,a4):   # ai is the distance   
    fractional_coordinates = [[ 0.  ,  0.  ,  0.  ],
                                           [ 0.  ,  0.  ,  dis]]
    bulk_configuration = BulkConfiguration(
        bravais_lattice=lattice,
        elements=elements,
        fractional_coordinates=fractional_coordinates
        )

    calculator = LCAOCalculator()

    bulk_configuration.setCalculator(calculator, initial_state=scf)    # NEW
    bulk_configuration.update()
    scf = bulk_configuration    # NEW
    nlsave('energy.nc', bulk_configuration)

    total_energy = TotalEnergy(bulk_configuration)
    nlsave('energy.nc', total_energy)
    nlprint(total_energy)
Only 3 lines were modified, indicated by "NEW" above.