Author Topic: Question about nlread usage  (Read 3332 times)

0 Members and 1 Guest are viewing this topic.

Offline Kaspar

  • Regular QuantumATK user
  • **
  • Posts: 19
  • Country: dk
  • Reputation: 0
    • View Profile
Question about nlread usage
« on: May 3, 2013, 05:07 »
Dear Forum, I am a little confused about how to properly use the nlread function. I have done a major calculation on a quite big system (120 atoms) which took days on my computer :), but I would like to redo the DOS and transmission. I got this example of how to load the "device configuration" from the .nc file that was saved to along the way
Code
device_configuration = nlread('file.nc', DeviceConfiguration)[-1]
I am not quite sure why the object type/name is DeviceConfiguration. Where can I see a list of suitable names usable for nlread? I would expect it to be 'device_configuration' since that is how it got saved in the original script (the standard when doing the script out the the Script Generator), or otherwise 'Device Configuration' as shown in the the VNL window when clicking on my .nc file. Otherwise, I can refer to the object handle eg. 'gID000', right? Lastly I do not know what the [-1] means. I learned that nlread gets a list (array?) and so you need to specify the element that you want to use, but how can that be [-1] ? In the VNL window I have two objects, 'Device Configuration' and 'Density of States'  (the one I wish to redo). I would expect that the device configuration would be [ 0 ] and DOS would be [1]. Is this correct/wrong? Thank you a lot! Kaspar
« Last Edit: May 3, 2013, 09:32 by Anders Blom »

Offline fangyongxinxi

  • QuantumATK Guru
  • ****
  • Posts: 143
  • Reputation: 0
    • View Profile
Re: Question about nlread usage
« Reply #1 on: May 3, 2013, 07:53 »
First, results in ".nc" file have a list form. For example, there are three "TotalEnergy" (e1,e2,e3) in you file.nc, you can use this line to read them: e_list = nlread ( 'aa.nc', TotalEnergy) e1=e_list[0] e2=e_list[1] e3=e_list[2]=e_list[-1] here the "-1" correspond to the last one, e3. Same thing, e2=e_list[-2] Second, if you want to read content by the object_id, and you want to get e2, so ,use this: e2 = nlread(filename = 'file.cn',object_id = '**')[0], "**" is the object_id of your e2, and the default value is "gID00*"
Dear Forum, I am a little confused about how to properly use the nlread function. I have done a major calculation on a quite big system (120 atoms) which took days on my computer :), but I would like to redo the DOS and transmission. I got this example of how to load the "device configuration" from the .nc file that was saved to along the way
Code
device_configuration = nlread('file.nc', DeviceConfiguration)[-1]
I am not quite sure why the object type/name is DeviceConfiguration. Where can I see a list of suitable names usable for nlread? I would expect it to be 'device_configuration' since that is how it got saved in the original script (the standard when doing the script out the the Script Generator), or otherwise 'Device Configuration' as shown in the the VNL window when clicking on my .nc file. Otherwise, I can refer to the object handle eg. 'gID000', right? Lastly I do not know what the [-1] means. I learned that nlread gets a list (array?) and so you need to specify the element that you want to use, but how can that be [-1] ? In the VNL window I have two objects, 'Device Configuration' and 'Density of States'  (the one I wish to redo). I would expect that the device configuration would be
  • and DOS would be [1]. Is this correct/wrong?
Thank you a lot! Kaspar

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5411
  • Country: dk
  • Reputation: 89
    • View Profile
    • QuantumATK at Synopsys
Re: Question about nlread usage
« Reply #2 on: May 3, 2013, 09:34 »
Good answer, hope everything is clear now, Kaspar.

Just a note: there is no default for the object_id. If you don't give this argument, it's not used, i.e. you either get all contents of the file, or all objects of the specified type. For instance, use nlread("file.nc", TotalEnergy) to get all TotalEnergy objects in the file (in a list).

Note on my modification of the original post above: Using [ 0 ] without spaces causes the Forum rendering engine to display
  • .


To get [0], use [nobbc][0][/nobbc], or use spaces.

Offline Kaspar

  • Regular QuantumATK user
  • **
  • Posts: 19
  • Country: dk
  • Reputation: 0
    • View Profile
Re: Question about nlread usage
« Reply #3 on: May 3, 2013, 18:41 »
Thank you both!

Still I would like to see if there is a list of all the types of objects that can be called with nlread. Like 'TotalEnergy', 'DeviceConfiguration' etc. Or are they all just that intuitive, ie. the name without spaces?

As a reference to other people who might have questions about the negative index, I realized that the negative index is a property of Python and found this link which explains it: http://docs.python.org/2/tutorial/introduction.html#lists


Edit: Minor typos

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5411
  • Country: dk
  • Reputation: 89
    • View Profile
    • QuantumATK at Synopsys
Re: Question about nlread usage
« Reply #4 on: May 4, 2013, 00:36 »
Negative index, yes this is very standard Python. As for nlread, it's fairly transparent: any class you can nlsave, can be nlread. So that's all the Analysis stuff you see in the Script Generator, basically, and configurations of course, plus a few more exotic things. But there is nlinspect. You can do this on a NC file:
Code: python
from NL.IO.NLSaveUtilities import nlinspect
nlinspect("file.nc")
and you might see something like
Quote
array([['Bandstructure', 'gID001'],        ['Bandstructure', 'gID004'],        ['BulkConfiguration', 'gID000'],        ['BulkConfiguration', 'gID003'],        ['MullikenPopulation', 'gID002'],        ['MullikenPopulation', 'gID005']],       dtype='|S18')
Then you know what's in the file. You can also do
Code: python
from NL.IO.NLSaveUtilities import nlinspect
file_objects = nlinspect("file.nc")

# Make a data dictionary from the NC file
data_dict = {}
for file_object in file_objects:
    object_type = file_object[0]
    id = file_object[1]
    data_dict[id] = { 'data' : nlread("file.nc", object_id=id)[0], 'type' : object_type}

# Print data dictionary
data_dict
This might produce something like
Quote
{'gID000': {'data': <NL.CommonConcepts.Configurations.BulkConfiguration.BulkConfiguration object at 0x000000000D845C18>,             'type': 'BulkConfiguration'},  'gID001': {'data': <NL.Analysis.Bandstructure.Bandstructure object at 0x000000000DB6ED68>,             'type': 'Bandstructure'},  'gID002': {'data': <NL.Analysis.MullikenPopulation.MullikenPopulation object at 0x000000000DB6E3C8>,             'type': 'MullikenPopulation'},  'gID003': {'data': <NL.CommonConcepts.Configurations.BulkConfiguration.BulkConfiguration object at 0x000000000DB6EDD8>,             'type': 'BulkConfiguration'},  'gID004': {'data': <NL.Analysis.Bandstructure.Bandstructure object at 0x000000000DB6EC88>,             'type': 'Bandstructure'},  'gID005': {'data': <NL.Analysis.MullikenPopulation.MullikenPopulation object at 0x000000000DB6EEB8>,             'type': 'MullikenPopulation'}}
which could be useful to keep track of objects etc.