Technical Documentation
Utilities: Iterate over an AtomVector file

The AVRecords module provides an iterator for AtomVector files (AVF). Once the iterator object has been set up, a method of the object can be called to obtain the next AVF record, until the end of the file is reached. (This is a temporary implementation.)

The AVRecords module is located in Yup.Tools. Thus, the required import statement is: from Yup.Tools.AVRecords import AVRecords.


To use this object, first set up the iterator by creating the AVRecords object. Then, within an infinite loop, obtain or load the next record in the AVF by calling the nextavf() method. When the method signals the lack of a record, break out of the loop. Depending on how the iterator is set up, the values read from the AVF are loaded into an AtomVector of the model or is returned as an Anonymous AtomVector.

AVF = AVRecords( modelobject, avfname, options... )

while True:

nextrecord = AVF.nextavf()

if nextrecord: { process nextrecord }

else: break

A "for" loop cannot be used since this is not a proper iterator.


The AVRecords() constructor function creates an iterator object for an AVF.

Function Name
Number of Arguments
Return Value
AVRecords
2 required + 5 optional
The AVRecords object
Argument
Type
Preset Value
model
Model object
-
avfile
string or list of strings
-
limit None, Group AtomMap, or list of two integers None
dest string ""
first integer 1
every integer 1
final integer 0

The model argument must contain a complete Model object.

The avfile argument must be the name of an AVF that is compatible with model. This argument can also be a list (not a tuple) containing the names of AVF files, all of which must be compatible with model. The files will be processed in the order listed. The first and every arguments will be applied to each file independently, i.e., record numbering does not carry from one file to the next.

Please see the Targeted Simulation section of the Introduction to Simulation Methods to see how to set limit. The AtomVector is restricted to the range of atoms specified in limit.

The dest argument must be a string, blank or a single character "C", "G" or "V" only. If dest is a blank string, the records will be read from the AVF and returned as an Anonymous AtomVector. This cannot be mapped; but slicing can be accomplished by using the Extract function from Yup.Taro.AtomVect. If dest is a single character, each AVF record is read into one of three AtomVectors of model - "C" for Coordinates, "G" for Gradients and "V" for Velocities.

The first argument is a number indicating the first record to be read from the file. The records are numbered 1, 2 and so on.

Then, the value of the every argument is added to obtain the number of the next record to be read.

The value of the final argument, if greater than 0, is used to indicate the last record to be read.


The nextavf() method reads the next record in the AVF and returns an indication of success.

Method Name
Number of Arguments
Return Value
nextavf
0
AtomVector or success indicator

The return value can take three forms.

If a record is not read either because there is an error or the end of the file has been reached, the return value is None.

If a record is read and dest was a blank string, then the return value is an Anonymous AtomVector containing the record read from the AVF. If dest was a single character "C", "G" or "V", the record read from the AVF is loaded into one of the Coordinates, Gradients or Velocities AtomVectors of the model and the return value is 1.


The showlastread() method returns a tuple of two items: the name of the AVF file and the record number read in the previous successful call to nextavf().

Method Name
Number of Arguments
Return Value
showlastread
0
tuple

Obviously, calling this method makes sense only if the previous call to nextavf() yielded a non-null result.


In the following example, we go through four AVF files, and calculate the Linking Number for each record we find in each file. The "iterator" is constructed to read the data into the Coordinates AtomVector of the model, which means the nextavf() method returns only a truth value.

>>> from Yup.Models.rrDNAv1.FFA import Make3DNA
>>> from Yup.Models.rrDNAv1.Analyzer import Link
>>> from Yup.Tools.AVRecords import AVRecords
>>> M = Make3DNA( '360' )
>>> A = AVRecords( M, ['test0.av','test1.av','test2.av','test3.av'], dest="C" )
>>> while A.nextavf():
... print 'From FILE %s, RECORD # %d' % A.showlastread()
... Link( M )

If the file list is too long, construct it first and assign the list to a variable.


Technical
Introduction
Directory
Vectors
Energy
Model
Assembly
Methods
FPF
FFF
AVF
TaroScript
YammpScript
Python
Utilities

Home
Information
News
User
Technical
Programmer
iYup
Download
Showcase
ETC