Beispiel #1
0
def test_write():
    gro = Trajectory.open(cwd + '/files/100-SPCE.gro')
    tmp = os.path.join(tempdir, 'gro-out.xtc')
    xtc = Trajectory.open(tmp, 'w')
    for i in range(gro.n_frame):
        frame = gro.read_frame(i)
        xtc.write_frame(frame)
    xtc.close()
    assert filecmp.cmp(tmp, cwd + '/files/baselines/gro-out.xtc')
Beispiel #2
0
def test_write():
    top = Topology.open(cwd + '/files/100-SPCE.psf')
    xtc = Trajectory.open(cwd + '/files/100-SPCE.xtc')
    tmp = os.path.join(tempdir, 'xtc-out.xyz')
    xyz = Trajectory.open(tmp, 'w')
    for i in range(xtc.n_frame):
        frame = xtc.read_frame(i)
        xyz.write_frame(frame, top, subset=list(range(150, 300)))
    xyz.close()
    filecmp.cmp(tmp, cwd + '/files/baselines/xtc-out.xyz')
Beispiel #3
0
def test_write():
    gro = Trajectory.open(cwd + '/files/100-SPCE.gro')
    tmp = os.path.join(tempdir, 'gro-out.dcd')
    dcd = Trajectory.open(tmp, 'w')
    for i in range(gro.n_frame):
        frame = gro.read_frame(i)
        dcd.write_frame(frame)
    dcd.close()
    # It's annoying that DCD files generated are different every time. Compare the size instead of the content.
    assert os.path.getsize(tmp) == os.path.getsize(
        cwd + '/files/baselines/gro-out.dcd')
Beispiel #4
0
def test_read():
    trj = Trajectory.open(
        [cwd + '/files/100-SPCE.gro', cwd + '/files/100-SPCE.lammpstrj'])
    assert trj.n_atom == 300
    assert trj.n_frame == 6

    frame = trj.read_frame(0)
    assert frame.has_velocity == True
    assert pytest.approx(frame.positions[0], abs=1E-6) == [1.283, 1.791, 1.658]
    assert frame.has_charge == False

    frame = trj.read_frame(1)
    assert frame.cell.is_rectangular
    assert pytest.approx(frame.cell.size,
                         abs=1E-6) == [3.00906, 3.00906, 3.00906]
    assert pytest.approx(frame.velocities[-1],
                         abs=1E-6) == [-1.0323, 0.5604, -0.3797]

    frame = trj.read_frame(2)
    assert frame.has_velocity == False
    assert pytest.approx(frame.positions[0],
                         abs=1E-6) == [2.2545, 1.45688, 1.98961]
    assert frame.has_charge == True
    assert pytest.approx(frame.charges[:4],
                         abs=1E-6) == [0.4238, -0.8476, 0.4238, 0.4238]

    frame = trj.read_frame(3)
    assert frame.cell.is_rectangular
    assert pytest.approx(frame.cell.size, abs=1E-6) == [3.0004316] * 3
    assert pytest.approx(frame.positions[-1],
                         abs=1E-6) == [2.11148, 0.241373, 0.664092]
Beispiel #5
0
def test_read():
    xyz = Trajectory.open(cwd + '/files/100-SPCE.xyz')
    assert xyz.n_frame == 4
    assert xyz.n_atom == 300
    frame1 = xyz.read_frame(1)
    assert pytest.approx(frame1.positions[150],
                         abs=1E-6) == [1.227000, 1.109000, 2.458000]
    frame2, frame0 = xyz.read_frames([2, 0])
    assert pytest.approx(frame0.positions[150],
                         abs=1E-6) == [1.410000, 1.315000, 2.851000]
    assert pytest.approx(frame2.positions[-1],
                         abs=1E-6) == [2.529000, 0.136000, 1.780000]
Beispiel #6
0
def test_read():
    gro = Trajectory.open(cwd + '/files/100-SPCE.gro')
    assert gro.n_atom == 300
    assert gro.n_frame == 2

    frame = gro.read_frame(0)
    assert frame.has_velocity == True
    assert pytest.approx(frame.positions[0], abs=1E-6) == [1.283, 1.791, 1.658]

    frame = gro.read_frame(1)
    assert frame.cell.is_rectangular
    assert pytest.approx(frame.cell.size,
                         abs=1E-6) == [3.00906, 3.00906, 3.00906]
    assert pytest.approx(frame.velocities[-1],
                         abs=1E-6) == [-1.0323, 0.5604, -0.3797]
Beispiel #7
0
def test_read():
    xtc = Trajectory.open(cwd + '/files/100-SPCE.xtc')
    assert xtc.n_atom == 300
    assert xtc.n_frame == 4

    frame = xtc.read_frame(0)
    assert frame.has_velocity == False
    assert frame.has_charge == False
    assert pytest.approx(frame.positions[0], abs=1E-4) == [1.283, 1.791, 1.658]
    assert pytest.approx(frame.positions[-1],
                         abs=1E-4) == [2.726, 2.750, 1.876]

    frame2, frame1 = xtc.read_frames([2, 1])
    assert pytest.approx(frame1.positions[0],
                         abs=1E-4) == [1.335, 1.775, 1.818]
    assert pytest.approx(frame2.positions[-1],
                         abs=1E-4) == [2.529, 0.136, 1.780]
Beispiel #8
0
def test_read():
    dcd = Trajectory.open(cwd + '/files/100-SPCE.dcd')
    assert dcd.n_atom == 300
    assert dcd.n_frame == 3

    frame = dcd.read_frame(0)
    assert frame.has_velocity == False
    assert frame.has_charge == False
    assert pytest.approx(frame.positions[0],
                         abs=1E-6) == [1.180277, 1.421659, 1.885429]

    frame2, frame1 = dcd.read_frames([2, 1])
    assert pytest.approx(frame1.positions[0],
                         abs=1E-6) == [1.645082, 1.233684, 2.165311]
    assert pytest.approx(frame2.positions[-1],
                         abs=1E-6) == [2.545774, 2.661569, 1.707037]
    assert pytest.approx(frame2.cell.lengths,
                         abs=1E-6) == [2.983427, 2.983427, 2.983427]
Beispiel #9
0
def test_read():
    trj = Trajectory.open(cwd + '/files/100-SPCE.lammpstrj')
    assert trj.n_atom == 300
    assert trj.n_frame == 4

    frame = trj.read_frame(0)
    assert frame.has_velocity == False
    assert pytest.approx(frame.positions[0],
                         abs=1E-6) == [2.2545, 1.45688, 1.98961]
    assert frame.has_charge == True
    assert pytest.approx(frame.charges[:4],
                         abs=1E-6) == [0.4238, -0.8476, 0.4238, 0.4238]

    frame = trj.read_frame(1)
    assert frame.cell.is_rectangular
    assert pytest.approx(frame.cell.size, abs=1E-6) == [3.0004316] * 3
    assert pytest.approx(frame.positions[-1],
                         abs=1E-6) == [2.11148, 0.241373, 0.664092]
Beispiel #10
0
    ],
    "EAN-N": [
        atom.id for atom in top.atoms
        if atom.symbol == 'N' and atom.molecule.name == 'N0002'
    ],
    "EAN-O": [
        atom.id for atom in top.atoms
        if atom.symbol == 'O' and atom.molecule.name == 'NO3'
    ],
}
idx_dict = {k: v for k, v in idx_dict.items() if v}

print(len(idx_zn1), len(idx_zn2))
print({k: len(l) for k, l in idx_dict.items()})

trj = Trajectory.open(args.input)

if args.end > trj.n_frame or args.end == -1:
    args.end = trj.n_frame


def wrap_pbc(positions, origin, cell):
    displace_array = positions - origin
    delta_array = np.floor(displace_array / cell.lengths + 0.5)
    return positions - delta_array * cell.lengths


def cartesian2cylindrical(positions, origin, vec_unit):
    vec_relative = positions - origin
    z_array = vec_relative.dot(vec_unit)
    rsq_array = np.sum(vec_relative * vec_relative, axis=1) - z_array**2
Beispiel #11
0
else:
    typer = None

molecules = []
for inp, n in zip(args.input, args.number):
    if inp.startswith(':'):
        if typer is None:
            raise Exception('--typer is required for SMILES input')
    top = Topology.open(inp)
    molecules += top.molecules * n
top = Topology(molecules)
top.remove_drude_particles()
top.remove_virtual_sites()

if args.trj is not None:
    frame = Trajectory.read_frame_from_file(args.trj, -1)
    if frame.cell.volume != 0:
        top.cell.set_box(frame.cell.vectors)

if args.box is not None:
    top.cell.set_box(args.box)

ff = ForceField.open(*args.forcefield)
if args.nodrude:
    ff.polarizable_terms.clear()
    ff.virtual_site_terms.clear()
if args.ljscale is not None:
    scaler = PaduaLJScaler(args.ljscale)
    scaler.scale(ff)

if args.scaleeps != 1.0 or args.scalesig != 1.0:
Beispiel #12
0
                    required=True,
                    type=str,
                    help='output dcd file')
parser.add_argument('--anode',
                    required=True,
                    type=float,
                    help='z coordinate (in nm) of anode (right electrode)')
parser.add_argument('--ignore',
                    nargs='+',
                    default=[],
                    type=str,
                    help='ignore these atom types')
args = parser.parse_args()

top = Topology.open(args.topology)
trj = Trajectory.open(args.input)
frame = trj.read_frame(0)

atoms_non_img = [atom for atom in top.atoms if atom.type != 'IMG']
ids_gen = [atom.id for atom in atoms_non_img if atom.type not in args.ignore]

print('Topology info: ', top.n_atom, 'atoms;', top.n_molecule, 'molecules')
print('Trajectory info: ', trj.n_atom, 'atoms;', trj.n_frame, 'frames')
print('Image info: ', len(atoms_non_img), 'non-image atoms;', len(ids_gen),
      'images to gen')

assert len(atoms_non_img) == trj.n_atom
assert trj.n_atom + len(ids_gen) == top.n_atom

trj_out = Trajectory.open(args.output, 'w')