Author Topic: how should i write a script to specify the different initial_scaled_spin  (Read 4184 times)

0 Members and 1 Guest are viewing this topic.

Offline njuxyh

  • QuantumATK Guru
  • ****
  • Posts: 163
  • Reputation: 0
    • View Profile
how should i write a script to specify the different initial_scaled_spin for different atoms in differnt region (has some rules)
hi. i have wrote a script including below small code:
for index in range(len(scattering_elements)):
        if (scattering_elements[index]=="Carbon") :
                if (scattering_coordinates[index][2]> 17):
                      scattering_region_initial_scaled_spin[index]=1
                elif  (scattering_coordinates[index][2]< 13):
                       scattering_region_initial_scaled_spin[index]=1
        else:
           scattering_region_initial_scaled_spin[index]=0

this code is used to specify initial_scaled_spin for the atoms in scattering region(obey some rules see the if

language), but there is errror:
Traceback (most recent call last):
  File "two-my-own-scf-ALL-DZP.py", line 143, in ?
    scattering_region_initial_scaled_spin[index]=0
NameError: name 'scattering_region_initial_scaled_spin' is not defined
how should i revised my code, i have a look at the manual ATK(2008)Page 215, the script is similar to mine, but

still can not find a way to solve.
ps: i am a beginner in python.

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Start by setting "scattering_region_initial_scaled_spin" to zero for all atoms, then your code will go in and change some atoms to another value. So, something like
Code: python
scattering_region_initial_scaled_spin = [0,]*len(scattering_elements)
for index in range(len(scattering_elements)):
        if (scattering_elements[index]==Carbon) :
                if (scattering_coordinates[index][2]> 17):
                      scattering_region_initial_scaled_spin[index]=1
                elif  (scattering_coordinates[index][2]< 13):
                       scattering_region_initial_scaled_spin[index]=1
(You don't need the "else" part any more now :) )
« Last Edit: January 15, 2011, 22:19 by Anders Blom »

Offline njuxyh

  • QuantumATK Guru
  • ****
  • Posts: 163
  • Reputation: 0
    • View Profile
thank you Anders Blom
i have revised my code following you suggestion.
scattering_region_initial_scaled_spin = [0,]*len(scattering_elements)
 
for index in range(len(scattering_elements)):
        if (scattering_elements[index]=="Carbon") :
                if (scattering_coordinates[index][2]> 17):
                      scattering_region_initial_scaled_spin[index]=1
                elif  (scattering_coordinates[index][2]< 13):
                       scattering_region_initial_scaled_spin[index]=1
but a strange things happed. the for ...if ... language does not work. all the scattering_region_initial_scaled_spin are set to 0 in my output
Initial Scaled Spin = (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

my scattering_elements and corresponding scattering_coordinates are following, i can make sure there are atoms fit the if condition (the atoms are carbon and their y coordinates are larger than 17 or less than 13), and of course, these atoms initial_scaled_spin should be labled 1. but the output shows not. i do not know why? please give me some hints. thanks a lot!!!!
scattering_elements = [Hydrogen, Carbon,   Carbon,   Carbon,
                       Carbon,   Hydrogen, Carbon,   Carbon,
                       Carbon,   Carbon,   Hydrogen, Carbon,
                       Carbon,   Carbon,   Carbon,   Hydrogen,
                       Carbon,   Carbon,   Carbon,   Carbon,
                       Hydrogen, Carbon,   Carbon,   Carbon,
                       Carbon,   Hydrogen, Carbon,   Carbon,
                       Carbon,   Carbon,   Hydrogen, Carbon,
                       Carbon,   Carbon,   Carbon,   Hydrogen,
                       Carbon,   Carbon,   Carbon,   Carbon,
                       Hydrogen, Hydrogen, Carbon,   Hydrogen,

,,,,,
and scattering_coordinates = [[  0.00000000e+00+5.0,   0.00000000e+00+20.0,   9.83800000e+00],
                          [ -1.22989401e-15+5.0,  -1.12843802e+00+20.0,   9.85067344e+00],
                          [ -2.94995475e-15+5.0,  -3.92924460e+00+20.0,   9.85627415e+00],
                          [ -4.66985681e-15+5.0,  -5.36743000e+00+20.0,   9.86150159e+00],
                          [ -5.47776181e-16+5.0,  -8.20440839e+00+20.0,   9.84598938e+00],
                          [  7.14895909e-16+5.0,  -9.36487852e+00+20.0,   9.81171705e+00],
                          [ -2.17900005e-15+5.0,  -1.78728400e+00+20.0,   1.10995077e+01],
                          [ -2.86524241e-15+5.0,  -3.23383319e+00+20.0,   1.11043162e+01],
                          [ -2.38880286e-15+5.0,  -6.08197662e+00+20.0,   1.11053456e+01],
                          [  1.62864277e-15+5.0,  -7.53795350e+00+20.0,   1.10969972e+01],
                          [ -1.10737121e-15+5.0,   9.41494265e-02+20.0,   1.23040920e+01],
                          [ -3.10119238e-15+5.0,  -1.06706289e+00+20.0,   1.23230761e+01],
                          [ -2.21118463e-15+5.0,  -3.93739872e+00+20.0,   1.23453547e+01],
                          [  9.63002055e-16+5.0,  -5.37828650e+00+20.0,   1.23518140e+01],
.......

Offline kstokbro

  • Supreme QuantumATK Wizard
  • *****
  • Posts: 392
  • Reputation: 13
    • View Profile
    • QuantumWise
try writing Carbon instead of "Carbon"

Offline njuxyh

  • QuantumATK Guru
  • ****
  • Posts: 163
  • Reputation: 0
    • View Profile
thank you it is the problem exists
and another problem is the 17, it should be written 17ang , including the unit.