def convertPdbStep(self):
        """ Although is not mandatory, usually is used by the protocol to
        register the resulting outputs in the database.
        """
        pdbFn = self._getPdbFileName()
        outFile = removeExt(self._getVolName())
        if getExt(pdbFn) == ".cif":
            pdbFn2 = replaceBaseExt(pdbFn, 'pdb')
            cifToPdb(pdbFn, pdbFn2)
            pdbFn = pdbFn2

        args = '-i %s --sampling %f -o %s' % (pdbFn, self.sampling.get(),
                                              outFile)

        if self.centerPdb:
            args += ' --centerPDB'

        if self.setSize:
            args += ' --size'

        if self.size.hasValue():
            args += ' %d' % self.size.get()

        self.info("Input file: " + pdbFn)
        self.info("Output file: " + outFile)

        program = "xmipp_volume_from_pdb"
        self.runJob(program, args)
Ejemplo n.º 2
0
    def _insertAllSteps(self):
        atomsFn = self.getInputPdb().getFileName()
        # Define some outputs filenames
        self.imgsFn = self._getExtraPath('images.xmd')
        self.modesFn = self._getExtraPath('modes.xmd')
        self.structureEM = self.inputModes.get().getPdb().getPseudoAtoms()
        if self.structureEM:
            self.atomsFn = self._getExtraPath(basename(atomsFn))
            copyFile(atomsFn, self.atomsFn)
        else:
            localFn = self._getExtraPath(
                replaceBaseExt(basename(atomsFn), 'pdb'))
            cifToPdb(atomsFn, localFn)
            self.atomsFn = self._getExtraPath(basename(localFn))

        self._insertFunctionStep('convertInputStep', atomsFn)

        if self.copyDeformations.empty():  #ONLY FOR DEBUGGING
            self._insertFunctionStep("performNmaStep", self.atomsFn,
                                     self.modesFn)
        else:
            # TODO: for debugging and testing it will be useful to copy the deformations
            # metadata file, not just the deformation.txt file
            self._insertFunctionStep('copyDeformationsStep',
                                     self.copyDeformations.get())

        self._insertFunctionStep('createOutputStep')
Ejemplo n.º 3
0
    def copyPdbStep(self, inputFn, localFn, isEM):
        """ Copy the input pdb file and also create a link 'atoms.pdb'
        """
        cifToPdb(inputFn, localFn)

        if isEM:
            fnOut = self._getPath('pseudoatoms.pdb')
        else:
            fnOut = self._getPath('atoms.pdb')

        if not os.path.exists(fnOut):
            createLink(localFn, fnOut)
    def _generateAnimation(self):
        prot = self.protocol
        projectorFile = prot.getProjectorFile()

        animation = self.trajectoriesWindow.getAnimationName()
        animationPath = prot._getExtraPath('animation_%s' % animation)

        cleanPath(animationPath)
        makePath(animationPath)
        animationRoot = join(animationPath, 'animation_%s' % animation)

        trajectoryPoints = np.array(
            [p.getData() for p in self.trajectoriesWindow.pathData])
        np.savetxt(join(animationPath, 'trajectory.txt'), trajectoryPoints)

        if projectorFile:
            M = np.loadtxt(projectorFile)
            deformations = np.dot(trajectoryPoints, np.linalg.pinv(M))
        else:
            Y = np.loadtxt(prot.getOutputMatrixFile())
            X = np.loadtxt(prot.getDeformationFile())
            # Find closest points in deformations
            deformations = [
                X[np.argmin(np.sum((Y - p)**2, axis=1))]
                for p in trajectoryPoints
            ]

        pdb = prot.getInputPdb()
        pdbFile = pdb.getFileName()

        structureEM = prot.getInputPdb().getPseudoAtoms()
        if not structureEM:
            localFn = replaceBaseExt(basename(pdbFile), 'pdb')
            cifToPdb(pdbFile, localFn)
            pdbFile = basename(localFn)

        modesFn = prot.inputNMA.get()._getExtraPath('modes.xmd')

        for i, d in enumerate(deformations):
            atomsFn = animationRoot + 'atomsDeformed_%02d.pdb' % (i + 1)
            cmd = '-o %s --pdb %s --nma %s --deformations %s' % (
                atomsFn, pdbFile, modesFn, str(d)[1:-1])
            runJob(None, 'xmipp_pdb_nma_deform', cmd, env=prot._getEnviron())

        # Join all deformations in a single pdb
        # iterating going up and down through all points
        # 1 2 3 ... n-2 n-1 n n-1 n-2 ... 3, 2
        n = len(deformations)
        r1 = range(1, n + 1)
        r2 = range(2, n)  # Skip 1 at the end
        r2.reverse()
        loop = r1 + r2

        trajFn = animationRoot + '.pdb'
        trajFile = open(trajFn, 'w')

        for i in loop:
            atomsFn = animationRoot + 'atomsDeformed_%02d.pdb' % i
            atomsFile = open(atomsFn)
            for line in atomsFile:
                trajFile.write(line)
            trajFile.write('TER\nENDMDL\n')
            atomsFile.close()

        trajFile.close()
        # Delete temporary atom files
        cleanPattern(animationRoot + 'atomsDeformed_??.pdb')

        # Generate the vmd script
        vmdFn = animationRoot + '.vmd'
        vmdFile = open(vmdFn, 'w')
        vmdFile.write("""
        mol new %s
        animate style Loop
        display projection Orthographic
        mol modcolor 0 0 Index
        mol modstyle 0 0 Beads 1.000000 8.000000
        animate speed 0.5
        animate forward
        """ % trajFn)
        vmdFile.close()

        VmdView(' -e ' + vmdFn).show()