def copy(self, newname=None):
        """copy makes a new Protein instance with 'newname' and 
        other protein level parameters from self. Next,self.allAtoms is copied
        atom by atom. First: '_fit_atom_into_tree', which uses the same
        logic as pdbParser, builds up new instances of residues and chains
        as necessary.  Then: _copy_atom_attr copies the remaining
        String, Int, Float, None, List and Tuple attributes into new atom
        instances. The new molecule is returned by copy. 
        NB: subsequently the two copies can be visualized: 
        copy2=mv.Mols[0].copy()
        mv.addMolecule(copy2)
        mv.GUI.VIEWER.TransformRootOnly( yesno=0)
        mv.GUI.VIEWER.currentObject=copy2.geomContainer.geoms['master']
        then mouse movements would move only copy2, the new object """

        if not newname: newname = self.name + "_copy"
        newmol=Protein(name=newname, parent=self.parent,
            elementType=self.elementType, childrenName=self.childrenName,
            setClass=self.setClass, childrenSetClass=self.childrenSetClass,
            top=self.top)
        newmol.curChain=Chain()
        newmol.curRes=Residue()
        newmol.allAtoms= AtomSet()
        newmol.parser = self.parser
        for at in self.allAtoms:
            self._fit_atom_into_tree(newmol, at)
        newmol.buildBondsByDistance()
        return newmol
def buildPdb(map_dict,
             npts,
             name='DlgBuilt',
             ctr=0,
             outputfile='results.pdb',
             scale=1.0):
    if debug: print "in buildPdb: tolerance=", tolerance
    name = 'DlgBuilt'
    mol = Protein(name=name)
    mol.curChain = Chain()
    mol.chains = ChainSet([mol.curChain])
    mol.curRes = Residue()
    mol.curChain.adopt(mol.curRes)
    mol.allAtoms = AtomSet()
    mol.curRes.atoms = mol.allAtoms
    nzpts = nypts = nxpts = npts
    #nxpts, nypts, nzpts = npts
    ctr = 0
    for ADtype, m in map_dict.items():
        if debug:
            print "PROCESSING ", ADtype, " array:", max(m.ravel()), ':', min(
                m.ravel())
        vals = []
        tctr = 0  #for number of each type
        for z in range(nzpts):
            for y in range(nypts):
                for x in range(nxpts):
                    val = scale * abs(m[x, y, z])
                    vals.append(val)
                    #if abs(val)>.005:
                    if val > tolerance * scale:
                        ctr += 1
                        name = ADtype + str(ctr)
                        #version3:
                        #info_lo = (xcen - numxcells*spacing,
                        #    ycen - numycells*spacing,
                        #    zcen - numzcells *spacing)
                        #using lower back pt of cube, i think
                        #xcoord = (x-info_lo[0])/spacing
                        #ycoord = (y-info_lo[1])/spacing
                        #zcoord = (z-info_lo[2])/spacing
                        #version2:
                        xcoord = (x - numxcells) * spacing + xcen
                        ycoord = (y - numycells) * spacing + ycen
                        zcoord = (z - numzcells) * spacing + zcen
                        coords = (xcoord, ycoord, zcoord)
                        tctr += 1
                        #    #print "addAtom: name=",name,"ADtype=", ADtype," val=", val, "coords=", coords,"ctr=", ctr
                        addAtom(mol, name, ADtype, val, coords, ctr)
        print "added ", tctr, '<-', ADtype, " atoms"
        if debug:
            print ADtype, ':', tctr, ' ', ctr
    print "total atoms=", ctr
    writer = PdbWriter()
    writer.write(outputfile, mol.allAtoms, records=['ATOM'])
def buildPdb(map_dict, npts, name='DlgBuilt', ctr=0, outputfile='results.pdb', 
                    scale=1.0):
    if debug: print "in buildPdb: tolerance=", tolerance
    name = 'DlgBuilt'
    mol = Protein(name=name)
    mol.curChain = Chain()
    mol.chains = ChainSet([mol.curChain])
    mol.curRes = Residue()
    mol.curChain.adopt(mol.curRes)
    mol.allAtoms = AtomSet()
    mol.curRes.atoms = mol.allAtoms
    nzpts=nypts=nxpts = npts
    #nxpts, nypts, nzpts = npts
    ctr = 0
    for ADtype, m in map_dict.items():
        if debug: 
            print "PROCESSING ", ADtype, " array:", max(m.ravel()), ':', min(m.ravel())
        vals = []
        tctr = 0  #for number of each type
        for z in range(nzpts):
            for y in range(nypts):
                for x in range(nxpts):
                    val = scale * abs(m[x,y,z])
                    vals.append(val)
                    #if abs(val)>.005:
                    if val>tolerance*scale:
                        ctr += 1
                        name = ADtype + str(ctr)
                        #version3:
                        #info_lo = (xcen - numxcells*spacing,
                        #    ycen - numycells*spacing, 
                        #    zcen - numzcells *spacing)
                        #using lower back pt of cube, i think
                        #xcoord = (x-info_lo[0])/spacing
                        #ycoord = (y-info_lo[1])/spacing
                        #zcoord = (z-info_lo[2])/spacing
                        #version2:
                        xcoord = (x-numxcells)*spacing + xcen
                        ycoord = (y-numycells)*spacing + ycen
                        zcoord = (z-numzcells)*spacing + zcen
                        coords = (xcoord,ycoord,zcoord)
                        tctr += 1
                    #    #print "addAtom: name=",name,"ADtype=", ADtype," val=", val, "coords=", coords,"ctr=", ctr
                        addAtom(mol, name, ADtype, val, coords, ctr)
        print "added ",tctr, '<-', ADtype, " atoms"
        if debug:
            print ADtype, ':', tctr , ' ', ctr
    print "total atoms=", ctr
    writer = PdbWriter()
    writer.write(outputfile, mol.allAtoms, records=['ATOM'])