def test_uio66zrbrick_crossterms(): with log.section('NOSETEST', 2): # Load input data for a ficticious system of an isolated # UiO-66 brick with path('quickff.data.systems.uio66-zr-brick', 'system.chk') as fn: data = load_chk(fn) system = System(data['numbers'],data['pos'],charges=data['charges'], ffatypes=data['ffatypes'],bonds=data['bonds'],radii=data['radii']) system.set_standard_masses() ai = SecondOrderTaylor('ai', coords=system.pos.copy(), grad=data['gradient'], hess=data['hessian']) # Run QuickFF with tmpdir('test_uio66') as dn: fn_yaff = os.path.join(dn, 'pars_cov.txt') fn_sys = os.path.join(dn, 'system.chk') fn_log = os.path.join(dn, 'quickff.log') program = DeriveFF(system, ai, Settings(consistent_cross_rvs=True, remove_dysfunctional_cross=True,fn_yaff=fn_yaff,fn_sys=fn_sys,log_file=fn_log)) program.run() # Check force constants of cross terms and corresponding diagonal terms print("%50s %15s %15s"%("Basename","Cross FC","Diag FC")) for term in program.valence.terms: if not term.is_master(): continue if term.basename.startswith('Cross'): fc = program.valence.get_params(term.index, only='fc') for i in [0,1]: fc_diag = program.valence.get_params(term.diag_term_indexes[i], only='fc') print("%50s %15.6f %15.6f %50s" % (term.basename,fc,fc_diag,program.valence.terms[term.diag_term_indexes[i]].basename)) if fc_diag==0.0: assert fc==0.0
def test_uio66zrbrick_crossterms(): with log.section('NOSETEST', 2): # Load input data for a ficticious system of an isolated # UiO-66 brick name = 'uio66-zr-brick/system.chk' fn = context.get_fn(os.path.join('systems', name)) data = load_chk(fn) system = System(data['numbers'],data['pos'],charges=data['charges'], ffatypes=data['ffatypes'],bonds=data['bonds'],radii=data['radii']) system.set_standard_masses() ai = SecondOrderTaylor('ai', coords=system.pos.copy(), grad=data['gradient'], hess=data['hessian']) # Run QuickFF with tmpdir('test_uio66') as dn: fn_yaff = os.path.join(dn, 'pars_cov.txt') fn_sys = os.path.join(dn, 'system.chk') fn_log = os.path.join(dn, 'quickff.log') program = DeriveFF(system, ai, Settings(consistent_cross_rvs=True, remove_dysfunctional_cross=True,fn_yaff=fn_yaff,fn_sys=fn_sys,log_file=fn_log)) program.run() # Check force constants of cross terms and corresponding diagonal terms print("%50s %15s %15s"%("Basename","Cross FC","Diag FC")) for term in program.valence.terms: if not term.is_master(): continue if term.basename.startswith('Cross'): fc = program.valence.get_params(term.index, only='fc') for i in [0,1]: fc_diag = program.valence.get_params(term.diag_term_indexes[i], only='fc') print("%50s %15.6f %15.6f %50s" % (term.basename,fc,fc_diag,program.valence.terms[term.diag_term_indexes[i]].basename)) if fc_diag==0.0: assert fc==0.0
def test_methane_consistent_crossterms(): with log.section('NOSETEST', 2): system, ai = read_system('methane/gaussian.fchk') set_ffatypes(system, 'high') for consistent in [False, True]: with tmpdir('test_methane_%s'%('consistent' if consistent else 'inconsistent')) as dn: fn_yaff = os.path.join(dn, 'pars_cov.txt') fn_sys = os.path.join(dn, 'system.chk') program = DeriveFF(system, ai, Settings(consistent_cross_rvs=consistent, fn_yaff=fn_yaff,fn_sys=fn_sys,do_cross_DSS=True,do_cross_DSD=True, do_cross_DAA=True,do_cross_DAD=True)) program.run() compare_crossterm_rest_values(program,equal=consistent)
def test_output_charmm22(): with log.section('NOSETST', 2): system, ai = read_system('ethanol/gaussian.fchk') set_ffatypes(system, 'low') with tmpdir('test_output_charmm22') as dn: fn_yaff = os.path.join(dn, 'pars_cov.txt') fn_charmm22_prm = os.path.join(dn, 'test.prm') fn_charmm22_psf = os.path.join(dn, 'test.psf') fn_sys = os.path.join(dn, 'system.chk') settings = Settings( do_cross_ASS=False, do_cross_ASA=False, fn_yaff=fn_yaff, fn_sys=fn_sys, fn_charmm22_prm=fn_charmm22_prm, fn_charmm22_psf=fn_charmm22_psf, ) program = DeriveFF(system, ai, settings) program.run() assert os.path.isfile(fn_yaff) assert os.path.isfile(fn_charmm22_prm) assert os.path.isfile(fn_charmm22_psf) assert os.path.isfile(fn_sys) # Count the number of BOND, ANGLES and DIHEDRAL lines in the PRM file. counts = {} with open(fn_charmm22_prm, 'r') as f: for line in f: print line line = line[:line.find('!')].strip() if len(line) == 0: continue if line in ['BONDS','ANGLES', 'DIHEDRALS', 'IMPROPER']: key = line counts[key] = 0 else: counts[key] += 1 assert counts['BONDS'] == 4 assert counts['ANGLES'] == 5 assert counts['DIHEDRALS'] == 2 assert counts['IMPROPER'] == 0 # Count the number atoms, bonds, angles and dihedrals in the PSF file and # check for consistency. with open(fn_charmm22_psf, 'r') as f: natom = 0 assert f.next() == 'PSF\n' for line in f: if '!NATOM' in line: natom = int(line.split()[0]) break assert natom == system.natom for iatom in xrange(natom+1): f.next() line = f.next() assert '!NBOND: bonds' in line nbond = int(line.split()[0]) nline = int(np.ceil(nbond/4.0)) numbers = (''.join([f.next() for iline in xrange(nline)])).split() assert len(numbers) == nbond*2 f.next() line = f.next() assert '!NTHETA: angles' in line ntheta = int(line.split()[0]) nline = int(np.ceil(ntheta/3.0)) numbers = (''.join([f.next() for iline in xrange(nline)])).split() assert len(numbers) == ntheta*3 f.next() line = f.next() assert '!NPHI: dihedrals' in line nphi = int(line.split()[0]) nline = int(np.ceil(nphi/2.0)) numbers = (''.join([f.next() for iline in xrange(nline)])).split() assert len(numbers) == nphi*4 f.next() line = f.next() assert '!NIMPHI: impropers' in line nimphi = int(line.split()[0]) assert nimphi == 0
def test_output_charmm22(): with log.section('NOSETST', 2): system, ai = read_system('ethanol/gaussian.fchk') set_ffatypes(system, 'low') with tmpdir('test_output_charmm22') as dn: fn_yaff = os.path.join(dn, 'pars_cov.txt') fn_charmm22_prm = os.path.join(dn, 'test.prm') fn_charmm22_psf = os.path.join(dn, 'test.psf') fn_sys = os.path.join(dn, 'system.chk') settings = Settings( do_cross_ASS=False, do_cross_ASA=False, fn_yaff=fn_yaff, fn_sys=fn_sys, fn_charmm22_prm=fn_charmm22_prm, fn_charmm22_psf=fn_charmm22_psf, ) program = DeriveFF(system, ai, settings) program.run() assert os.path.isfile(fn_yaff) assert os.path.isfile(fn_charmm22_prm) assert os.path.isfile(fn_charmm22_psf) assert os.path.isfile(fn_sys) # Count the number of BOND, ANGLES and DIHEDRAL lines in the PRM file. counts = {} with open(fn_charmm22_prm, 'r') as f: for line in f: print(line) line = line[:line.find('!')].strip() if len(line) == 0: continue if line in ['BONDS','ANGLES', 'DIHEDRALS', 'IMPROPER']: key = line counts[key] = 0 else: counts[key] += 1 assert counts['BONDS'] == 4 assert counts['ANGLES'] == 5 assert counts['DIHEDRALS'] == 3 assert counts['IMPROPER'] == 0 # Count the number atoms, bonds, angles and dihedrals in the PSF file and # check for consistency. with open(fn_charmm22_psf, 'r') as f: natom = 0 assert next(f) == 'PSF\n' for line in f: if '!NATOM' in line: natom = int(line.split()[0]) break assert natom == system.natom for iatom in range(natom+1): next(f) line = next(f) assert '!NBOND: bonds' in line nbond = int(line.split()[0]) nline = int(np.ceil(nbond/4.0)) numbers = (''.join([next(f) for iline in range(nline)])).split() assert len(numbers) == nbond*2 next(f) line = next(f) assert '!NTHETA: angles' in line ntheta = int(line.split()[0]) nline = int(np.ceil(ntheta/3.0)) numbers = (''.join([next(f) for iline in range(nline)])).split() assert len(numbers) == ntheta*3 next(f) line = next(f) assert '!NPHI: dihedrals' in line nphi = int(line.split()[0]) nline = int(np.ceil(nphi/2.0)) numbers = (''.join([next(f) for iline in range(nline)])).split() assert len(numbers) == nphi*4 next(f) line = next(f) assert '!NIMPHI: impropers' in line nimphi = int(line.split()[0]) assert nimphi == 0