def _WriteMEADFiles(self, system, systemCharges, systemRadii): """For each instance of each site, write: - PQR file for the site - PQR file for the model compound - OGM file for the site - MGM file for the model compound""" grids = [] model = self.parent for stepIndex, (nodes, resolution) in enumerate(model.focusingSteps): if stepIndex < 1: grids.append("ON_GEOM_CENT %d %f\n" % (nodes, resolution)) else: x, y, z = self.center grids.append("(%f %f %f) %d %f\n" % (x, y, z, nodes, resolution)) selectSite = Selection(self.siteAtomIndices) selectModel = Selection(self.modelAtomIndices) # . In the PQR file of the model compound, charges of the site atoms must be set to zero (requirement of the my_2diel_solver program) chargesZeroSite = Clone(systemCharges) for atomIndex in self.siteAtomIndices: chargesZeroSite[atomIndex] = 0.0 for instance in self.instances: PQRFile_FromSystem( instance.modelPqr, system, selection=selectModel, charges=chargesZeroSite, radii=systemRadii, ) # . Update system charges with instance charges chargesInstance = Clone(systemCharges) for chargeIndex, atomIndex in enumerate(self.siteAtomIndices): chargesInstance[atomIndex] = instance.charges[chargeIndex] PQRFile_FromSystem( instance.sitePqr, system, selection=selectSite, charges=chargesInstance, radii=systemRadii, ) del chargesInstance # . Write OGM and MGM files (they have the same content) for fileGrid in (instance.modelGrid, instance.siteGrid): WriteInputFile(fileGrid, grids) del chargesZeroSite
def SetUpSystem(path, forceNoQC=False, useSystemWithTimings=True): """Set up the system.""" # . Get system data. systemData = YAMLUnpickle(os.path.join(path, _TestDataFileName)) # . Get the parameters. parameters = CHARMMParameterFiles_ToParameters( glob.glob(os.path.join(path, "*.prm"))) # . Get the test name. name = os.path.split(path)[-1] # . Generate the system. system = CHARMMPSFFile_ToSystem(os.path.join(path, name + ".psfx"), isXPLOR=True, parameters=parameters) if useSystemWithTimings: system = SystemWithTimings.FromSystem(system) system.coordinates3 = XYZFile_ToCoordinates3( os.path.join(path, name + ".xyz")) system.label = systemData["Label"] # . Symmetry. if systemData.get("Crystal Class", None) is not None: symmetryOptions = systemData["Symmetry Parameters"] symmetryOptions["crystalClass"] = _CrystalClasses[ systemData["Crystal Class"]] system.DefineSymmetry(**symmetryOptions) # . QC data. if not forceNoQC: qcData = systemData.get(_QCRegionKey, None) if qcData is not None: # . Electronic state. system.electronicState = ElectronicState( charge=qcData.get("Charge", 0), multiplicity=qcData.get("Multiplicity", 1)) # . QC atoms. qcAtoms = set() for path in qcData["Atoms"]: index = system.sequence.AtomIndex(path) qcAtoms.add(index) system.DefineQCModel(_QCModel, qcSelection=Selection(qcAtoms)) # . Finish set up. system.DefineNBModel(_NBModel) return system
def ExtractDisorderData ( self, dataBlock, system, disorderGroup = _DefaultDisorderGroup ): """Extract atom data from a data block.""" result = system table = dataBlock.get ( "atom_site", None ) if table is not None: # . Disorder and multiplicity information. assemblies = table.ColumnValues ( "atom_site_disorder_assembly" ) groups = table.ColumnValues ( "atom_site_disorder_group" ) multiplicities = table.ColumnValues ( "atom_site_symmetry_multiplicity" ) # . Check for the disorder groups to include. if groups is not None: uniqueGroups = set ( groups ) uniqueGroups.discard ( disorderGroup ) uniqueGroups.discard ( "-" + disorderGroup ) uniqueGroups.discard ( _UndefinedCharacter ) if len ( uniqueGroups ) > 0: toInclude = set ( [ _UndefinedCharacter, disorderGroup, "-" + disorderGroup ] ) indices = [] for ( i, group ) in enumerate ( groups ): if group in toInclude: indices.append ( i ) if len ( indices ) < len ( groups ): result = system.Prune ( Selection ( indices ) ) result.label = system.label return result
def runTest ( self ): """The test.""" # . Initialization. failures = 0 otherFailures = 0 successes = 0 # . Paths. dataPath = os.path.join ( os.getenv ( "PDYNAMO_PMOLECULE" ), "data", "pdb" ) if self.resultPath is None: outPath = os.path.join ( os.getenv ( "PDYNAMO_SCRATCH" ), _Destination ) else: outPath = os.path.join ( self.resultPath, _Destination ) if not os.path.exists ( outPath ): os.mkdir ( outPath ) log = self.GetLog ( ) # . Models. mmModel = MMModelCHARMM ( "c36a2" ) nbModel = NBModelABFS ( ) qcModel = QCModelMNDO ( ) # . Get the file. pdbFile = os.path.join ( dataPath, "2E4E_folded_solvated.pdb" ) ( head, tail ) = os.path.split ( pdbFile ) tag = tail[0:-4] if log is not None: log.Text ( "\nProcessing " + pdbFile + ":\n" ) system = PDBFile_ToSystem ( pdbFile, log = log, useComponentLibrary = True ) try: # . Fixed atoms. fixedAtoms = Selection ( ~ AtomSelection.FromAtomPattern ( system, "A:*:*" ) ) # . QC selection. indices = set ( ) for atomTag in _Tags: indices.add ( system.sequence.AtomIndex ( "A:TYR.2:" + atomTag ) ) tyrosine = Selection ( indices ) # . Setup. system.electronicState = ElectronicState ( charge = 0, multiplicity = 1 ) system.DefineFixedAtoms ( fixedAtoms ) system.DefineSymmetry ( crystalClass = CrystalClassCubic ( ), a = _BoxSize ) system.DefineMMModel ( mmModel, log = log ) system.DefineQCModel ( qcModel, qcSelection = tyrosine ) system.DefineNBModel ( nbModel ) system.Summary ( log = log ) referenceEnergy = system.Energy ( log = log, doGradients = True ) # . Pickling. pklFile = os.path.join ( outPath, tag + ".pkl" ) yamlFile = os.path.join ( outPath, tag + ".yaml" ) Pickle ( pklFile , system ) YAMLPickle ( yamlFile, system ) # . Unpickling. pklSystem = Unpickle ( pklFile ) pklSystem.label += " (Pickled)" pklSystem.Summary ( log = log ) pklEnergy = pklSystem.Energy ( log = log, doGradients = True ) if math.fabs ( referenceEnergy - pklEnergy <= _Tolerance ): successes += 1 else: failures += 1 yamlSystem = YAMLUnpickle ( yamlFile ) yamlSystem.label += " (YAMLPickled)" yamlSystem.Summary ( log = log ) yamlEnergy = yamlSystem.Energy ( log = log, doGradients = True ) if math.fabs ( referenceEnergy - yamlEnergy <= _Tolerance ): successes += 1 else: failures += 1 except Exception as e: otherFailures += 1 if log is not None: log.Text ( "\nError occurred> " + e.args[0] + "\n" ) # . Summary of results. if log is not None: summary = log.GetSummary ( ) summary.Start ( "Pickle Tests" ) summary.Entry ( "Pickle Successes", "{:d}".format ( successes ) ) summary.Entry ( "Pickle Failures" , "{:d}".format ( failures ) ) summary.Entry ( "Total Tests" , "2" ) summary.Entry ( "Loop Failures" , "{:d}".format ( otherFailures ) ) summary.Stop ( ) # . Success/failure. self.assertTrue ( ( failures == 0 ) and ( otherFailures == 0 ) )
def WriteJobFiles(self, log=logFile): """Write files: PQR, FPT, OGM and MGM.""" if self.isInitialized: # . Get atomic charges and radii for the system system = self.owner systemCharges = system.AtomicCharges() systemRadii = [] systemTypes = system.energyModel.mmAtoms.AtomTypes() radii = YAMLUnpickle("%s/%s" % (YAMLPATHIN, "radii.yaml")) for atomType in systemTypes: if radii.has_key(atomType): radius = radii[atomType] else: generalAtomType = "%s*" % atomType[0] if radii.has_key(generalAtomType): radius = radii[generalAtomType] else: raise ContinuumElectrostaticsError( "Cannot find atomic radius for atom type %s" % atomType) systemRadii.append(radius) # . Prepare scratch space if not os.path.exists(self.pathScratch): try: os.makedirs(self.pathScratch) except: raise ContinuumElectrostaticsError( "Cannot create scratch directory %s" % self.pathScratch) # . Create subdirectories, if necessary if self.splitToDirectories: for site in self.sites: sitePqr = site.instances[0].sitePqr directory = os.path.dirname(sitePqr) if not os.path.exists(directory): try: os.makedirs(directory) except: raise ContinuumElectrostaticsError( "Cannot create directory %s" % directory) # . Write PQR, OGM and MGM files of all instances of all sites for site in self.sites: site._WriteMEADFiles(system, systemCharges, systemRadii) # . Write background PQR file PQRFile_FromSystem(self.pathPqrBack, system, selection=Selection(self.backAtomIndices), charges=systemCharges, radii=systemRadii) # . Write full-protein PQR file (to be used as eps2set_region) PQRFile_FromSystem(self.pathPqrProtein, system, selection=Selection(self.proteinAtomIndices), charges=systemCharges, radii=systemRadii) # . Write FPT-file lines = [] for siteIndex, site in enumerate(self.sites): for instanceIndex, instance in enumerate(site.instances): for atomIndex, charge in zip(site.siteAtomIndices, instance.charges): x, y, z = system.coordinates3[atomIndex] line = "%d %d %f %f %f %f\n" % ( siteIndex, instanceIndex, x, y, z, charge) lines.append(line) WriteInputFile(self.pathFptSites, lines) self.isFilesWritten = True