Exemplo n.º 1
0
def test_read_pdb():
   """Tests that pdb files are read correctly."""

   with open(local("test.pos_0.pdb"), "r") as f:
      atoms, cell = io_pdb.read_pdb(f)
      assert(len(atoms) == 3)
      assert_equal(pos, atoms.q)
Exemplo n.º 2
0
def init_pdb(filename):
    """Reads an pdb file and returns the data contained in it.

   Args:
      filename: A string giving the name of the pdb file to be read from.

   Returns:
      A list of Atoms objects as read from each frame of the pdb file, and
      a Cell object as read from the final pdb frame.
   """

    rfile = open(filename, "r")
    ratoms = []
    while True:
        #while loop, so that more than one configuration can be given
        #so multiple beads can be initialized at once.
        try:
            myatoms, rcell = read_pdb(rfile)
        except EOFError:
            break
        ratoms.append(myatoms)
    return (ratoms, rcell)  # if multiple frames, the last cell is returned
Exemplo n.º 3
0
def init_pdb(filename):
   """Reads an pdb file and returns the data contained in it.

   Args:
      filename: A string giving the name of the pdb file to be read from.

   Returns:
      A list of Atoms objects as read from each frame of the pdb file, and
      a Cell object as read from the final pdb frame.
   """

   rfile = open(filename,"r")
   ratoms = []
   while True:
   #while loop, so that more than one configuration can be given
   #so multiple beads can be initialized at once.
      try:
         myatoms, rcell  = read_pdb(rfile)
      except EOFError:
         break
      ratoms.append(myatoms)
   return ( ratoms, rcell ) # if multiple frames, the last cell is returned
Exemplo n.º 4
0
    def step(self):
        """Does one simulation time step."""

        self.ptime = self.ttime = 0
        self.qtime = -time.time()

        try:
            if (self.intraj.mode == "xyz"):
                for b in self.beads:
                    myatoms = read_xyz(self.rfile)
                    myatoms.q *= unit_to_internal("length", self.intraj.units,
                                                  1.0)
                    b.q[:] = myatoms.q
            elif (self.intraj.mode == "pdb"):
                for b in self.beads:
                    myatoms, mycell = read_pdb(self.rfile)
                    myatoms.q *= unit_to_internal("length", self.intraj.units,
                                                  1.0)
                    mycell.h *= unit_to_internal("length", self.intraj.units,
                                                 1.0)
                    b.q[:] = myatoms.q
                self.cell.h[:] = mycell.h
            elif (self.intraj.mode == "chk"
                  or self.intraj.mode == "checkpoint"):
                # reads configuration from a checkpoint file
                xmlchk = xml_parse_file(self.rfile)  # Parses the file.

                from ipi.inputs.simulation import InputSimulation
                simchk = InputSimulation()
                simchk.parse(xmlchk.fields[0][1])
                mycell = simchk.cell.fetch()
                mybeads = simchk.beads.fetch()
                self.cell.h[:] = mycell.h
                self.beads.q[:] = mybeads.q
                softexit.trigger(" # Read single checkpoint")
        except EOFError:
            softexit.trigger(" # Finished reading re-run trajectory")

        self.qtime += time.time()
Exemplo n.º 5
0
    def step(self):
        """Does one simulation time step."""

        self.ptime = self.ttime = 0
        self.qtime = -time.time()

        try:
            if self.intraj.mode == "xyz":
                for b in self.beads:
                    myatoms = read_xyz(self.rfile)
                    myatoms.q *= unit_to_internal("length", self.intraj.units, 1.0)
                    b.q[:] = myatoms.q
            elif self.intraj.mode == "pdb":
                for b in self.beads:
                    myatoms, mycell = read_pdb(self.rfile)
                    myatoms.q *= unit_to_internal("length", self.intraj.units, 1.0)
                    mycell.h *= unit_to_internal("length", self.intraj.units, 1.0)
                    b.q[:] = myatoms.q
                self.cell.h[:] = mycell.h
            elif self.intraj.mode == "chk" or self.intraj.mode == "checkpoint":
                # reads configuration from a checkpoint file
                xmlchk = xml_parse_file(self.rfile)  # Parses the file.

                from ipi.inputs.simulation import InputSimulation

                simchk = InputSimulation()
                simchk.parse(xmlchk.fields[0][1])
                mycell = simchk.cell.fetch()
                mybeads = simchk.beads.fetch()
                self.cell.h[:] = mycell.h
                self.beads.q[:] = mybeads.q
                softexit.trigger(" # Read single checkpoint")
        except EOFError:
            softexit.trigger(" # Finished reading re-run trajectory")

        self.qtime += time.time()