예제 #1
0
 def open_old(cls, fname):
     """
     Opens the NetCDF file and sets the global attributes that the file sets
     """
     inst = cls(fname, 'r')
     ncfile = inst._ncfile
     inst.Conventions = ncfile.Conventions
     inst.ConventionVersion = ncfile.ConventionVersion
     inst.application = ncfile.application
     inst.program = ncfile.program
     inst.programVersion = ncfile.programVersion
     inst.title = ncfile.title
     # Set up the dimensions as attributes
     for dim in ncfile.dimensions:
         # Exception for ParmEd-created ncrst files
         if dim == 'time': continue
         setattr(inst, dim, amber.get_int_dimension(ncfile, dim))
     inst.hasvels = 'velocities' in ncfile.variables
     inst.hasbox = ('cell_lengths' in ncfile.variables and
                     'cell_angles' in ncfile.variables)
     if inst.hasvels:
         vels = ncfile.variables['velocities']
         inst.velocity_scale = vels.scale_factor
         # Turn off automatic scaling for netCDF4. Ugh.
         try:
             vels.set_auto_maskandscale(False)
         except AttributeError:
             # Other packages do not have this variable
             pass
     return inst
예제 #2
0
    def open_old(cls, fname):
        """
        Opens the NetCDF file and sets the global attributes that the file sets

        Parameters:
            -  fname (string): File name of the trajectory to open. It must
                               exist
        """
        inst = cls(fname, 'r')
        ncfile = inst._ncfile
        inst.Conventions = ncfile.Conventions
        inst.ConventionVersion = ncfile.ConventionVersion
        inst.application = ncfile.application
        inst.program = ncfile.program
        inst.programVersion = ncfile.programVersion
        inst.title = ncfile.title
        # Set up the dimensions as attributes
        for dim in ncfile.dimensions:
            setattr(inst, dim, amber.get_int_dimension(ncfile, dim))
        inst.hascrds = 'coordinates' in ncfile.variables
        inst.hasvels = 'velocities' in ncfile.variables
        inst.hasfrcs = 'forces' in ncfile.variables
        inst.hasbox = ('cell_lengths' in ncfile.variables and
                       'cell_angles' in ncfile.variables)
        if inst.hasvels:
            inst.velocity_scale = ncfile.variables['velocities'].scale_factor
        if inst.frame is None:
            if 'time' in ncfile.variables:
                inst.frame = len(ncfile.variables['time'][:])
            elif inst.hascrds:
                inst.frame = len(ncfile.variables['coordinates'][:])
            elif inst.hasvels:
                inst.frame = len(ncfile.variables['velocities'][:])
            elif inst.hasfrcs:
                inst.frame = len(ncfile.variables['forces'][:])
        return inst