~ubuntu-branches/debian/sid/mgltools-molkit/sid

« back to all changes in this revision

Viewing changes to MolKit/pdbWriter.py

  • Committer: Bazaar Package Importer
  • Author(s): Steffen Moeller
  • Date: 2011-06-17 01:20:19 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110617012019-xiksl9rlwu5qkhpk
Tags: 1.5.6~rc1+cvs.20110617-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
#############################################################################
8
8
 
9
9
#
10
 
# $Header: /opt/cvs/python/packages/share1.5/MolKit/pdbWriter.py,v 1.22.4.2 2011/04/07 23:01:32 rhuey Exp $
 
10
# $Header: /opt/cvs/python/packages/share1.5/MolKit/pdbWriter.py,v 1.27 2011/06/09 19:45:45 sanner Exp $
11
11
#
12
 
# $Id: pdbWriter.py,v 1.22.4.2 2011/04/07 23:01:32 rhuey Exp $
 
12
# $Id: pdbWriter.py,v 1.27 2011/06/09 19:45:45 sanner Exp $
13
13
#
14
14
 
15
15
from MolKit.moleculeWriter import MoleculeWriter
46
46
        # All the PDB records in order
47
47
        self.PDBRECORDS = ['HEADER', 'OBSLTE','TITLE', 'CAVEAT',
48
48
                           'COMPND', 'SOURCE','KEYWDS', 'EXPDTA',
49
 
                           'AUTHOR', 'REVDAT', 'SPRSDE', 'JRNL',
 
49
                           'AUTHOR', 'REVDAT', 'SPRSDE', 'JRNL', 'USER',
50
50
                           'REMARK', 'DBREF', 'SEQADV', 'SEQRES',
51
51
                           'MODRES', 'HET','HETNAM', 'HETSYN', 'FORMUL',
52
52
                           'HELIX', 'SHEET', 'TURN','SSBOND', 'LINK',
62
62
                               'HETATM','CONECT']
63
63
 
64
64
    def write(self, filename, nodes, sort=False, sortFunc=None,
65
 
              records=['ATOM', 'CONECT'], bondOrigin=('File',),
 
65
              records=['ATOM', 'CONECT'], bondOrigin=('File','UserDefined'),
66
66
              ssOrigin='File'):
67
67
        """
68
68
        required argument:
76
76
        sortFunc  -- (None) sort function that will be used to sort the nodes
77
77
                     when specified.This function has to return (-1, 0 or 1).
78
78
        records -- list of PDB record to write out
79
 
        bondOrigin -- (('File', )) This will be used if the CONECT records are
 
79
        bondOrigin -- (('File', 'UserDefined')) This will be used if the CONECT records are
80
80
                      written out. Can be any combination of 'File',
81
81
                      'BuiltByDistance' and 'UserDefined'.
82
82
        ssOrigin -- 'File' This will be used if the TURN, HELIX and SHEET
139
139
        file = open(filename, 'w')
140
140
        if not ('  ' or ' ' or '') in [x.chemElem for x in mol.allAtoms.data]:
141
141
            file.write('REMARK   4 XXXX COMPLIES WITH FORMAT V. 2.0\n')       
 
142
 
142
143
        for rec in self.PDBRECORDS:
143
144
            if self.recordsToWrite.has_key(rec):
144
145
                recLine = self.recordsToWrite[rec]
148
149
                else:
149
150
                    file.write(line)
150
151
        file.close()
 
152
        
151
153
        #self.recordsToWrite = {}
152
154
 
153
155
    def write_atom(self, f, atm):
606
608
        rec = rec + '\n'
607
609
        return rec
608
610
 
609
 
    def defineSecondaryStructureSection(self, mol, origin=''):
 
611
    def defineSecondaryStructureSection(self, mol, origin='File'):
610
612
        """
611
613
        The Secondary structure section contains the following records:
612
614
        HELIX, SHEET, TURN
655
657
        # 2- Create the SS record from the information generated by stride
656
658
        else:
657
659
            # only if the data structure has been created
658
 
            if not mol.hasSS == ['From Stride']: return
 
660
            if not mol.hasSS in ['From Stride', "From PROSS"]: return
659
661
            else:
660
662
                allstrands = SecondaryStructureSet([])
661
663
                allhelices = SecondaryStructureSet([])
672
674
                    
673
675
                self.defineHELIXRecords(allhelices)
674
676
                self.defineSHEETRecords(allstrands)
675
 
                self.defineTURNRecords(allturns)
676
 
 
 
677
                self.defineTURNRecords(allturns)        
677
678
 
678
679
    def defineCoordsSection(self, nodes, sort=False, sortFunc=None, atmRec=True, hetRec=True):
679
680
        """
705
706
                    self.recordsToWrite['ATOM'].append(self.defineATOM_HETATMRecord(atm))
706
707
 
707
708
 
708
 
    def defineConnectSection(self, atms, bondOrigin=('File',)):
 
709
    def defineConnectSection(self, atms, bondOrigin=('File','UserDefined')):
709
710
        """
710
711
        The Connectivity section contains the following records:
711
712
        CONECT
725
726
        elif type(bondOrigin) is types.ListType:
726
727
            bondOrigin = tuple(bondOrigin)
727
728
        self.recordsToWrite['CONECT'] = []
728
 
        for atm in atms:
729
 
            rec = 'CONECT%5i'%atm.number
730
 
            alLeast1Bond = 0
731
 
            for b in atm.bonds:
732
 
                if not b.origin in bondOrigin: continue
733
 
                a2 = b.atom1
734
 
                if a2==atm: a2 = b.atom2
735
 
                if not a2 in atms: continue
736
 
                alLeast1Bond = 1
737
 
                rec = rec + '%5i'%a2.number
738
 
            if alLeast1Bond:
739
 
                self.recordsToWrite['CONECT'].append(rec+'\n')
740
 
            
 
729
 
 
730
        ##
 
731
        ## MS June 2011
 
732
        ## replace thsi code with a loop over bonds whihc is faster but creates
 
733
        ## a CONECT record for each bond rather than one for all bonds for a
 
734
        ## given atom
 
735
        ##
 
736
##         from time import time
 
737
##         t1 = time()
 
738
##         for atm in atms:
 
739
##             rec = 'CONECT%5i'%atm.number
 
740
##             alLeast1Bond = 0
 
741
##             for b in atm.bonds:
 
742
##                 if not b.origin in bondOrigin: continue
 
743
##                 a2 = b.atom1
 
744
##                 if a2==atm: a2 = b.atom2
 
745
##                 if not a2 in atms: continue
 
746
##                 alLeast1Bond = 1
 
747
##                 rec = rec + '%5i'%a2.number
 
748
##             if alLeast1Bond:
 
749
##                 self.recordsToWrite['CONECT'].append(rec+'\n')
 
750
##         print 'Loop1', time()-t1
 
751
 
 
752
##         t1 = time()
 
753
        allBonds = atms.bonds[0]
 
754
        bl = self.recordsToWrite['CONECT']
 
755
        for b in allBonds:
 
756
           if not b.origin in bondOrigin: continue
 
757
           rec = 'CONECT%5i%5i'%(b.atom1.number, b.atom2.number)
 
758
           bl.append(rec+'\n')
 
759
##         print 'Loop2', time()-t1
 
760
        
741
761
class PdbqWriter(PdbWriter):
742
762
    """Class to write data records from a molecule tree to a pdbq file.
743
763
    Has methods for the user to add own records and to write the record."""