Author Topic: some bugs in my script  (Read 6305 times)

0 Members and 1 Guest are viewing this topic.

Offline fanjiaping

  • Heavy QuantumATK user
  • ***
  • Posts: 67
  • Reputation: 0
    • View Profile
some bugs in my script
« on: November 21, 2010, 05:46 »
Dear: 
   I want to adjust the distance between the electrode and molecule. Here ,A central region, contained Lithium and Hydrogen, was adopted as my example. The file "li_h2_prototype.py" is the script got from the VNL without any change !
the second script "test.py" is the script which I want to test my code.
I split the central region into three parts,first part contained the left five Lithium atoms, second part contained two hydrogen atoms, third part contained right five lithium.
first:
     I adjust the distance between the first part and second part by moving the coordinates of second part and third part.(if coordinate[2]>=12.1*Ang:
                                     coordinate[2]+=add*Ang)
second:
      I adjust the distance between the second part and third part by moving the coordinates of  third part. ( if coordinate[2]>(12.8+add)*Ang:
            coordinate[2]+=add*Ang)
third :
     we get the new coordinates to define the new central_region_coordinates, then get the central_region.
    But maybe here exist some errors. So, could you give me some guidance?

Thank you!

Offline zh

  • Supreme QuantumATK Wizard
  • *****
  • Posts: 1141
  • Reputation: 24
    • View Profile
Re: some bugs in my script
« Reply #1 on: November 21, 2010, 12:08 »
As for how to update the coordinates of atoms, please refer to the examples demonstrated in the manual:
http://www.quantumwise.com/documents/manuals/ATK-2008.10/chap.litwoprobe.html

Quote
    for coordinate in central_region_coordinates:
        if coordinate[2]>=12.1*Ang:
            coordinate[2]+=add*Ang
        if coordinate[2]>(12.8+add)*Ang:
            coordinate[2]+=add*Ang

The variable of "central_region_coordinates" has PhysicalQuantity, so it cannot be used directly in the logic manipulation.

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: some bugs in my script
« Reply #2 on: November 21, 2010, 21:37 »
I always prefer (esp. in 2008.10) to manipulate coordinates without units, i.e. to strip all units off first, then do the arithmetic, and finally just put the unit back on, in the end (one global "*Ang").

Offline fanjiaping

  • Heavy QuantumATK user
  • ***
  • Posts: 67
  • Reputation: 0
    • View Profile
Re: some bugs in my script
« Reply #3 on: November 22, 2010, 00:38 »
yeah! I also want to strip the unit. but the problem is ,for example in my adopted prototype, the function coordinate.strip(Ang) can't pass through the ATK interpreter!

Offline fanjiaping

  • Heavy QuantumATK user
  • ***
  • Posts: 67
  • Reputation: 0
    • View Profile
Re: some bugs in my script
« Reply #4 on: November 22, 2010, 05:17 »
As for how to update the coordinates of atoms, please refer to the examples demonstrated in the manual:
http://www.quantumwise.com/documents/manuals/ATK-2008.10/chap.litwoprobe.html

Quote
    for coordinate in central_region_coordinates:
        if coordinate[2]>=12.1*Ang:
            coordinate[2]+=add*Ang
        if coordinate[2]>(12.8+add)*Ang:
            coordinate[2]+=add*Ang

The variable of "central_region_coordinates" has PhysicalQuantity, so it cannot be used directly in the logic manipulation.
I am afraid the tutorial of manuals/ATK-2008.10/chap.litwoprobe.html can't work on my investgate system. the example show the code as:
   positions = [
    (0.0, 0.0, 0*a),
    (0.0, 0.0, 1*a),
    (0.0, 0.0, 2*a),
    (0.0, 0.0, 2*a + dist_LiH),
    (0.0, 0.0, 2*a + dist_LiH + dist_HH),
    (0.0, 0.0, 2*a + dist_LiH + dist_HH + dist_LiH + 0*a),
    (0.0, 0.0, 2*a + dist_LiH + dist_HH + dist_LiH + 1*a),
    (0.0, 0.0, 2*a + dist_LiH + dist_HH + dist_LiH + 2*a)
    ] * Angstrom

 which is enough to simple system. If I have hundreds of atom , Adjusting the atomic coordinate by using this way is so tedious!  So can you give me a example about how to use the condition to control the variate on the atomic coordinate?

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: some bugs in my script
« Reply #5 on: November 22, 2010, 09:23 »
I think your prototype test.py is pretty much what you need. The only thing to change is to forget all about "Ang" regarding all coordinates, until you reach the point when you make the BulkConfigurations. So, for example
Code: python
for add in [0.1,0.2,0.3,0.4]:
    vector_a = [10.0, 0.0, 0.0]
    vector_b = [0.0, 10.0, 0.0]
    vector_c = [0.0, 0.0, 24.9]
    vector_c[2]+=2*add
    print vector_c
    central_region_lattice = UnitCell(vector_a*Ang, vector_b*Ang, vector_c*Ang)
    for coordinate in central_region_coordinates:
        if coordinate[2]>=12.1:
            coordinate[2]+=add
        if coordinate[2]>(12.8+add):
            coordinate[2]+=add
        
        
central_region = BulkConfiguration(
    bravais_lattice=central_region_lattice,
    elements=central_region_elements,
    cartesian_coordinates=coordinate*Ang
    )
        
device_configuration = DeviceConfiguration(
    central_region,
    [left_electrode, right_electrode]
    )
Be careful about your indentation, it's a bit hard to see the logic in the script. As it stands, "central_region = BulkConfiguration" is part of the loop "for coordinate in central_region_coordinates", that's perhaps not your intention? If you are using ATK 10.8, units are stripped off using the method "inUnitsOf":
Code: python
coords = central_region_coordinates.inUnitsOf(Ang)
although you don't really need that if you just don't introduce "Ang" until the "BulkConfiguration" calls. Oh, and one more thing: the use of "+=" can be dangerous! Try to avoid it when operating on arrays, even if it means writing a bit more:
Code: python
coordinate[2] = coordinate[2]+add

Offline fanjiaping

  • Heavy QuantumATK user
  • ***
  • Posts: 67
  • Reputation: 0
    • View Profile
Re: some bugs in my script
« Reply #6 on: November 22, 2010, 11:08 »
   I modify my script following your advices. But it still doesn't work. (:-[ :-[ :-[(it nearly drive me crazy!))
   the code:
   central_region = BulkConfiguration( 
    bravais_lattice=central_region_lattice, 
    elements=central_region_elements, 
    cartesian_coordinates=coordinate*Ang 
    ) 
         
device_configuration = DeviceConfiguration( 
    central_region, 
    [left_electrode, right_electrode] 
    ) 

is  part of the loop   "for add in [0.1,0.2,0.3,0.4]:  "


the code after modify :
central_region_coordinates=central_region_coordinates.inUnitsOf(Ang)
for add in [0.1,0.2,0.3,0.4]:
    vector_a = [10.0, 0.0, 0.0]*Angstrom
    vector_b = [0.0, 10.0, 0.0]*Angstrom
    vector_c = [0.0, 0.0, 24.9]*Angstrom
    vector_c[2]+=2*add*Ang
    print vector_c
    central_region_lattice = UnitCell(vector_a, vector_b, vector_c)
    for coordinate in central_region_coordinates:
        if coordinate[2]>=12.1:
            coordinate[2]=coordinate[2]+add
        if coordinate[2]>(12.8+add):
            coordinate[2]=coordinate[2]+add
    central_region = BulkConfiguration(
    bravais_lattice=central_region_lattice,
    elements=central_region_elements,
    cartesian_coordinates=coordinate*Ang
    )
    device_configuration = DeviceConfiguration(
    central_region,
    [left_electrode, right_electrode]
    )

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: some bugs in my script
« Reply #7 on: November 22, 2010, 13:07 »
I understand it can be frustrating sometimes. Sometimes it's better to take a step back and consider what it really is you want to achieve. As I understand it, you want to introduce a variable Li-H distance, is that correct? If so, consider the attached script as an alternative. However, there is only a minor issue with your script, if you want to learn from it. The problem is that "coordinate" is not what you want it to be; I changed your loop to
Code: python
    coordinate = central_region_coordinates.inUnitsOf(Ang)
    for j in range(len(coordinate)):
        if coordinate[j][2]>=12.1:
            coordinate[j][2]=coordinate[j][2]+add
        if coordinate[j][2]>(12.8+add):
            coordinate[j][2]=coordinate[j][2]+add
I trust you can see the difference! :)

Offline fanjiaping

  • Heavy QuantumATK user
  • ***
  • Posts: 67
  • Reputation: 0
    • View Profile
Re: some bugs in my script
« Reply #8 on: November 22, 2010, 14:33 »
 :'(  thank you! utimately, I see the information that "NanoLanguageScript finished successfully "