コード例 #1
0
def create_random_xyz_traj_to_write(request):

    natoms, frames, comment, expected_cell, precision = request.param

    a, b, c, alpha, beta, gamma = mt.h2abc_deg(expected_cell)

    fmt_header = "# CELL(abcABC): %10.5f  %10.5f  %10.5f  %10.5f  %10.5f  %10.5f  %s"

    comment = fmt_header % (a, b, c, alpha, beta, gamma, comment)

    filedesc, xyz, atom_names = xyz_gen.xyz_traj_filedesc(natoms, frames, comment)
    filedesc.seek(0)

    masses = [Elements.mass(_am) for _am in atom_names]

    cell_list = []
    atoms_list = []

    for _fr in xrange(frames):
        cell = Cell(expected_cell)
        atoms = Atoms(natoms)
        atoms.q[:] = xyz[_fr * natoms * 3:(_fr + 1) * natoms * 3]
        atoms.names = atom_names[_fr * natoms:(_fr + 1) * natoms]
        atoms.m[:] = masses[_fr * natoms:(_fr + 1) * natoms]
        atoms_list.append(atoms)
        cell_list.append(cell)

    return (filedesc, atoms_list, cell_list, comment, precision)
コード例 #2
0
def print_instanton_geo(prefix, step, nbeads, natoms, names, q, pots, cell,
                        shift):

    outfile = open(prefix + '_' + str(step) + '.ener', 'w')
    print >> outfile, ('#Bead    Energy (eV)')
    for i in range(nbeads):
        print >> outfile, (
            str(i) + '     ' +
            str(units.unit_to_user('energy', "electronvolt", pots[i] - shift)))
    outfile.close()

    # print_file("xyz", pos[0], cell, out, title='positions{angstrom}')

    unit = 'angstrom'
    a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h)

    outfile = open(prefix + '_' + str(step) + '.xyz', 'w')
    for i in range(nbeads):
        print >> outfile, natoms
        # print >> outfile, (('CELL(abcABC): Traj: positions(%s) Bead: %i' %(unit,i) ))
        print >> outfile, (
            'CELL(abcABC):  %f %f %f %f %f %f cell{atomic_unit}  Traj: positions{%s}   Bead:       %i'
            % (a, b, c, alpha, beta, gamma, unit, i))
        # print >> outfile, ('#Potential (eV):   ' + str(units.unit_to_user('energy', "electronvolt", pots[i] - shift)))

        for j in range(natoms):
            print >> outfile, names[j], \
                str(units.unit_to_user('length', unit, q[i, 3 * j])), \
                str(units.unit_to_user('length', unit, q[i, 3 * j + 1])), \
                str(units.unit_to_user('length', unit, q[i, 3 * j + 2]))

    outfile.close()
コード例 #3
0
def print_pdb(atoms, cell, filedesc=sys.stdout, title=""):
    """Prints an atomic configuration into a pdb formatted file.

    Also prints the cell parameters in standard pdb form. Note
    that the angles are in degrees.

    Args:
        atoms: An atoms object giving the atom positions.
        cell: A cell object giving the system box.
        filedesc: An open writable file object. Defaults to standard output.
        title: An optional string of max. 70 characters.
    """

    fmt_cryst = "CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f%s%4i\n"
    fmt_atom = "ATOM  %5i %4s%1s%3s %1s%4i%1s   %8.3f%8.3f%8.3f%6.2f%6.2f          %2s%2i\n"

    if title != "":
        filedesc.write("TITLE   %70s\n" % (title))

    a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h)

    z = 1
    filedesc.write(fmt_cryst %
                   (a, b, c, alpha, beta, gamma, " P 1        ", z))

    natoms = atoms.natoms
    qs = depstrip(atoms.q)
    lab = depstrip(atoms.names)
    for i in range(natoms):
        data = (i + 1, lab[i], ' ', '  1', ' ', 1, ' ', qs[3 * i],
                qs[3 * i + 1], qs[3 * i + 2], 0.0, 0.0, '  ', 0)
        filedesc.write(fmt_atom % data)

    filedesc.write("END\n")
コード例 #4
0
ファイル: io_xyz.py プロジェクト: Clockwork-Sphinx/lammps
def print_xyz_path(beads, cell, filedesc=sys.stdout):
    """Prints all the bead configurations, into a xyz formatted file.

   Prints all the replicas for each time step separately, rather than all at
   once.

   Args:
      beads: A beads object giving the bead positions.
      cell: A cell object giving the system box.
      filedesc: An open writable file object. Defaults to standard output.
   """

    a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h)

    natoms = beads.natoms
    nbeads = beads.nbeads
    for j in range(nbeads):
        filedesc.write(
            "%d\n# bead: %d CELL(abcABC): %10.5f  %10.5f  %10.5f  %10.5f  %10.5f  %10.5f \n"
            % (natoms, j, a, b, c, alpha, beta, gamma)
        )
        for i in range(natoms):
            qs = depstrip(beads.q)
            lab = depstrip(beads.names)
            filedesc.write("%8s %12.5e %12.5e %12.5e\n" % (lab[i], qs[j][3 * i], qs[j][3 * i + 1], qs[j][3 * i + 2]))
コード例 #5
0
def print_xyz(atoms,
              cell,
              filedesc=sys.stdout,
              title="",
              cell_conv=1.0,
              atoms_conv=1.0):
    """Prints an atomic configuration into an XYZ formatted file.

    Args:
        atoms: An atoms object giving the centroid positions.
        cell: A cell object giving the system box.
        filedesc: An open writable file object. Defaults to standard output.
        title: This gives a string to be appended to the comment line.
    """

    a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h * cell_conv)

    natoms = atoms.natoms
    fmt_header = "%d\n# CELL(abcABC): %10.5f  %10.5f  %10.5f  %10.5f  %10.5f  %10.5f  %s\n"
    filedesc.write(fmt_header % (natoms, a, b, c, alpha, beta, gamma, title))
    # direct access to avoid unnecessary slow-down
    qs = dstrip(atoms.q) * atoms_conv
    lab = dstrip(atoms.names)
    for i in range(natoms):
        filedesc.write("%8s %12.5e %12.5e %12.5e\n" %
                       (lab[i], qs[3 * i], qs[3 * i + 1], qs[3 * i + 2]))
コード例 #6
0
ファイル: instools.py プロジェクト: i-pi/i-pi
def print_instanton_geo(prefix, step, nbeads, natoms, names, q, pots, cell, shift, output_maker):

    outfile = output_maker.get_output(prefix + '_' + str(step) + '.ener', 'w')
    print >> outfile, ('#Bead    Energy (eV)')
    for i in range(nbeads):
        print >> outfile, (str(i) + '     ' + str(units.unit_to_user('energy', "electronvolt", pots[i] - shift)))
    outfile.close()

    # print_file("xyz", pos[0], cell, out, title='positions{angstrom}')

    unit = 'angstrom'
    a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h)

    outfile = output_maker.get_output(prefix + '_' + str(step) + '.xyz', 'w')
    for i in range(nbeads):
        print >> outfile, natoms

        print >> outfile, ('CELL(abcABC):  %f %f %f %f %f %f cell{atomic_unit}  Traj: positions{%s}   Bead:       %i' % (a, b, c, alpha, beta, gamma, unit, i))

        for j in range(natoms):
            print >> outfile, names[j], \
                str(units.unit_to_user('length', unit, q[i, 3 * j])), \
                str(units.unit_to_user('length', unit, q[i, 3 * j + 1])), \
                str(units.unit_to_user('length', unit, q[i, 3 * j + 2]))

    outfile.close()
コード例 #7
0
def print_xyz_path(beads,
                   cell,
                   filedesc=sys.stdout,
                   cell_conv=1.0,
                   atoms_conv=1.0):
    """Prints all the bead configurations into a XYZ formatted file.

    Prints all the replicas for each time step separately, rather than all at
    once.

    Args:
        beads: A beads object giving the bead positions.
        cell: A cell object giving the system box.
        filedesc: An open writable file object. Defaults to standard output.
    """

    a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h * cell_conv)

    fmt_header = "%d\n# bead: %d CELL(abcABC): %10.5f  %10.5f  %10.5f  %10.5f  %10.5f  %10.5f \n"
    natoms = beads.natoms
    nbeads = beads.nbeads
    for j in range(nbeads):
        filedesc.write(fmt_header % (natoms, j, a, b, c, alpha, beta, gamma))
        for i in range(natoms):
            qs = dstrip(beads.q) * atoms_conv
            lab = dstrip(beads.names)
            filedesc.write(
                "%8s %12.5e %12.5e %12.5e\n" %
                (lab[i], qs[j][3 * i], qs[j][3 * i + 1], qs[j][3 * i + 2]))
コード例 #8
0
ファイル: io_pdb.py プロジェクト: Clockwork-Sphinx/lammps
def print_pdb(atoms, cell, filedesc = sys.stdout, title=""):
   """Prints the atom configurations, into a pdb formatted file.

   Also prints the cell parameters in standard pdb form. Note
   that the angles are in degrees.

   Args:
      atoms: An atoms object giving the atom positions.
      cell: A cell object giving the system box.
      filedesc: An open writable file object. Defaults to standard output.
      title: An optional string of max. 70 characters.
   """


   if title != "" :
      filedesc.write("TITLE   %70s\n" % (title))

   a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h)

   z = 1
   filedesc.write("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f%s%4i\n" % (a, b, c, alpha, beta, gamma, " P 1        ", z))

   natoms = atoms.natoms
   qs = depstrip(atoms.q)
   lab = depstrip(atoms.names)
   for i in range(natoms):
      filedesc.write("ATOM  %5i %4s%1s%3s %1s%4i%1s   %8.3f%8.3f%8.3f%6.2f%6.2f          %2s%2i\n" % (i+1, lab[i], ' ', '  1', ' ', 1, ' ', qs[3*i], qs[3*i+1], qs[3*i+2], 0.0, 0.0, '  ', 0))

   filedesc.write("END\n")
コード例 #9
0
def print_pdb_path(beads, cell, filedesc = sys.stdout):
   """Prints all the bead configurations, into a pdb formatted file.

   Prints the ring polymer springs as well as the bead positions using the
   CONECT command. Also prints the cell parameters in standard pdb form. Note
   that the angles are in degrees.

   Args:
      beads: A beads object giving the bead positions.
      cell: A cell object giving the system box.
      filedesc: An open writable file object. Defaults to standard output.
   """

   a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h)

   z = 1 #What even is this parameter?
   filedesc.write("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f%s%4i\n" % (a, b, c, alpha, beta, gamma, " P 1        ", z))

   natoms = beads.natoms
   nbeads = beads.nbeads
   for j in range(nbeads):
      for i in range(natoms):
         qs = depstrip(beads.q)
         lab = depstrip(beads.names)
         filedesc.write("ATOM  %5i %4s%1s%3s %1s%4i%1s   %8.3f%8.3f%8.3f%6.2f%6.2f          %2s%2i\n" % (j*natoms+i+1, lab[i],' ','  1',' ',1,' ', qs[j][3*i], qs[j][3*i+1], qs[j][3*i+2],0.0,0.0,'  ',0))

   if nbeads > 1:
      for i in range(natoms):
         filedesc.write("CONECT%5i%5i\n" % (i+1, (nbeads-1)*natoms+i+1))
      for j in range(nbeads-1):
         for i in range(natoms):
            filedesc.write("CONECT%5i%5i\n" % (j*natoms+i+1, (j+1)*natoms+i+1))

   filedesc.write("END\n")
コード例 #10
0
def print_json(atoms, cell, filedesc=sys.stdout, title="", cell_conv=1.0, atoms_conv=1.0):
    """Prints an atomic configuration into an XYZ formatted file.

    Args:
        atoms: An atoms object giving the centroid positions.
        cell: A cell object giving the system box.
        filedesc: An open writable file object. Defaults to standard output.
        title: This gives a string to be appended to the comment line.
    """

    a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h * cell_conv)

    natoms = atoms.natoms
    # direct access to avoid unnecessary slow-down
    qs = dstrip(atoms.q) * atoms_conv
    lab = dstrip(atoms.names)

    data = {}
    data['natoms'] = natoms
    data['cell'] = [a, b, c, alpha, beta, gamma]
    data['title'] = title
    data['q'] = qs.tolist()
    data['labels'] = lab.tolist()

    filedesc.write(json.dumps(data))
    filedesc.write(" \n")
コード例 #11
0
ファイル: instools.py プロジェクト: robinzyb/i-pi
def print_instanton_geo(prefix, step, nbeads, natoms, names, q, f, pots, cell,
                        shift, output_maker):
    """ Alternative (but very useful) output of the instanton geometry and potential energy """

    outfile = output_maker.get_output(prefix + "_" + str(step) + ".ener", "w")
    print("#Bead    Energy (eV)", file=outfile)
    for i in range(nbeads):
        print(
            (str(i) + "     " +
             str(units.unit_to_user("energy", "electronvolt",
                                    pots[i] - shift))),
            file=outfile,
        )
    outfile.close_stream()

    # print_file("xyz", pos[0], cell, out, title='positions{angstrom}')

    unit = "angstrom"
    unit2 = "atomic_unit"
    a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h)

    outfile = output_maker.get_output(prefix + "_" + str(step) + ".xyz", "w")
    outfile2 = output_maker.get_output(
        prefix + "_forces_" + str(step) + ".xyz", "w")
    for i in range(nbeads):
        print(natoms, file=outfile)
        print(natoms, file=outfile2)

        print(
            ("CELL(abcABC):  %f %f %f %f %f %f cell{atomic_unit}  Traj: positions{%s}   Bead:       %i"
             % (a, b, c, alpha, beta, gamma, unit, i)),
            file=outfile,
        )
        print(
            ("CELL(abcABC):  %f %f %f %f %f %f cell{atomic_unit}  Traj: positions{%s}   Bead:       %i"
             % (a, b, c, alpha, beta, gamma, unit2, i)),
            file=outfile2,
        )
        # print >> outfile, ('#Potential (eV):   ' + str(units.unit_to_user('energy', "electronvolt", pots[i] - shift)))

        for j in range(natoms):
            print(
                names[j],
                str(units.unit_to_user("length", unit, q[i, 3 * j])),
                str(units.unit_to_user("length", unit, q[i, 3 * j + 1])),
                str(units.unit_to_user("length", unit, q[i, 3 * j + 2])),
                file=outfile,
            )

        for j in range(natoms):
            print(
                names[j],
                str(units.unit_to_user("force", unit2, f[i, 3 * j])),
                str(units.unit_to_user("force", unit2, f[i, 3 * j + 1])),
                str(units.unit_to_user("force", unit2, f[i, 3 * j + 2])),
                file=outfile2,
            )
    outfile.close_stream()
    outfile2.close_stream()
コード例 #12
0
ファイル: io_xyz.py プロジェクト: epfl-cosmo/i-pi-dev
def print_xyz(atoms, cell, filedesc=sys.stdout, title="", cell_conv=1.0, atoms_conv=1.0):
    """Prints an atomic configuration into an XYZ formatted file.

    Args:
        atoms: An atoms object giving the centroid positions.
        cell: A cell object giving the system box.
        filedesc: An open writable file object. Defaults to standard output.
        title: This gives a string to be appended to the comment line.
    """

    a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h * cell_conv)

    natoms = atoms.natoms
    fmt_header = "%d\n# CELL(abcABC): %10.5f  %10.5f  %10.5f  %10.5f  %10.5f  %10.5f  %s\n"
    filedesc.write(fmt_header % (natoms, a, b, c, alpha, beta, gamma, title))
    # direct access to avoid unnecessary slow-down
    qs = dstrip(atoms.q) * atoms_conv
    lab = dstrip(atoms.names)
    for i in range(natoms):
        filedesc.write("%8s %12.5e %12.5e %12.5e\n" % (lab[i], qs[3 * i], qs[3 * i + 1], qs[3 * i + 2]))
コード例 #13
0
def print_json(atoms, cell, filedesc=sys.stdout, title=""):
    """Prints an atomic configuration into an XYZ formatted file.

    Args:
        atoms: An atoms object giving the centroid positions.
        cell: A cell object giving the system box.
        filedesc: An open writable file object. Defaults to standard output.
        title: This gives a string to be appended to the comment line.
    """

    a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h)

    natoms = atoms.natoms
    # direct access to avoid unnecessary slow-down
    qs = depstrip(atoms.q)
    lab = depstrip(atoms.names)
    filedesc.write(
        json.dumps([
            natoms, a, b, c, alpha, beta, gamma, title,
            qs.tolist(),
            lab.tolist()
        ]))
    filedesc.write("\n")
コード例 #14
0
ファイル: instools.py プロジェクト: kzinovjev/i-pi
def print_instanton_geo(prefix, step, nbeads, natoms, names, q, f, pots, cell, shift, output_maker):

    outfile = output_maker.get_output(prefix + '_' + str(step) + '.ener', 'w')
    print(('#Bead    Energy (eV)'), file=outfile)
    for i in range(nbeads):
        print((str(i) + '     ' + str(units.unit_to_user('energy', "electronvolt", pots[i] - shift))), file=outfile)
    outfile.close_stream()

    # print_file("xyz", pos[0], cell, out, title='positions{angstrom}')

    unit = 'angstrom'
    unit2 = 'atomic_unit'
    a, b, c, alpha, beta, gamma = mt.h2abc_deg(cell.h)

    outfile = output_maker.get_output(prefix + '_' + str(step) + '.xyz', 'w')
    outfile2 = output_maker.get_output(prefix + '_forces_' + str(step) + '.xyz', 'w')
    for i in range(nbeads):
        print(natoms, file=outfile)
        print(natoms, file=outfile2)

        print(('CELL(abcABC):  %f %f %f %f %f %f cell{atomic_unit}  Traj: positions{%s}   Bead:       %i' % (a, b, c, alpha, beta, gamma, unit, i)), file=outfile)
        print(('CELL(abcABC):  %f %f %f %f %f %f cell{atomic_unit}  Traj: positions{%s}   Bead:       %i' % (a, b, c, alpha, beta, gamma, unit2, i)), file=outfile2)
        # print >> outfile, ('#Potential (eV):   ' + str(units.unit_to_user('energy', "electronvolt", pots[i] - shift)))

        for j in range(natoms):
            print(names[j], \
                str(units.unit_to_user('length', unit, q[i, 3 * j])), \
                str(units.unit_to_user('length', unit, q[i, 3 * j + 1])), \
                str(units.unit_to_user('length', unit, q[i, 3 * j + 2])), file=outfile)

        for j in range(natoms):
            print(names[j], \
                str(units.unit_to_user('force', unit2, f[i, 3 * j])), \
                str(units.unit_to_user('force', unit2, f[i, 3 * j + 1])), \
                str(units.unit_to_user('force', unit2, f[i, 3 * j + 2])), file=outfile2)
    outfile.close_stream()
    outfile2.close_stream()