コード例 #1
0
ファイル: reducecoordinates.py プロジェクト: suliat16/biskit
class Test(BT.BiskitTest):
    """Test"""

    def test_ReduceCoordinates(self):
        """ReduceCoordinates test"""

        self.m = PDBModel( T.testRoot()+'/com/1BGS.pdb' )
        self.m = self.m.compress( N0.logical_not( self.m.maskH2O() ) )

        self.m.atoms.set('test', list(range(len(self.m))))

        self.red = ReduceCoordinates( self.m, 4 )

        self.mred = self.red.reduceToModel()
        
        if self.local:
            print('\nAtoms before reduction %i'% self.m.lenAtoms())
            print('Atoms After reduction %i'% self.mred.lenAtoms())

        self.assertEqual( self.mred.lenAtoms(), 445 )
コード例 #2
0
class Test(BT.BiskitTest):
    """Test case"""
    def test_surfaceRacerTools(self):
        """surfaceRacerTools test"""
        from biskit import PDBModel
        import biskit.tools as T

        ## load a structure
        self.m = PDBModel(T.testRoot() + '/lig/1A19.pdb')
        self.m = self.m.compress(self.m.maskProtein())
        self.m = self.m.compress(self.m.maskHeavy())

        ## some fake surface data
        surf = N0.ones(self.m.lenAtoms()) * 10.0

        relExp = relExposure(self.m, surf)

        ##         if self.local:
        ##             globals().update( locals() )

        self.assertAlmostEqual(N0.sum(relExp), 44276.86085222386, 8)
コード例 #3
0
ファイル: surfaceRacerTools.py プロジェクト: graik/biskit
class Test(BT.BiskitTest):
    """Test case"""

    def test_surfaceRacerTools(self):
        """surfaceRacerTools test"""
        from biskit import PDBModel
        import biskit.tools as T
        
        ## load a structure
        self.m = PDBModel( T.testRoot()+'/lig/1A19.pdb' )
        self.m = self.m.compress( self.m.maskProtein() )
        self.m = self.m.compress( self.m.maskHeavy() )
        
        ## some fake surface data
        surf = N0.ones( self.m.lenAtoms()) * 10.0

        relExp = relExposure( self.m, surf )
        
##         if self.local:
##             globals().update( locals() )
            
        self.assertAlmostEqual( N0.sum(relExp), 44276.86085222386, 8 )
コード例 #4
0
ファイル: amberCrdParser.py プロジェクト: suliat16/biskit
class AmberCrdParser:
    """
    Convert an Amber-generated crd file into a Trajectory object.
    """
    def __init__(self,
                 fcrd,
                 fref,
                 box=0,
                 rnAmber=0,
                 pdbCode=None,
                 log=StdLog(),
                 verbose=0):
        """
        :param fcrd: path to input coordinate file
        :type  fcrd: str
        :param fref: PDB or pickled PDBModel with same atom content and order
        :type  fref: str
        :param box: expect line with box info at the end of each frame
                    (default: 0)
        :type  box: 1|0
        :param rnAmber: rename amber style residues into standard (default: 0)
        :type  rnAmber: 1|0
        :param pdbCode: pdb code to be put into the model (default: None)
        :type  pdbCode: str
        :param log: LogFile instance [Biskit.StdLog]
        :type  log: biskit.LogFile
        :param verbose: print progress to log [0]
        :type  verbose: int
        """
        self.fcrd = T.absfile(fcrd)
        self.crd = T.gzopen(self.fcrd)

        self.ref = PDBModel(T.absfile(fref), pdbCode=pdbCode)
        self.box = box

        self.n = self.ref.lenAtoms()

        self.log = log
        self.verbose = verbose

        if rnAmber:
            self.ref.renameAmberRes()

        ## pre-compile pattern for line2numbers
        xnumber = "-*\d+\.\d+"  # optionally negtive number
        xspace = ' *'  # one or more space char
        self.xnumbers = re.compile('(' + xspace + xnumber + ')')

        ## pre-compute lines expected per frame
        self.lines_per_frame = self.n * 3 // 10

        if self.n % 10 != 0: self.lines_per_frame += 1
        if self.box: self.lines_per_frame += 1

        ## mark chains (the TER position might get lost when deleting atoms)
        ## should not be necessary any longer


##        if not self.ref.getAtoms()[0].get('chain_id',''):
##            self.ref.addChainId()

    def line2numbers(self, l):
        """
        convert a line from crd/vel file to list of float numbers
        
        :param l: line
        :type  l: str
        
        :return: list of floats
        :rtype: [float]
        """
        match = self.xnumbers.findall(l)

        return [round(float(strCrd), 3) for strCrd in match]

    def nextLine(self):
        """
        extract next 10 coordinates from crd file

        :return: coordinates
        :rtype: [float]    
        """
        l = self.crd.readline()
        if l == '':
            raise EOFError('EOF')

        return self.line2numbers(l)

    def nextFrame(self):
        """
        Collect next complete coordinate frame

        :return: coordinate frame
        :rtype: array
        """

        i = 0
        xyz = []
        while i != self.lines_per_frame:

            if self.box and i + 1 == self.lines_per_frame:

                ## skip box info
                if len(self.nextLine()) != 3:
                    raise ParseError("BoxInfo must consist of 3 numbers.")

            else:
                xyz += self.nextLine()

            i += 1

        return N.reshape(xyz, (len(xyz) // 3, 3)).astype(N.float)

    def crd2traj(self):
        """
        Convert coordinates into a Trajectory object.

        :return: trajectory object
        :rtype: Trajectory
        """
        ## skip first empty line
        self.crd.readline()

        xyz = []
        i = 0

        if self.verbose: self.log.write("Reading frames ..")

        try:
            while 1 == 1:

                xyz += [self.nextFrame()]
                i += 1

                if i % 100 == 0 and self.verbose:
                    self.log.write('#')

        except EOFError:
            if self.verbose: self.log.write("Read %i frames.\n" % i)

        t = Trajectory(refpdb=self.ref)

        t.frames = N0.array(xyz).astype(N0.Float32)

        t.setRef(self.ref)
        t.ref.disconnect()

        return t
コード例 #5
0
ファイル: amberCrdParser.py プロジェクト: graik/biskit
class AmberCrdParser:
    """
    Convert an Amber-generated crd file into a Trajectory object.
    """

    def __init__( self, fcrd, fref, box=0, rnAmber=0, pdbCode=None,
                  log=StdLog(), verbose=0 ):
        """
        :param fcrd: path to input coordinate file
        :type  fcrd: str
        :param fref: PDB or pickled PDBModel with same atom content and order
        :type  fref: str
        :param box: expect line with box info at the end of each frame
                    (default: 0)
        :type  box: 1|0
        :param rnAmber: rename amber style residues into standard (default: 0)
        :type  rnAmber: 1|0
        :param pdbCode: pdb code to be put into the model (default: None)
        :type  pdbCode: str
        :param log: LogFile instance [Biskit.StdLog]
        :type  log: biskit.LogFile
        :param verbose: print progress to log [0]
        :type  verbose: int
        """
        self.fcrd = T.absfile( fcrd )
        self.crd  = T.gzopen( self.fcrd )

        self.ref  = PDBModel( T.absfile(fref), pdbCode=pdbCode )
        self.box  = box

        self.n = self.ref.lenAtoms()

        self.log = log
        self.verbose = verbose

        if rnAmber:
            self.ref.renameAmberRes()

        ## pre-compile pattern for line2numbers
        xnumber = "-*\d+\.\d+"              # optionally negtive number
        xspace  = ' *'                      # one or more space char
        self.xnumbers = re.compile('('+xspace+xnumber+')')

        ## pre-compute lines expected per frame
        self.lines_per_frame = self.n * 3 // 10

        if self.n % 10 != 0:  self.lines_per_frame += 1
        if self.box:          self.lines_per_frame += 1

        ## mark chains (the TER position might get lost when deleting atoms)
        ## should not be necessary any longer
##        if not self.ref.getAtoms()[0].get('chain_id',''):
##            self.ref.addChainId()

    def line2numbers( self, l ):
        """
        convert a line from crd/vel file to list of float numbers
        
        :param l: line
        :type  l: str
        
        :return: list of floats
        :rtype: [float]
        """
        match = self.xnumbers.findall( l )

        return [ round( float(strCrd),3) for strCrd in match ] 


    def nextLine( self ):
        """
        extract next 10 coordinates from crd file

        :return: coordinates
        :rtype: [float]    
        """
        l = self.crd.readline()
        if l == '':
            raise EOFError('EOF')

        return self.line2numbers( l )


    def nextFrame( self ):
        """
        Collect next complete coordinate frame

        :return: coordinate frame
        :rtype: array
        """

        i = 0
        xyz = []
        while i != self.lines_per_frame:

            if self.box and i+1 == self.lines_per_frame:

                ## skip box info
                if len( self.nextLine() ) != 3:
                    raise ParseError( "BoxInfo must consist of 3 numbers." )

            else:
                xyz += self.nextLine()

            i += 1

        return N.reshape( xyz, ( len(xyz) // 3, 3 ) ).astype(N.float)


    def crd2traj( self ):
        """
        Convert coordinates into a Trajectory object.

        :return: trajectory object
        :rtype: Trajectory
        """
        ## skip first empty line
        self.crd.readline()

        xyz = []
        i = 0

        if self.verbose: self.log.write( "Reading frames .." )

        try:
            while 1==1:

                xyz += [ self.nextFrame() ]
                i += 1

                if i % 100 == 0 and self.verbose:
                    self.log.write( '#' )

        except EOFError:
            if self.verbose: self.log.write("Read %i frames.\n" % i)

        t = Trajectory( refpdb=self.ref )

        t.frames = N0.array( xyz ).astype(N0.Float32)

        t.setRef( self.ref )
        t.ref.disconnect()

        return t