Ejemplo n.º 1
0
def get_tangent_trj_str(atoms,
                        coords,
                        tangent,
                        comment=None,
                        points=10,
                        displ=None):
    if displ is None:
        # Linear equation. Will give displ~3 for 30 atoms and
        # displ ~ 1 for 3 atoms.
        # displ = 2/27 * len(atoms) + 0.78

        # Logarithmic function f(x) = a*log(x) + b
        # f(3) = ~1 and (f30) = ~2 with a = 0.43429 and b = 0.52288
        # I guess this works better, because only some atoms move, even in bigger
        # systems and the log function converges against a certain value, whereas
        # the linear function just keeps growing.
        displ = 0.43429 * log(len(atoms)) + 0.52288
    step_sizes = np.linspace(-displ, displ, 2 * points + 1)
    steps = step_sizes[:, None] * tangent
    trj_coords = coords[None, :] + steps
    trj_coords = trj_coords.reshape(step_sizes.size, -1, 3) / ANG2BOHR

    comments = None
    if comment:
        comments = [comment] * step_sizes.size
    trj_str = make_trj_str(atoms, trj_coords, comments=comments)

    return trj_str
Ejemplo n.º 2
0
def dump_coords(atoms, coords, trj_fn):
    coords = np.array(coords)
    coords = coords.reshape(-1, len(atoms), 3) * BOHR2ANG
    trj_str = make_trj_str(atoms, coords)

    with open(trj_fn, "w") as handle:
        handle.write(trj_str)
Ejemplo n.º 3
0
def test_oniom_md():
    calc_dict = {
        "high": {
            "type": "pypsi4",
            "method": "scf",
            "basis": "sto-3g",
        },
        "low": {
            "type": "pyxtb",
        },
    }
    high_inds = (4, 5, 6)
    from pysisyphus.calculators.ONIOM import ONIOM
    oniom = ONIOM(calc_dict, high_inds)

    geom = geom_loader("lib:acetaldehyd_oniom.xyz")
    geom.set_calculator(oniom)

    v0 = .005 * np.random.rand(*geom.coords.shape)
    md_kwargs = {
        "v0": v0,
        "t": 40,
        "dt": 0.5,
    }
    md_result = md(geom, **md_kwargs)
    from pysisyphus.xyzloader import make_trj_str

    coords = md_result.coords.reshape(-1, len(geom.atoms), 3) * BOHR2ANG
    trj_str = make_trj_str(geom.atoms, coords)
    with open("md.trj", "w") as handle:
        handle.write(trj_str)
Ejemplo n.º 4
0
def test_fragmentation():
    fn = "01_dihedral_scan.009.xyz"
    geom = geom_from_xyz_file(fn, coord_type="redund")

    prim_coord = (19, 20)
    bbis = geom.internal.bare_bond_indices.tolist()
    _ = bbis.copy()
    bbis.remove(list(sorted(prim_coord)))
    import pdb
    pdb.set_trace()
    # bbis.delete(

    frag_kwargs = {
        "step": 6,
        "step_num": 10,
    }
    cc = fragment(geom, prim_coord, **frag_kwargs)
    cc = np.reshape(cc, (-1, len(geom.atoms), 3)) * BOHR2ANG
    trj_str = make_trj_str(geom.atoms, cc)
    with open("fragmented.xyz", "w") as handle:
        handle.write(trj_str)
Ejemplo n.º 5
0
    def write_trj(self, path, prefix, coords=None):
        path = pathlib.Path(path)
        atoms = self.geometry.atoms
        if coords is None:
            coords = self.all_mw_coords
        coords = coords.copy()
        coords /= self.m_sqrt
        coords = coords.reshape(-1, len(atoms), 3) * BOHR2ANG
        # all_mw_coords = self.all_mw_coords.flatten()
        trj_string = make_trj_str(atoms, coords, comments=self.all_energies)
        trj_fn = f"{prefix}_irc.trj"
        with open(path / trj_fn, "w") as handle:
            handle.write(trj_string)

        first_coords = coords[0]
        first_fn = f"{prefix}_first.xyz"
        with open(path / first_fn, "w") as handle:
            handle.write(make_xyz_str(atoms, first_coords))

        last_coords = coords[-1]
        first_fn = f"{prefix}_last.xyz"
        with open(path / first_fn, "w") as handle:
            handle.write(make_xyz_str(atoms, last_coords))
 def save(self, out_fn):
     atoms = self.images[0].atoms
     coords_list = [image.coords.reshape((-1, 3)) for image in self.images]
     trj_str = make_trj_str(atoms, coords_list)
     with open(out_fn, "w") as handle:
         handle.write(trj_str)