def ToSystem ( self ): """Return a system from the CHARMM CRD data.""" if self.QPARSED: sequence = self.ToSequence ( ) system = System.FromSequence ( sequence ) system.coordinates3 = self.ToCoordinates3 ( ) system.label = " ".join ( self.title ).strip ( ) return system else: return None
def ToSystem ( self, mmModel = None ): """Create a system.""" system = None if self.QPARSED: # . Sequence data and then basic system. sequence = self.ToSequence ( ) system = System.FromSequence ( sequence ) system.label = " ".join ( self.title ) # . Assign atomic numbers using atomic numbers if they exist, otherwise masses. atomicNumbers = getattr ( self, "atomic_number", None ) if atomicNumbers is None: for ( mass, atom ) in zip ( self.mass, system.atoms ): atom.atomicNumber = PeriodicTable.AtomicNumberFromMass ( mass ) else: for ( n, atom ) in zip ( atomicNumbers, system.atoms ): atom.atomicNumber = n # . The MM model (with some options). if mmModel is None: mmModel = MMModelAMBER ( ) # . 1-4 scaling factors. if hasattr ( self, "scee_scale_factor" ): mmModel.electrostaticScale14 = 1.0 / self.scee_scale_factor[0] if hasattr ( self, "scnb_scale_factor" ): mmModel.lennardJonesScale14 = 1.0 / self.scnb_scale_factor[0] # . Define the model. system.DefineMMModel ( mmModel, buildModel = False ) # . The MM atoms. mm = self.ToMMAtomContainer ( ) if mm is not None: system.energyModel.mmAtoms = mm # . Various MM terms. mmTerms = [] mm = self.ToHarmonicBondContainer ( ) if mm is not None: mmTerms.append ( mm ) mm = self.ToHarmonicAngleContainer ( ) if mm is not None: mmTerms.append ( mm ) self.UntangleDihedralsAnd14s ( ) if self.dihedrals is not None: mmTerms.append ( self.dihedrals ) if self.impropers is not None: mmTerms.append ( self.impropers ) if len ( mmTerms ) > 0: system.energyModel.mmTerms = MMTermContainer ( mmTerms ) # . Remaining MM data. if self.interactions14 is not None: system.energyModel.interactions14 = self.interactions14 mm = self.ToExclusionsPairList ( ) if mm is not None: system.energyModel.exclusions = mm mm = self.ToLJParameterContainer ( mmModel.lennardJonesStyle ) if mm is not None: system.energyModel.ljParameters = mm # . 1-4 parameters. scale = mmModel.lennardJonesScale14 if scale != 0.0: lj14 = Clone ( mm ) lj14.label = "1-4 Lennard-Jones" lj14.Scale ( scale ) system.energyModel.ljParameters14 = lj14 # . Symmetry data. self.ToSymmetry ( system ) return system
def ToSystem(self, mmModel=None, parameters=None): """Create a system.""" system = None if self.QPARSED: # . Get the sequence. sequence = self.ToSequence() # . Basic system. system = System.FromSequence(sequence) system.label = " ".join(self.title) # . Assign atomic numbers from masses. for (datum, atom) in zip(self.atoms, system.atoms): atom.atomicNumber = PeriodicTable.AtomicNumberFromMass( datum[7]) # . The MM model. if mmModel is None: mmModel = MMModelCHARMM() # . Build the model but only when PSF files are in XPLOR format. if (mmModel is not None) and (parameters is not None) and (self.isXPLOR): system.DefineMMModel(mmModel, buildModel=False) # . The MM atoms. mm = self.ToMMAtomContainer() if mm is not None: system.energyModel.mmAtoms = mm # . Various MM terms. mmTerms = [] mm = self.ToHarmonicBondContainer( rawParameters=parameters.bonds) if mm is not None: mmTerms.append(mm) mm = self.ToHarmonicAngleContainer( rawParameters=parameters.angles) if mm is not None: mmTerms.append(mm) mm = self.ToHarmonicUreyBradleyContainer( rawParameters=parameters.ureybradleys) if mm is not None: mmTerms.append(mm) mm = self.ToFourierDihedralContainer( rawParameters=parameters.dihedrals, rawParametersWild=parameters.dihedralwilds) if mm is not None: mmTerms.append(mm) mm = self.ToHarmonicImproperContainer( rawParameters=parameters.impropers, rawParametersWild=parameters.improperwilds) if mm is not None: mmTerms.append(mm) mm = self.ToCMAPDihedralContainer( rawParameters=parameters.cmaps) if mm is not None: mmTerms.append(mm) if len(mmTerms) > 0: system.energyModel.mmTerms = MMTermContainer(mmTerms) # . Exclusions. (exclusions, interactions14) = self.ToExclusionPairLists() if exclusions is not None: system.energyModel.exclusions = exclusions if interactions14 is not None: system.energyModel.interactions14 = interactions14 # . LJ terms. ( ljParameters, ljParameters14 ) = self.ToLJParameterContainers ( parameters = parameters.nonbonds , parametersWild = parameters.nonbondwilds, \ parameters14 = parameters.nonbond14s, parameters14Wild = parameters.nonbond14wilds ) if ljParameters is not None: system.energyModel.ljParameters = ljParameters if ljParameters14 is not None: system.energyModel.ljParameters14 = ljParameters14 # . Fixed atoms - do after MM model so MM terms are appropriately affected. self.ToFixedAtoms(system) return system
def ToSystem(self, altLoc=_UNDEFINEDCHARACTER, modelNumber=_DEFAULTMODELNUMBER, embeddedHydrogens=False): """Return a system from the model.""" system = None if self.QFINALIZED: # . Initialization. index = 0 atomPaths = [] majorSeparator = Sequence.defaultAttributes["labelSeparator"] minorSeparator = Sequence.defaultAttributes["fieldSeparator"] systemAtoms = [] undefined = [] xyz = [] # . Loop over entities. entities = list(self.entities.values()) entities.sort(key=mmCIFModelEntity.GetIndex) entityLabels = {} for entity in entities: # . Entity label. if entity.asymlabel == _UNDEFINEDCHARACTER: entityLabel = _DefaultLabel else: entityLabel = entity.asymlabel if (entity.asymlabel != entity.label) and ( entity.label != _UNDEFINEDCHARACTER): entityLabel += (minorSeparator + entity.label) entityLabels[entity] = entityLabel # . Loop over components. components = list(entity.components.values()) components.sort(key=mmCIFModelComponent.GetIndex) for component in components: # . Component path. fields = [] for item in (component.name, component.sequencenumber, component.insertioncode): if item == _UNDEFINEDCHARACTER: fields.append(_DefaultLabel) else: fields.append(item) n = 3 for item in reversed(fields): if item == _DefaultLabel: n -= 1 else: break componentLabel = minorSeparator.join(fields[0:max(n, 1)]) # . Loop over atoms - putting hydrogens at the end if necessary. atoms = list(component.atoms.values()) if embeddedHydrogens: atoms.sort(key=mmCIFModelAtom.GetIndex) else: atoms.sort( key=mmCIFModelAtom.GetNonEmbeddedHydrogenIndex) # . Generate atoms and associated data. for atom in atoms: systemAtoms.append( Atom(atomicNumber=atom.atomicNumber, formalCharge=atom.formalCharge)) if atom.label == _UNDEFINEDCHARACTER: atomLabel = _DefaultLabel else: atomLabel = atom.label atomPaths.append(entityLabel + majorSeparator + componentLabel + majorSeparator + atomLabel) (QUNDEFINED, x, y, z) = atom.GetCoordinateData(altLoc, modelNumber) if QUNDEFINED: undefined.append(index) xyz.append((x, y, z)) index += 1 # . Make the sequence. sequence = Sequence.FromAtomPaths(atomPaths, atoms=systemAtoms) # . Make the system. system = System.FromSequence(sequence) if self.label is not None: system.label = self.label # . Coordinates. coordinates3 = Coordinates3.WithExtent(len(systemAtoms)) for (i, (x, y, z)) in enumerate(xyz): coordinates3[i, 0] = x coordinates3[i, 1] = y coordinates3[i, 2] = z system.coordinates3 = coordinates3 # . Undefined coordinates. if len(undefined) > 0: for i in undefined: system.coordinates3.FlagCoordinateAsUndefined(i) # . Define polymer data. for oldEntity in entities: if isinstance(oldEntity, mmCIFModelPolymerEntity): newEntity = system.sequence.childIndex.get( entityLabels[oldEntity]) system.sequence.linearPolymers.append ( SequenceLinearPolymer ( isCyclic = oldEntity.QCYCLIC , \ leftTerminalComponent = newEntity.children[ 0] , \ rightTerminalComponent = newEntity.children[-1] ) ) # . Finish up. return system