Esempio n. 1
0
File: deshaw.py Progetto: DaMSL/ddc
def convert_topology(src_filename, set_backbone=True, in_place=False, split_dir=None):
  """ Converts the D.E.Shaw topology to Charm-usable force field with
  TIP4P water molecules. THis re-sorts the atoms in the water solvent chains
  (C2,C3) to group all 4 atoms as one contiguous residue. It also aliases the
  ion charges 'pseu' atom to 'OM' for use with the standard tip4p.par parameter
  file. The set_backbone option is to set constraint during initial minimzation"""

  # Grab unit cell description (should be on first few lines:
  cryst = None
  with open(src_filename) as src:
    for line in src.readlines():
      if line.startswith('CRYST1'):
        cryst = line
        break

  # Read in source PDB (DEShaw original format)
  src_pdb = PdbStructure(open(src_filename))
  atoms = list(src_pdb.iter_atoms())
  topo = md.load(src_filename).top

  # Break into 4 segments
  segment_list = ['C1', 'C2', 'C3', 'C4']
  segment = {l:[] for l in segment_list}
  for i in atoms: 
    segment[i.segment_id].append(i)

  # Set temperature factor (for gradual heating) 
  if set_backbone:
    backbone = topo.select("backbone")
    for i in range(0, len(segment['C1'])):
      if i in backbone:
        segment['C1'][i].location.temperature_factor = 1.0

  # Resort water segements and alias "pseu" to OM (tip4p forcefield)
  for wat in ['C2', 'C3']:
    segment[wat] = sorted(segment[wat], key = lambda i: i.residue_number)
    start_serial_num = min(segment[wat], key= lambda i: i.serial_number)
    for i in range(0, len(segment[wat])):
      newsn = i + start_serial_num.serial_number
      segment[wat][i].serial_number = newsn
      if segment[wat][i].get_name == 'pseu':
        segment[wat][i].set_name_with_spaces(' OM ')

  # FOR RE-RUNNING THE PSFGEN
  if split_dir is not None:
    for s in segment_list:
      with open(split_dir + '/%s.pdb' % s, 'w') as dest:
        for atom in segment[s]:
          _=dest.write(str(atom) + '\n')

  # Writeout new file
  if in_place:
    dest = open(src_filename, 'w')
    if cryst is not None:
      dest.write(cryst)
    for s in segment_list:
      for atom in segment[s]:
        _=dest.write(str(atom) + '\n')
    _=dest.write('END')
    dest.close()
Esempio n. 2
0
File: deshaw.py Progetto: DaMSL/ddc
def reset_pdb(src_filename):
  """ Updates PDB file with crytalline unit cell data and backbone temp
  control to enable gradual heating"""

  # Standard unit cell description (first lines)
  cryst= 'CRYST1   51.263   51.263   51.263  90.00  90.00  90.00 P 1           1\n'

  # Read in source PDB (DEShaw original format)
  src_pdb = PdbStructure(open(src_filename))
  atoms = list(src_pdb.iter_atoms())
  topo = md.load(src_filename).top

  # Set temperature factor (for gradual heating) 
  backbone = topo.select("backbone")
  for i in range(0, len(atoms)):
    if i in backbone:
      atoms[i].location.temperature_factor = 1.0

  # Write out to file
  dest = open(src_filename, 'w')
  if cryst is not None:
    dest.write(cryst)
  dest.write('REMARK Dynamically Generated from data driven controller (DDC)\n')
  for atom in atoms:
    _=dest.write(str(atom) + '\n')
  _=dest.write('END')
  dest.close()
Esempio n. 3
0
File: deshaw.py Progetto: DaMSL/ddc
def reset_pdb(src_filename):
    """ Updates PDB file with crytalline unit cell data and backbone temp
  control to enable gradual heating"""

    # Standard unit cell description (first lines)
    cryst = 'CRYST1   51.263   51.263   51.263  90.00  90.00  90.00 P 1           1\n'

    # Read in source PDB (DEShaw original format)
    src_pdb = PdbStructure(open(src_filename))
    atoms = list(src_pdb.iter_atoms())
    topo = md.load(src_filename).top

    # Set temperature factor (for gradual heating)
    backbone = topo.select("backbone")
    for i in range(0, len(atoms)):
        if i in backbone:
            atoms[i].location.temperature_factor = 1.0

    # Write out to file
    dest = open(src_filename, 'w')
    if cryst is not None:
        dest.write(cryst)
    dest.write(
        'REMARK Dynamically Generated from data driven controller (DDC)\n')
    for atom in atoms:
        _ = dest.write(str(atom) + '\n')
    _ = dest.write('END')
    dest.close()
Esempio n. 4
0
def test_load_multiframe():
    with open(get_fn('multiframe.pdb')) as f:
        pdb = PdbStructure(f)
        yield lambda: eq(len(pdb.models), 2)
        yield lambda: eq(len(pdb.models[0].chains), 1)
        yield lambda: eq(len(pdb.models[0].chains[0].residues), 3)
        yield lambda: eq(ilen(pdb.models[0].iter_atoms()), 22)

        yield lambda: eq(len(pdb.models[1].chains), 1)
        yield lambda: eq(len(pdb.models[1].chains[0].residues), 3)
        yield lambda: eq(ilen(pdb.models[1].iter_atoms()), 22)

    t = load(get_fn('multiframe.pdb'))
    yield lambda: eq(t.n_frames, 2)
    yield lambda: eq(t.n_atoms, 22)
    yield lambda: eq(t.xyz[0], t.xyz[1])
Esempio n. 5
0
def test_load_multiframe(get_fn):
    with open(get_fn('multiframe.pdb')) as f:
        pdb = PdbStructure(f)
        assert eq(len(pdb.models), 2)
        assert eq(len(pdb.models[0].chains), 1)
        assert eq(len(pdb.models[0].chains[0].residues), 3)
        assert eq(len(list(pdb.models[0].iter_atoms())), 22)

        assert eq(len(pdb.models[1].chains), 1)
        assert eq(len(pdb.models[1].chains[0].residues), 3)
        assert eq(len(list(pdb.models[1].iter_atoms())), 22)

    t = load(get_fn('multiframe.pdb'))
    assert eq(t.n_frames, 2)
    assert eq(t.n_atoms, 22)
    assert eq(t.xyz[0], t.xyz[1])
Esempio n. 6
0
    def _read_models(self):
        if not self._mode == 'r':
            raise ValueError('file not opened for reading')

        self._topology = Topology()

        pdb = PdbStructure(self._file, load_all_models=True)

        atomByNumber = {}
        for chain in pdb.iter_chains():
            c = self._topology.add_chain()
            for residue in chain.iter_residues():
                resName = residue.get_name()
                if resName in PDBTrajectoryFile._residueNameReplacements:
                    resName = PDBTrajectoryFile._residueNameReplacements[resName]
                r = self._topology.add_residue(resName, c, residue.number)
                if resName in PDBTrajectoryFile._atomNameReplacements:
                    atomReplacements = PDBTrajectoryFile._atomNameReplacements[resName]
                else:
                    atomReplacements = {}
                for atom in residue.atoms:
                    atomName = atom.get_name()
                    if atomName in atomReplacements:
                        atomName = atomReplacements[atomName]
                    atomName = atomName.strip()
                    element = atom.element
                    if element is None:
                        element = self._guess_element(atomName, residue)

                    newAtom = self._topology.add_atom(atomName, element, r, serial=atom.serial_number)
                    atomByNumber[atom.serial_number] = newAtom

        # load all of the positions (from every model)
        _positions = []
        for model in pdb.iter_models(use_all_models=True):
            coords = []
            for chain in model.iter_chains():
                for residue in chain.iter_residues():
                    for atom in residue.atoms:
                        coords.append(atom.get_position())
            _positions.append(coords)

        if not all(len(f) == len(_positions[0]) for f in _positions):
            raise ValueError('PDB Error: All MODELs must contain the same number of ATOMs')

        self._positions = np.array(_positions)

        ## The atom positions read from the PDB file
        self._unitcell_lengths = pdb.get_unit_cell_lengths()
        self._unitcell_angles = pdb.get_unit_cell_angles()
        self._topology.create_standard_bonds()
        self._topology.create_disulfide_bonds(self.positions[0])

        # Add bonds based on CONECT records.
        connectBonds = []
        for connect in pdb.models[0].connects:
            i = connect[0]
            for j in connect[1:]:
                if i in atomByNumber and j in atomByNumber:
                    connectBonds.append((atomByNumber[i], atomByNumber[j]))
        if len(connectBonds) > 0:
            # Only add bonds that don't already exist.
            existingBonds = set(self._topology.bonds)
            for bond in connectBonds:
                if bond not in existingBonds and (bond[1], bond[0]) not in existingBonds:
                    self._topology.add_bond(bond[0], bond[1])
                    existingBonds.add(bond)
Esempio n. 7
0
    def _read_models(self):
        if not self._mode == 'r':
            raise ValueError('file not opened for reading')

        self._topology = Topology()

        pdb = PdbStructure(self._file, load_all_models=True)

        atomByNumber = {}
        for chain in pdb.iter_chains():
            c = self._topology.add_chain()
            for residue in chain.iter_residues():
                resName = residue.get_name()
                if resName in PDBTrajectoryFile._residueNameReplacements:
                    resName = PDBTrajectoryFile._residueNameReplacements[resName]
                r = self._topology.add_residue(resName, c, residue.number)
                r.segment_id = residue.segment_id
                if resName in PDBTrajectoryFile._atomNameReplacements:
                    atomReplacements = PDBTrajectoryFile._atomNameReplacements[resName]
                else:
                    atomReplacements = {}
                for atom in residue.atoms:
                    atomName = atom.get_name()
                    if atomName in atomReplacements:
                        atomName = atomReplacements[atomName]
                    atomName = atomName.strip()
                    element = atom.element
                    if element is None:
                        element = self._guess_element(atomName, residue)

                    newAtom = self._topology.add_atom(atomName, element, r, serial=atom.serial_number)
                    atomByNumber[atom.serial_number] = newAtom

        # load all of the positions (from every model)
        _positions = []
        for model in pdb.iter_models(use_all_models=True):
            coords = []
            for chain in model.iter_chains():
                for residue in chain.iter_residues():
                    for atom in residue.atoms:
                        coords.append(atom.get_position())
            _positions.append(coords)

        if not all(len(f) == len(_positions[0]) for f in _positions):
            raise ValueError('PDB Error: All MODELs must contain the same number of ATOMs')

        self._positions = np.array(_positions)

        ## The atom positions read from the PDB file
        self._unitcell_lengths = pdb.get_unit_cell_lengths()
        self._unitcell_angles = pdb.get_unit_cell_angles()
        self._topology.create_standard_bonds()
        self._topology.create_disulfide_bonds(self.positions[0])

        # Add bonds based on CONECT records.
        connectBonds = []
        for connect in pdb.models[-1].connects:
            i = connect[0]
            for j in connect[1:]:
                if i in atomByNumber and j in atomByNumber:
                    connectBonds.append((atomByNumber[i], atomByNumber[j]))
        if len(connectBonds) > 0:
            # Only add bonds that don't already exist.
            existingBonds = set(self._topology.bonds)
            for bond in connectBonds:
                if bond not in existingBonds and (bond[1], bond[0]) not in existingBonds:
                    self._topology.add_bond(bond[0], bond[1])
                    existingBonds.add(bond)
Esempio n. 8
0
File: deshaw.py Progetto: DaMSL/ddc
def convert_topology(src_filename,
                     set_backbone=True,
                     in_place=False,
                     split_dir=None):
    """ Converts the D.E.Shaw topology to Charm-usable force field with
  TIP4P water molecules. THis re-sorts the atoms in the water solvent chains
  (C2,C3) to group all 4 atoms as one contiguous residue. It also aliases the
  ion charges 'pseu' atom to 'OM' for use with the standard tip4p.par parameter
  file. The set_backbone option is to set constraint during initial minimzation"""

    # Grab unit cell description (should be on first few lines:
    cryst = None
    with open(src_filename) as src:
        for line in src.readlines():
            if line.startswith('CRYST1'):
                cryst = line
                break

    # Read in source PDB (DEShaw original format)
    src_pdb = PdbStructure(open(src_filename))
    atoms = list(src_pdb.iter_atoms())
    topo = md.load(src_filename).top

    # Break into 4 segments
    segment_list = ['C1', 'C2', 'C3', 'C4']
    segment = {l: [] for l in segment_list}
    for i in atoms:
        segment[i.segment_id].append(i)

    # Set temperature factor (for gradual heating)
    if set_backbone:
        backbone = topo.select("backbone")
        for i in range(0, len(segment['C1'])):
            if i in backbone:
                segment['C1'][i].location.temperature_factor = 1.0

    # Resort water segements and alias "pseu" to OM (tip4p forcefield)
    for wat in ['C2', 'C3']:
        segment[wat] = sorted(segment[wat], key=lambda i: i.residue_number)
        start_serial_num = min(segment[wat], key=lambda i: i.serial_number)
        for i in range(0, len(segment[wat])):
            newsn = i + start_serial_num.serial_number
            segment[wat][i].serial_number = newsn
            if segment[wat][i].get_name == 'pseu':
                segment[wat][i].set_name_with_spaces(' OM ')

    # FOR RE-RUNNING THE PSFGEN
    if split_dir is not None:
        for s in segment_list:
            with open(split_dir + '/%s.pdb' % s, 'w') as dest:
                for atom in segment[s]:
                    _ = dest.write(str(atom) + '\n')

    # Writeout new file
    if in_place:
        dest = open(src_filename, 'w')
        if cryst is not None:
            dest.write(cryst)
        for s in segment_list:
            for atom in segment[s]:
                _ = dest.write(str(atom) + '\n')
        _ = dest.write('END')
        dest.close()