示例#1
0
 def ToSystem(self):
     """Generate a system from the component."""
     # . Bonds.
     labelIndices = {}
     for (i, atom) in enumerate(self.atoms):
         labelIndices[atom.label] = i
     bonds = []
     for bond in self.bonds:
         bonds.append((labelIndices[bond.atomLabel1],
                       labelIndices[bond.atomLabel2], bond.bondType))
     # . System from atoms and bonds.
     system = System.FromAtoms(self.atoms, bonds=bonds, withSequence=True)
     # . Set additional atom data.
     for (pAtom, sAtom) in zip(self.atoms, system.atoms):
         sAtom.formalCharge = pAtom.formalCharge
         sAtom.label = pAtom.label
     # . Label.
     system.label = "PDB Component"
     if self.label is not None: system.label += " " + self.label
     # . Define component labels.
     for entity in system.sequence.children:
         for component in entity.children:
             component.label = self.label
     # . Finish up.
     return system
示例#2
0
 def ExtractAtomData ( self, dataBlock, blockCode ):
     """Extract atom data from a data block."""
     system = xyzC = xyzF = None
     table  = dataBlock.get ( "atom_site", None )
     if table is not None:
         # . Atom labels and symbols.
         labels  = table.ColumnValues ( "atom_site_label"       )
         symbols = table.ColumnValues ( "atom_site_type_symbol" )
         # . Make the symbols from the labels if necessary.
         if symbols is None:
             if labels is not None:
                 symbols = []
                 for label in labels:
                     characters = []
                     for c in label:
                         if c.isalpha ( ): characters.append ( c )
                         else:             break
                     symbols.append ( "".join ( characters ) )
         # . Make the basic system.
         if symbols is not None:
             system = System.FromAtoms ( symbols )
             system.label = blockCode
         # . Use the labels in the data block.
         if labels is not None:
             for ( atom, label ) in zip ( system.atoms, labels ):
                 atom.label = label
         # . Coordinates.
         xyzC = self.ExtractCoordinates ( table, "atom_site_Cartn" )
         xyzF = self.ExtractCoordinates ( table, "atom_site_fract" )
     return ( system, xyzC, xyzF )
示例#3
0
 def ToSystem(self, QBEST=True):
     """Return a system constructed from the file data."""
     system = None
     if self.QPARSED and len(self.atomicNumbers > 0):
         system = System.FromAtoms(self.atomicNumbers)
         system.coordinates3 = self.ToCoordinates3(QBEST=QBEST)
         system.label = "System from Jaguar Output File"
     return system
示例#4
0
 def ToSystem(self):
     """Return a system."""
     system = None
     if self.QPARSED and hasattr(self, "atomicNumbers"):
         system = System.FromAtoms(self.atomicNumbers)
         system.label = self.title
         system.coordinates3 = self.ToCoordinates3()
     return system
示例#5
0
 def ToSystem ( self ):
     """Return a system."""
     system = None
     if self.QPARSED:
         system                 = System.FromAtoms ( self.atomicNumbers )
         system.label           = self.title
         system.coordinates3    = self.ToCoordinates3 ( )
         system.electronicState = ElectronicState ( charge = self.charge, multiplicity = self.multiplicity )
     return system
示例#6
0
 def ToSystem(self):
     """Return a system."""
     if self.QPARSED:
         system = System.FromAtoms(self.atomicNumbers)
         system.label = self.label
         system.coordinates3 = self.ToCoordinates3()
         return system
     else:
         return None
示例#7
0
 def ToSystem(self):
     """Return a system."""
     system = None
     if self.QPARSED and hasattr(self, "atomicNumbers"):
         system = System.FromAtoms(self.atomicNumbers)
         system.coordinates3 = self.ToCoordinates3()
         system.electronicState = self.ToElectronicState()
         if hasattr(self, "entryname"): system.label = self.entryname
     return system
 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
示例#9
0
 def ToSystem(self):
     """Return a system from the CRD data but without sequence information."""
     if self.QPARSED:
         atoms = []
         for (aname, atomicNumber, x, y, z) in self.atoms:
             atoms.append(atomicNumber)
         system = System.FromAtoms(atoms)
         system.coordinates3 = self.ToCoordinates3()
         return system
     else:
         return None
示例#10
0
 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, frameIndex=-1):
     """Return a system."""
     system = None
     if self.QPARSED:
         frame = self.frames[frameIndex]
         atomicNumbers = frame.GetItem("Atomic Numbers")
         if atomicNumbers is not None:
             (head, tail) = os.path.split(self.name)
             system = System.FromAtoms(atomicNumbers)
             system.label = _DefaultSystemLabel + " " + tail
             system.coordinates3 = self.ToCoordinates3()
             system.electronicState = self.ToElectronicState()
     return system
示例#12
0
 def ToSystem(self):
     """Return a system."""
     system = None
     if self.QPARSED:
         try:
             system = System.FromAtoms(self.atomicNumbers,
                                       bonds=getattr(self, "bonds", None))
             system.label = self.label
             system.coordinates3 = self.xyz
             if hasattr(self, "crystalClass") and hasattr(
                     self, "symmetryParameters"):
                 definitions = self.crystalClass.GetUniqueSymmetryParameters(
                     self.symmetryParameters)
                 definitions["crystalClass"] = self.crystalClass
                 system.DefineSymmetry(**definitions)
         except:
             pass
     return system
示例#13
0
 def ToSystem(self, index=0):
     """Return a system."""
     if self.QPARSED:
         if index in range(len(self.molrecords)):
             # . Get data.
             (label, atomicNumbers, bonds, charges, coordinates3, mchg,
              miso, mrad) = self.molrecords[index]
             # . Make atoms.
             atoms = self.ToAtoms(atomicNumbers, charges, mchg, miso, mrad)
             # . Make system.
             system = System.FromAtoms(atoms, bonds=bonds)
             system.label = label
             system.coordinates3 = coordinates3
             return system
         else:
             raise IndexError(
                 "MOL record index {:d} not in range [0,{:d}].".format(
                     index,
                     len(self.molrecords) - 1))
     else:
         return None
示例#14
0
    def ToSystem(self, **keywordArguments):
        """Return a system.

        Implicit hydrogens are added unless |QOMITIMPLICITHYDROGENS| is True.
        The hydrogens are placed after their host atom.
        """
        # . Options.
        QOMIT = keywordArguments.get("QOMITIMPLICITHYDROGENS", False)
        # . Atoms.
        if QOMIT:
            atoms = self.atoms
        else:
            atoms = []
            index = 0
            for atom in self.atoms:
                atom.index = index
                atoms.append(atom)
                for i in range(atom.implicithydrogens):
                    atoms.append(1)
                index += atom.implicithydrogens + 1
        # . Bonds.
        bonds = []
        for bond in self.bonds:
            bonds.append((bond.atom1.index, bond.atom2.index, bond.type))
        if not QOMIT:
            for atom in self.atoms:
                for i in range(atom.implicithydrogens):
                    bonds.append(
                        (atom.index, atom.index + i + 1, SingleBond()))
            self.IndexAtoms()
        # . Make the system.
        system = System.FromAtoms(atoms, bonds=bonds)
        # . Set the aromaticity and formalCharge of the new atoms.
        for atom in self.atoms:
            index = atom.index
            system.atoms[index].formalCharge = atom.formalCharge
            system.atoms[index].isAromatic = atom.isAromatic
        # . Finish up.
        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
示例#16
0
 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