Author Topic: KeyError  (Read 4349 times)

0 Members and 1 Guest are viewing this topic.

Offline sergio

  • Heavy QuantumATK user
  • ***
  • Posts: 56
  • Reputation: 0
    • View Profile
KeyError
« on: February 10, 2010, 21:56 »
Hi,

I have an input:

....
system = "system_name"
vnlfile=VNLFile(system + ".vnl")
twoprobe_config=vnlfile.readAtomicConfigurations()[system]
....

Upon running I get the following error:

Traceback (most recent call last):
  File "system_name_file.py", line 7, in ?
    twoprobe_config=vnlfile.readAtomicConfigurations()[system]
KeyError: 'system_name'

What can be the reason?
Thanks

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5429
  • Country: dk
  • Reputation: 89
    • View Profile
    • QuantumATK at Synopsys
Re: KeyError
« Reply #1 on: February 10, 2010, 22:14 »
For this code to work, you would have had to save the configuration to the VNL with the name "system_name". If you know that the VNL file only contains a single configuration, you can always use the construction
Code
...
vnlfile=VNLFile("file.vnl")
configs=vnlfile.readAtomicConfigurations()
twoprobe_config=configs[configs.keys()[0]]
where "file.vnl" should be the proper name of the VNL file. Otherwise, if you forgot the name used to store the configuration, use this code:
Code
...
vnlfile=VNLFile("file.vnl")
configs=vnlfile.readAtomicConfigurations()
print configs.keys()
This will print the configuration name; let's say it is "my_system". Then use that in
Code
twoprobe_config=vnlfile.readAtomicConfigurations()["my_system"]
You can also open the VNL file in the Result Browser in VNL, then you will see the configuration name.

Offline sergio

  • Heavy QuantumATK user
  • ***
  • Posts: 56
  • Reputation: 0
    • View Profile
Re: KeyError
« Reply #2 on: February 11, 2010, 09:17 »
Dr. Blom,

Thanks for your reply, however when I use:
...
vnlfile=VNLFile("file.vnl")
configs=vnlfile.readAtomicConfigurations()
twoprobe_config=configs[configs.keys()[0]]

I get:

Traceback (most recent call last):
  File "Li_SW15_2-Trans.Spec.py", line 9, in ?
    twoprobe_config=configs[configs.keys()[0]]
IndexError: list index out of range

And, when I try to get the configuration name using
...
vnlfile=VNLFile("file.vnl")
configs=vnlfile.readAtomicConfigurations()
print configs.keys()

I get only []

Besides that I have also used the configuration name in the Result Browser in VNL and again it gives KeyError.

Is there any other reason?

Thanks,

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5429
  • Country: dk
  • Reputation: 89
    • View Profile
    • QuantumATK at Synopsys
Re: KeyError
« Reply #3 on: February 11, 2010, 09:21 »
Most likely only the results are stored in the VNL file, not the geometry. This typically happens for PeriodicAtomConfigurations, like nanotubes, if you are unlucky...

Is the VNL file large? You can email it to me and I can check.

Did you lose the script used to run the calculation? Is there any other way to restore the geometry?

Offline sergio

  • Heavy QuantumATK user
  • ***
  • Posts: 56
  • Reputation: 0
    • View Profile
Re: KeyError
« Reply #4 on: February 18, 2010, 12:03 »
Dr. Blom,

Sorry for late reply, I was dealing with some reports....Actually I have just realized that upon defining the exact path of the vnl file, the code that you have written works!

Thanks,

Offline hellboy

  • Heavy QuantumATK user
  • ***
  • Posts: 47
  • Reputation: 0
    • View Profile
Re: KeyError
« Reply #5 on: November 15, 2010, 10:27 »
Dear Sir, I was trying to obtain the atoms in the central region for nanotube using the below mentioned code:
Code
from ATK.TwoProbe import *
from displayCentralRegion import displayCentralRegionAtoms

vnl_file=VNLFile("CNT.vnl")
atomic_configuration_dict = vnl_file.readAtomicConfigurations()
atomic_configuration = atomic_configuration_dict["twoprobe_configuration"]
displayCentralRegionAtoms(atomic_configuration)
      
then i tried using code mentioned below, but got errors:
Code
...
vnlfile=VNLFile("file.vnl")
configs=vnlfile.readAtomicConfigurations()
twoprobe_config=configs[configs.keys()[0]]
I get:
Code
  File "Li_SW15_2-Trans.Spec.py", line 9, in ?
    twoprobe_config=configs[configs.keys()[0]]
IndexError: list index out of range
Traceback (most recent call last):
And, when I try to get the configuration name using
Code
...
vnlfile=VNLFile("file.vnl")
configs=vnlfile.readAtomicConfigurations()
print configs.keys()

I get only [] How do i obtain the central region atoms with periodic_atom_configuration such as in nanotubes?

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5429
  • Country: dk
  • Reputation: 89
    • View Profile
    • QuantumATK at Synopsys
Re: KeyError
« Reply #6 on: November 15, 2010, 11:00 »
And, when I try to get the configuration name using
Code
...
vnlfile=VNLFile("file.vnl")
configs=vnlfile.readAtomicConfigurations()
print configs.keys()

I get only []
Then the VNL file does not contain any configurations. To extract a configuration from a VNL file, the easiest way is to use the Result Browser in VNL, and not use these complex scripts. Just open the file in the Result Browser, select the configuration and you will see the Python code that defines it.