def test_msibi_optimize_states(self, state0, pair, tmp_path): opt = MSIBI(2.5, n_bins, pot_cutoff=2.5) opt.add_state(state0) opt.add_pair(pair) opt.optimize(n_iterations=0, integrator="hoomd.md.integrate.nvt", integrator_kwargs={"tau": 0.1}, dt=0.001, gsd_period=100, engine="hoomd", _dir=tmp_path)
def test_rdf_length(self, state0, pair, tmp_path): opt = MSIBI(2.5, n_bins + 1, pot_cutoff=2.5) opt.add_state(state0) opt.add_pair(pair) with pytest.raises(ValueError): opt.optimize(n_iterations=0, integrator="hoomd.md.integrate.nvt", integrator_kwargs={"tau": 0.1}, dt=0.001, gsd_period=100, engine="hoomd", _dir=tmp_path)
def test_msibi_init_single_cutoff(self): opt = MSIBI(2.5, n_bins) assert opt.pot_cutoff == opt.rdf_cutoff assert opt.n_rdf_points == n_bins assert opt.rdf_n_bins == n_bins assert opt.r_switch == opt.pot_r[-5] assert opt.dr == 0.1 / 6.0 assert opt.smooth_rdfs is False assert opt.rdf_r_range.shape[0] == 2 assert opt.pot_r.shape[0] == n_bins
def test_current_rdf_smooth(self, state0, pair, tmp_path): opt = MSIBI(2.5, n_bins, smooth_rdfs=True) opt.add_state(state0) opt.add_pair(pair) opt.optimize( n_iterations=0, _dir=tmp_path, integrator="hoomd.md.integrate.nvt", integrator_kwargs={"tau": 0.1}, dt=0.001, gsd_period=1000 ) pair.compute_current_rdf(state0, opt.smooth_rdfs, query=False) assert pair._states[state0]["current_rdf"] is not None assert len(pair._states[state0]["f_fit"]) > 0
def test_update_potential(self, state0, pair, tmp_path): """Make sure the potential changes after calculating RDF""" opt = MSIBI(2.5, n_bins) opt.add_state(state0) opt.add_pair(pair) opt.optimize( n_iterations=0, _dir=tmp_path, integrator="hoomd.md.integrate.nvt", integrator_kwargs={"tau": 0.1}, dt=0.001, gsd_period=1000 ) pair.compute_current_rdf(state0, opt.smooth_rdfs, query=False) pair.update_potential(np.arange(0, 2.5 + dr, dr), r_switch=1.8) assert not np.array_equal(pair.potential, pair.previous_potential)
def test_add_state(self, pair, state0, rdf0, tmp_path): opt = MSIBI(2.5, n_bins, smooth_rdfs=True, rdf_exclude_bonded=True) opt.add_state(state0) opt.add_pair(pair) opt.optimize( n_iterations=0, _dir=tmp_path, integrator="hoomd.md.integrate.nvt", integrator_kwargs={"tau": 0.1}, dt=0.001, gsd_period=1000 ) assert isinstance(pair._states, dict) assert np.array_equal(pair._states[state0]["target_rdf"], rdf0) assert pair._states[state0]["current_rdf"] is None assert pair._states[state0]["alpha"] == 0.5 assert pair._states[state0]["pair_indices"] is None assert len(pair._states[state0]["f_fit"]) == 0
def test_save_current_rdf(self, state0, pair, tmp_path): opt = MSIBI(2.5, n_bins, smooth_rdfs=True) opt.add_state(state0) opt.add_pair(pair) opt.optimize( n_iterations=0, _dir=tmp_path, integrator="hoomd.md.integrate.nvt", integrator_kwargs={"tau": 0.1}, dt=0.001, gsd_period=1000 ) pair.compute_current_rdf(state0, opt.smooth_rdfs, query=False) pair.save_current_rdf(state0, 0, opt.dr) assert os.path.isfile( os.path.join( state0.dir, f"pair_{pair.name}-state_{state0.name}-step0.txt" ) )
import itertools import os import numpy as np from msibi import MSIBI, Pair, State, mie os.system("rm state*/_* rdfs/pair* potentials/* f_fits.log state*/log.txt") os.system("rm state*/err.txt") os.system("rm state*/query.dcd") # Set up global parameters. rdf_cutoff = 5.0 opt = MSIBI(rdf_cutoff=rdf_cutoff, n_rdf_points=101, pot_cutoff=3.0, smooth_rdfs=True) # Specify states. state0 = State( kT=0.5, state_dir="./state0", top_file="start.hoomdxml", name="state0", backup_trajectory=True, ) state1 = State( kT=1.5, state_dir="./state1", top_file="start.hoomdxml", name="state1",
import itertools import os import numpy as np from msibi import MSIBI, State, Pair, mie os.system('rm state*/_* rdfs/pair* potentials/* f_fits.log state*/log.txt') os.system('rm state*/err.txt') os.system('rm state*/query.dcd') # Set up global parameters. rdf_cutoff = 5.0 opt = MSIBI(rdf_cutoff=rdf_cutoff, n_rdf_points=101, pot_cutoff=3.0, smooth_rdfs=True) # Specify states. state0 = State(kT=0.5, state_dir='./state0', top_file='start.hoomdxml', name='state0', backup_trajectory=True) state1 = State(kT=1.5, state_dir='./state1', top_file='start.hoomdxml', name='state1', backup_trajectory=True) state2 = State(kT=2.0, state_dir='./state2', top_file='start.hoomdxml', name='state2', backup_trajectory=True) states = [state0, state1, state2] # Specify pairs. indices = list(itertools.combinations(range(1468), 2)) # all-all for 1468 atoms initial_guess = mie(opt.pot_r, 1.0, 1.0) # 1-D array of potential values. rdf_targets = [np.loadtxt('rdfs/rdf.target{0:d}.t1t1.txt'.format(i)) for i in range(3)]
import itertools import numpy as np import os from msibi import MSIBI, State, Pair, mie # Clear out the temp files os.system('rm state*/_* rdfs/pair* potentials/* f_fits.log state*/log.txt') os.system('rm state*/err.txt') # Set up global parameters. rdf_cutoff = 1.0 opt = MSIBI(engine='lammps', rdf_cutoff=rdf_cutoff, n_rdf_points=100, pot_cutoff=1.0, smooth_rdfs=True, max_frames=50) # Specify states. state0 = State(k=1, T=0.5, state_dir='./state_lmp', top_file='target.pdb', traj_file='query.dcd', name='state0', backup_trajectory=True) states = [state0] # Specify pairs. indices = list(itertools.combinations(range(3000), 2)) # all-all for 1468 atoms initial_guess = mie(opt.pot_r, 0.01, 0.2) # 1-D array of potential values. #rdf_target = np.loadtxt('rdfs/lmp.rdf') rdf_target = np.loadtxt('rdfs/lmp.target.txt') pair0 = Pair('1', '1', initial_guess, head_correction_form='linear') alphas = [1.0]