def make_atoms(): atoms = s22.create_s22_system('Water_dimer') # rotate down in x axis: center = atoms[0].position atoms.translate(-center) h = atoms[3].position[1] - atoms[0].position[1] l = np.linalg.norm(atoms[0].position - atoms[3].position) angle = np.degrees(np.arcsin(h / l)) atoms.rotate(angle, '-z', center=center) return atoms
def make_dimer(constraint=True): """Prepare atoms object for testing""" dimer = s22.create_s22_system("Water_dimer") calc = TIP3P(rc=9.0) dimer.calc = calc if constraint: dimer.constraints = FixBondLengths([(3 * i + j, 3 * i + (j + 1) % 3) for i in range(2) for j in [0, 1, 2]]) return dimer
def test_s22(): fragTest = Fragmentation(s22.s22) minimize = False #minimize = True print 'Relaxed:', minimize fragTest.molecules = [] fragTest.fragments = [] testSet = [ 'Ammonia_dimer', 'Water_dimer', 'Formic_acid_dimer', 'Formamide_dimer', 'Uracil_dimer_h-bonded', '2-pyridoxine_2-aminopyridine_complex', 'Adenine-thymine_Watson-Crick_complex', 'Methane_dimer', 'Ethene_dimer', 'Benzene-methane_complex', 'Benzene_dimer_parallel_displaced', 'Pyrazine_dimer', 'Uracil_dimer_stack', 'Indole-benzene_complex_stack', 'Adenine-thymine_complex_stack', 'Ethene-ethyne_complex', 'Benzene-water_complex', 'Benzene-ammonia_complex', 'Benzene-HCN_complex', 'Benzene_dimer_T-shaped', 'Indole-benzene_T-shape_complex', 'Phenol_dimer' ] for moleculeName in testSet: atoms = s22.create_s22_system(moleculeName) dimer1End = s22.data[moleculeName]['dimer atoms'][0] frag1Atoms = atoms.copy()[:dimer1End] frag2Atoms = atoms.copy()[dimer1End:] calculate_charges(frag1Atoms) calculate_charges(frag2Atoms) atoms.set_charges(np.append(frag1Atoms.get_charges(), frag2Atoms.get_charges())) fragment1 = CHARMMSystem(moleculeName + '_f1', frag1Atoms, minimize = minimize) fragment2 = CHARMMSystem(moleculeName + '_f2', frag2Atoms, minimize = minimize) system = CHARMMSystem(moleculeName, atoms, minimize = minimize, fragment_list = [fragment1.name, fragment2.name]) fragTest.molecules.append(system) fragTest.fragments += [fragment1, fragment2] fragTest.fill_data_reference(data_type='s22') fragTest.run(write=True)
def test_orca_qmmm(): from ase.calculators.tip4p import TIP4P, epsilon0, sigma0 from ase.calculators.orca import ORCA from ase.calculators.qmmm import EIQMMM, LJInteractions from ase.data import s22 atoms = s22.create_s22_system('Water_dimer') qmcalc = ORCA(label='water', orcasimpleinput='BLYP def2-SVP') lj = LJInteractions({('O', 'O'): (epsilon0, sigma0)}) atoms.calc = EIQMMM(selection=[0, 1, 2], qmcalc=qmcalc, mmcalc=TIP4P(), interaction=lj, output='orca_qmmm.log') e = atoms.get_potential_energy() assert abs(e + 2077.45445852) < 1.0
def test_amber(self): """ No Coulomb interactions! """ atoms = s22.create_s22_system('Phenol_dimer') atoms.calc = AMBER(get_datafile('gromacs_top'), debug=True) correct_potential_energy = 0.38964329304643913 correct_forces = np.array([[-1.18965078, 0.45654594, -0.97698022], [ 1.17449069, -0.74770987, 1.1477307 ], [-0.29906227, 0.55477431, -0.44393566], [ 0.76015103, 0.61180677, 0.10247458], [ 0.52975756, -0.54074168, 0.65060897], [-0.15563116, -0.16621851, 0.00960593], [-0.95161655, -0.19441948, -0.48233891], [ 0.40540709, 0.49151909, -0.0359589 ], [-0.0941877 , -0.11437976, 0.03738224], [-0.12133146, -0.04475436, -0.04464291], [ 0.00442227, 0.01445538, -0.00582965], [ 0.03461644, -0.0841398 , 0.07111583], [-0.33731331, -0.25623328, -0.05426193], [ 1.80220775, -0.63136398, 1.01602959], [-1.73424753, 1.04810168, -0.83955938], [-0.55120544, 0.4397597 , -0.12906718], [ 0.14753942, 0.13221715, 0.23576542], [-0.48769438, -0.48128516, -0.92159558], [ 0.16411578, -0.32870293, -0.11842823], [ 0.65146758, -0.09966372, 0.60424407], [ 0.10380976, 0.45212714, 0.49543921], [ 0.04952918, -0.26588613, -0.19287355], [ 0.10881918, -0.07302862, 0.0399899 ], [-0.01069515, 0.00719285, -0.00641906], [-0.01478911, -0.09125585, -0.09081484], [ 0.01108998, -0.08871428, -0.06768139]]) potential_energy = atoms.get_potential_energy() forces = atoms.get_forces() self.assertTrue(floatEqual(potential_energy, correct_potential_energy), 'Potential energy test failed. Output is %s' % repr(potential_energy)) self.assertTrue(floatEqual(forces, correct_forces), 'Force test failed. Output is\n%s' % repr(forces))
def test_pcff(self): atoms = s22.create_s22_system('Phenol_dimer') atoms.calc = PCFF(get_datafile('pcff.frc'), debug=True) correct_potential_energy = -0.6984590910167954 correct_forces = np.array([[ 0.38203557, 0.31769929, 0.04481593], [ 0.06645072, 0.103403 , 0.08574124], [ 0.00229426, -0.10892152, -0.09467121], [ 0.22153722, 0.10880227, 0.09930943], [ 0.3400227 , -0.16116659, 0.31053077], [-0.22498033, -0.3186932 , 0.06136411], [-0.46089536, -0.00924397, -0.28932139], [-0.28527205, 0.0557619 , -0.20593482], [-0.23553429, -0.14936895, -0.05274159], [-0.11395132, 0.11342922, -0.14521467], [ 0.09841353, 0.17775813, -0.04823693], [ 0.18713908, 0.01462723, 0.10630103], [-0.06184675, -0.2062761 , 0.08826763], [ 0.16000573, -0.27071082, -0.02609756], [-0.50141911, 1.13370675, 0.51524359], [ 0.1432776 , -0.02164376, 0.01262255], [-0.07181789, -0.21984863, -0.30902257], [-0.29430696, -0.16109547, -0.45144199], [ 0.19343122, -0.37887476, -0.12902685], [ 0.27851158, 0.06016552, 0.35355663], [ 0.1822294 , 0.08455133, 0.26004845], [ 0.16078021, -0.20149043, -0.02997253], [ 0.08616924, 0.0722537 , 0.1520211 ], [-0.09563302, 0.1601445 , 0.03820269], [-0.14750256, 0.01951328, -0.13697983], [-0.00913885, -0.21448015, -0.20936275]]) potential_energy = atoms.get_potential_energy() forces = atoms.get_forces() self.assertTrue(floatEqual(potential_energy, correct_potential_energy), 'Potential energy test failed. Output is %s' % repr(potential_energy)) self.assertTrue(floatEqual(forces, correct_forces), 'Force test failed. Output is\n%s' % repr(forces))
def test_reaxff(self): atoms = s22.create_s22_system('Phenol_dimer') atoms.calc = ReaxFF(get_datafile('ffield.reax'), debug=True) correct_potential_energy = -142.4691415172731 correct_forces = np.array([[ 2.07723156, 3.96541299, -1.15132559], [-3.2265494 , -0.20475922, -1.49226283], [ 2.60729701, 0.3025817 , 1.33967323], [ 5.04814524, 2.42645569, 1.66324749], [ 2.1388216 , -3.76116807, 3.61281947], [-2.80884034, -4.91705556, 1.26078092], [-5.08652247, -1.16750474, -2.46529692], [-0.73403717, 4.58245815, -3.24360016], [ 0.57589696, 0.03272494, 0.34879092], [ 0.22167946, -0.63391813, 0.53482248], [-0.39215936, -0.67218695, 0.16863779], [-0.75861594, -0.27159978, -0.30523254], [-0.45115578, 0.36083747, -0.49195707], [-1.93148048, -0.10359034, -2.32416844], [-1.29829954, 2.23213681, 0.54021264], [ 1.73759958, 1.86858085, 3.20233054], [-4.27793374, 3.30169938, -1.55869664], [-1.68371535, -3.23798885, -4.58176432], [ 2.71178281, -4.94754052, -1.52588302], [ 4.49239091, -2.09399613, 2.87009647], [ 0.39408212, 4.17231613, 4.14201763], [-0.52669605, 0.0963932 , -0.53510001], [-0.16398092, -0.54798349, -0.68089446], [ 0.37304923, -0.6820306 , -0.22145353], [ 0.68719527, -0.39223828, 0.3756307 ], [ 0.27481566, 0.29199609, 0.51855661]]) potential_energy = atoms.get_potential_energy() forces = atoms.get_forces() self.assertTrue(floatEqual(potential_energy, correct_potential_energy), 'Potential energy test failed. Output is %s' % repr(potential_energy)) self.assertTrue(floatEqual(forces, correct_forces), 'Force test failed. Output is\n%s' % repr(forces))
def test_oplsaa(self): atoms = s22.create_s22_system('Phenol_dimer') atoms.calc = OPLSAA(get_datafile('gromacs_top'), debug=True) correct_potential_energy = -0.06133657564514914 correct_forces = np.array([[-0.98749167, 0.58904496, -0.94773113], [ 1.50116115, -0.59847665, 1.26238973], [-0.47667556, 0.36518558, -0.63626413], [ 0.86374354, 0.6378209 , 0.17176304], [ 0.52247239, -0.62942994, 0.70529978], [-0.21845013, -0.27751117, 0.03861972], [-1.00563955, -0.26763673, -0.47074335], [ 0.24265077, 0.49094235, -0.14049189], [-0.07279922, -0.11405626, 0.01738402], [-0.08558296, -0.0180396 , -0.04223256], [-0.00345078, 0.00306927, -0.00374471], [ 0.039358 , -0.04353843, 0.04977722], [-0.20508662, -0.16699082, -0.02503193], [ 1.41905122, -0.31221416, 1.38811527], [-1.67894096, 1.18507153, -0.70823986], [-0.63693193, 0.04629638, -0.67252085], [ 0.04935659, 0.12054093, 0.12234444], [-0.43892277, -0.55833016, -0.94380668], [ 0.21860581, -0.42718367, -0.14489985], [ 0.72385528, -0.15894288, 0.62759131], [ 0.11829467, 0.56180796, 0.62555319], [ 0.01089657, -0.18085216, -0.14498788], [ 0.06462032, -0.03837788, 0.02591625], [-0.00216488, -0.00993168, -0.01454757], [-0.01138902, -0.06626078, -0.06814235], [ 0.04946673, -0.13200336, -0.07136257]]) potential_energy = atoms.get_potential_energy() forces = atoms.get_forces() self.assertTrue(floatEqual(potential_energy, correct_potential_energy), 'Potential energy test failed. Output is %s' % repr(potential_energy)) self.assertTrue(floatEqual(forces, correct_forces), 'Force test failed. Output is\n%s' % repr(forces))
def test_charmm(self): atoms = s22.create_s22_system('Phenol_dimer') atoms.calc = CHARMM(get_datafile('par_all36_cgenff.prm'), auto_charges=True, debug=True) correct_potential_energy = 0.13048314753274043 correct_forces = np.array([[ -1.14463884e+00, -1.68207618e+00, 3.29438386e-01], [ 7.32632172e-01, 1.23258558e+00, -2.10086066e-01], [ 6.14478002e-02, -3.51428322e-02, -1.11381564e-01], [ -3.83892857e-01, 8.85109028e-02, -2.69391246e-01], [ -2.85321917e-02, 2.78799956e-01, -1.93727826e-01], [ 2.50792383e-01, 5.02099931e-01, -1.46366854e-01], [ 2.67473252e-01, 5.31778323e-02, 1.19425171e-01], [ 4.38307000e-01, -2.35313133e-01, 4.25593946e-01], [ -5.97756804e-02, -1.48735402e-01, 5.85194224e-02], [ -4.37864686e-02, 5.72293404e-03, -3.22041337e-02], [ -1.94106828e-02, 1.09826094e-03, -5.47744985e-03], [ 2.54398108e-02, -1.46024278e-02, 2.67202660e-02], [ -1.74992799e-01, -8.94137434e-02, -4.01153071e-02], [ -4.07283454e-01, 9.06656651e-01, 5.03734758e-01], [ 4.46953802e-01, -1.07517389e+00, -5.36400936e-01], [ 1.89104779e-02, 1.54977664e-02, -6.15510068e-02], [ 5.78260304e-01, -1.36903073e-01, 4.56580633e-01], [ 4.72586323e-02, 1.69949554e-01, 2.11128106e-01], [ -2.75001694e-01, 4.50292838e-01, 1.19754739e-01], [ -3.09711622e-01, 2.23511159e-01, -1.03908195e-01], [ -1.82374237e-01, -1.64251511e-01, -3.31384567e-01], [ -1.18465957e-03, -1.46414989e-01, -1.39178821e-01], [ 2.86580776e-02, -1.30676421e-02, 1.20760786e-02], [ 2.21930104e-02, -1.87663790e-02, -1.36623808e-02], [ 2.58436173e-04, -3.01109919e-02, -3.58351835e-02], [ 1.11995166e-01, -1.37929935e-01, -3.22990144e-02]]) potential_energy = atoms.get_potential_energy() forces = atoms.get_forces() self.assertTrue(floatEqual(potential_energy, correct_potential_energy), 'Potential energy test failed. Output is %s' % repr(potential_energy)) self.assertTrue(floatEqual(forces, correct_forces), 'Force test failed. Output is\n%s' % repr(forces))
def test_compass(self): atoms = s22.create_s22_system('Phenol_dimer') atoms.calc = COMPASS(get_datafile('compass.frc'), debug=True) correct_potential_energy = -0.8709613598457432 correct_forces = np.array([[ 0.35112694, 0.25463791, 0.05644749], [ 0.72228116, 0.0895421 , 0.40237507], [-0.57104885, -0.14180625, -0.37549366], [-0.58755757, -0.07901503, -0.30178597], [-0.0170888 , 0.45440809, -0.28923813], [ 0.21728754, 0.47817162, -0.15168806], [ 0.35739913, 0.14291464, 0.12856372], [ 0.08421959, -0.55165643, 0.39717225], [ 0.50162293, 0.03809237, 0.28184412], [ 0.21723637, -0.42526915, 0.39161687], [-0.30955074, -0.52814441, 0.1298048 ], [-0.54157861, -0.1383445 , -0.25536383], [-0.33960857, 0.35724171, -0.43102226], [ 0.34620208, -0.02740724, 0.45917381], [-0.49434643, 1.08521701, 0.49173591], [-0.16693748, -0.33332728, -0.54045982], [ 0.62644216, -0.50698273, 0.1855112 ], [ 0.02029852, 0.28945408, 0.2759518 ], [-0.24916276, 0.3939607 , 0.08951348], [-0.43254608, 0.37100895, -0.1199759 ], [-0.07833031, -0.40428916, -0.45046629], [-0.49351384, 0.10938595, -0.42777082], [-0.1822294 , -0.3577326 , -0.50842675], [ 0.29216867, -0.54694709, -0.17945497], [ 0.49935065, -0.24628122, 0.30982784], [ 0.22785798, 0.22316858, 0.43161028]]) self.assertTrue(floatEqual(atoms.get_potential_energy(), correct_potential_energy), 'Potential energy test failed. Output is %s' % repr(correct_potential_energy)) self.assertTrue(floatEqual(atoms.get_forces(), correct_forces), 'Force test failed. Output is %s' % repr(correct_forces))
else: return { self.element1role: atoms.get_chemical_symbols()[i], self.element2role: atoms.get_chemical_symbols()[j], }[role] @pyqtSlot() def changed(self): self.dataChanged.emit(self.index(0), self.index(self.rowCount()-1)) if __name__ == '__main__': import sys from ase.data import s22 try: atoms = s22.create_s22_system(sys.argv[1]) except: atoms = s22.create_s22_system('Adenine-thymine_complex_stack') try: if sys.argv[2] == 'charmm': typedata = charmmtypes.data if sys.argv[2] == 'compass': typedata = compasstypes.data except: typedata = charmmtypes.data atoms.info['bonds'] = Bonds(atoms, autodetect=True) type_resolver = TypeResolver(typedata) matches = [type_resolver.resolve(atom) for atom in atoms] atoms.info['atom_types'] = [m.type for m in matches]
from ase.atoms import Atoms from multiasecalc.lammps.reaxff import ReaxFF from multiasecalc.lammps.compass import COMPASS from multiasecalc.lammps.dynamics import LAMMPSOptimizer, LAMMPS_NVT from multiasecalc.utils import get_datafile from ase.data import s22 from ase import units import numpy as np import ase.io from ase.io.trajectory import PickleTrajectory atoms = s22.create_s22_system('Methane_dimer') atoms.center(vacuum=10.0) print atoms.positions atoms.calc = COMPASS(ff_file_path=get_datafile('compass.frc'), debug=True) optimizer = LAMMPSOptimizer(atoms) optimizer.run() print atoms.positions atoms.calc = ReaxFF(ff_file_path=get_datafile('ffield.reax'), debug=True) dyn = LAMMPS_NVT(atoms, 1 * units.fs, 100, trajectory='test.traj', traj_interval=2) dyn.run(5) atoms.calc = COMPASS(ff_file_path=get_datafile('compass.frc'), debug=True) dyn.run(10)
def main(): if "ASE_DFTD3_COMMAND" not in os.environ: raise NotAvailable('$ASE_DFTD3_COMMAND not defined') # do all non-periodic calculations with Adenine-Thymine complex system = create_s22_system('Adenine-thymine_complex_stack') # Default is D3(zero) system.set_calculator(DFTD3()) close(system.get_potential_energy(), -0.6681154466652238) # Only check forces once, for the default settings. f_ref = np.array([[ 0.0088385621657399, -0.0118387210205813, -0.0143242057174889], [-0.0346912282737323, 0.0177797757792533, -0.0442349785529711], [ 0.0022759961575945, -0.0087458217241648, -0.0051887171699909], [-0.0049317224619103, -0.0215152368018880, -0.0062290998430756], [-0.0013032612752381, -0.0356240144088481, 0.0203401124180720], [-0.0110305568118348, -0.0182773178473497, -0.0023730575217145], [ 0.0036258610447203, -0.0074994162928053, -0.0144058177906650], [ 0.0005289754841564, -0.0035901842246731, -0.0103580836569947], [ 0.0051775352510856, -0.0051076755874038, -0.0103428268442285], [ 0.0011299493448658, -0.0185829345539878, -0.0087205807334006], [ 0.0128459160503721, -0.0248356605575975, 0.0007946691695359], [-0.0063194401470256, -0.0058117310787239, -0.0067932156139914], [ 0.0013749100498893, -0.0118259631230572, -0.0235404547526578], [ 0.0219558160992901, -0.0087512938555865, -0.0226017156485839], [ 0.0001168268736984, -0.0138384169778581, -0.0014850073023105], [ 0.0037893625607261, 0.0117649062330659, 0.0162375798918204], [ 0.0011352730068862, 0.0142002748861793, 0.0129337874676760], [-0.0049945288501837, 0.0073929058490670, 0.0088391871214417], [ 0.0039715118075548, 0.0186949615105239, 0.0114822052853407], [-0.0008003587963147, 0.0161735976004718, 0.0050357997715004], [-0.0033142342134453, 0.0153658921418049, -0.0026233088963388], [-0.0025451124688653, 0.0067994927521733, -0.0017127589489137], [-0.0010451311609669, 0.0067173068779992, 0.0044413725566098], [-0.0030829302438095, 0.0112138539867057, 0.0151213034444885], [ 0.0117240581287903, 0.0161749855643631, 0.0173269837053235], [-0.0025949288306356, 0.0158830629834040, 0.0155589787340858], [ 0.0083784268665834, 0.0082132824775010, 0.0090603749323848], [-0.0019694065480327, 0.0115576523485515, 0.0083901101633852], [-0.0020036820791533, 0.0109276020920431, 0.0204922407855956], [-0.0062424587308054, 0.0069848349714167, 0.0088791235460659]]) array_close(system.get_forces(), f_ref) # calculate numerical forces, but use very loose comparison criteria! # dftd3 doesn't print enough digits to stdout to get good convergence f_numer = system.calc.calculate_numerical_forces(system, d=1e-4) array_close(f_numer, f_ref, releps=1e-2, abseps=1e-3) # D2 system.set_calculator(DFTD3(old=True)) close(system.get_potential_energy(), -0.8923443424663762) # D3(BJ) system.set_calculator(DFTD3(damping='bj')) close(system.get_potential_energy(), -1.211193213979179) # D3(zerom) system.set_calculator(DFTD3(damping='zerom')) close(system.get_potential_energy(), -2.4574447613705717) # D3(BJm) system.set_calculator(DFTD3(damping='bjm')) close(system.get_potential_energy(), -1.4662085277005799) # alternative tz parameters system.set_calculator(DFTD3(tz=True)) close(system.get_potential_energy(), -0.6160295884482619) # D3(zero, ABC) system.set_calculator(DFTD3(abc=True)) close(system.get_potential_energy(), -0.6528640090262864) # D3(zero) with revpbe parameters system.set_calculator(DFTD3(xc='revpbe')) close(system.get_potential_energy(), -1.5274869363442936) # Custom damping parameters system.set_calculator(DFTD3(s6=1.1, sr6=1.1, s8=0.6, sr8=0.9, alpha6=13.0)) close(system.get_potential_energy(), -1.082846357973487) # A couple of combinations, but not comprehensive # D3(BJ, ABC) system.set_calculator(DFTD3(damping='bj', abc=True)) close(system.get_potential_energy(), -1.1959417763402416) # D3(zerom) with B3LYP parameters system.set_calculator(DFTD3(damping='zerom', xc='b3-lyp')) close(system.get_potential_energy(), -1.3369234231047677) # use diamond for bulk system system = bulk('C') system.set_calculator(DFTD3()) close(system.get_potential_energy(), -0.2160072476277501) # Do one stress for the default settings s_ref = np.array([ 0.0182329043326, 0.0182329043326, 0.0182329043326, -3.22757439831e-14, -3.22766949320e-14, -3.22766949320e-14]) array_close(system.get_stress(), s_ref) # As with numerical forces, numerical stresses will not be very well # converged due to the limited number of digits printed to stdout # by dftd3. So, use very loose comparison criteria. s_numer = system.calc.calculate_numerical_stress(system, d=1e-4) array_close(s_numer, s_ref, releps=1e-2, abseps=1e-3)
from ase.constraints import FixBondLengths from ase.md.verlet import VelocityVerlet from ase.md.langevin import Langevin from ase.io import Trajectory import ase.units as u md_cls_and_kwargs = [ (VelocityVerlet, {}), (Langevin, { "temperature": 300 * u.kB, "friction": 0.02 }), ] # prepare atoms object for testing dimer = s22.create_s22_system("Water_dimer") calc = TIP3P(rc=9.0) dimer.constraints = FixBondLengths([(3 * i + j, 3 * i + (j + 1) % 3) for i in range(2) for j in [0, 1, 2]]) def fmax(forces): return np.sqrt((forces**2).sum(axis=1).max()) def test_opt(cls, atoms, calc, logfile="opt.log", trajectory="opt.traj"): """run optimization and verify that log and trajectory coincide""" # clean files to make sure the correct ones are tested for file in (*Path().glob("*.log"), *Path().glob("*.traj")):
from ase.atoms import Atoms from multiasecalc.lammps.reaxff import ReaxFF from multiasecalc.lammps.compass import COMPASS from multiasecalc.lammps.dynamics import LAMMPSOptimizer, LAMMPS_NVT from multiasecalc.utils import get_datafile from ase.data import s22 from ase import units import numpy as np import ase.io from ase.io.trajectory import PickleTrajectory atoms = s22.create_s22_system('Methane_dimer') atoms.center(vacuum=10.0) print atoms.positions atoms.calc = COMPASS(ff_file_path=get_datafile('compass.frc'), debug=True) optimizer = LAMMPSOptimizer(atoms) optimizer.run() print atoms.positions atoms.calc = ReaxFF(ff_file_path=get_datafile('ffield.reax'), debug=True) dyn = LAMMPS_NVT(atoms, 1*units.fs, 100, trajectory='test.traj', traj_interval = 2) dyn.run(5) atoms.calc = COMPASS(ff_file_path=get_datafile('compass.frc'), debug=True) dyn.run(10) trj = PickleTrajectory('test.traj', 'r') for t in trj: print t.positions
from ase import Atoms from gpaw import GPAW from gpaw.mpi import rank from ase.data import s22 from multiasecalc.mixer.selector import AtomListSelector from multiasecalc.mixer.mixer import Mixer, EnergyCalculation, ForceCalculation from multiasecalc.lammps.reaxff import ReaxFF from multiasecalc.utils import get_datafile import numpy as np dimer_name = "2-pyridoxine_2-aminopyridine_complex" atoms = s22.create_s22_system(dimer_name) # full system atom_counts = s22.get_number_of_dimer_atoms(dimer_name) Mixer.set_atom_ids(atoms) # sequence of numbers in same order as positions # were given above, index starts from 0 atoms_m1 = atoms[:atom_counts[0]] # first molecule atoms_m2 = atoms[atom_counts[0]:] # second molecule calc_gpaw = GPAW(nbands=-2, txt="h2_1.txt") calc_reaxff = ReaxFF(ff_file_path=get_datafile("ffield.reax.new"), implementation="C") reaxff_cell = (100.0, 100.0, 100.0) gpaw_cell = (10.0, 10.0, 10.0) filter_full_system = AtomListSelector( range(len(atoms)), dict(zip(range(len(atoms)), [1.0] * len(atoms))))
from ase import Atoms from ase.data import s22 import numpy as np from SCME.CALC_SCME2 import CALC_SCME from ase_qmscme import ase_qmscme from gpaw import GPAW dimer = s22.create_s22_system('Water_dimer') dimer.center(vacuum=5.0) # rotate the second water mol into the same x plane as # the first one, to make the potential curve easier to make center = dimer[0].position h = dimer[3].position[1]-dimer[0].position[1] l = np.linalg.norm(dimer[0].position - dimer[3].position) angle = np.arcsin(h/l) dimer.rotate('-z',a=angle,center=center) nsys = dimer[:3].copy() nsys.set_positions(dimer[:3].get_positions() + (2.,2.,0)) trimer = dimer + nsys # 3 mols now qmidx = 3 calc_qm = GPAW(h=0.20,mode='lcao',basis={None:'dzp'},txt='simpletest.txt') eF = np.zeros((3,2)) calc_mm = CALC_SCME(trimer[qmidx:]) trimer.set_calculator(ase_qmscme(trimer, qmidx=3,calc_qm=calc_qm, calc_mm=calc_mm,qm_cell=trimer.get_cell())) Etot = trimer.get_potential_energy() print '\n################################## #'
from __future__ import print_function from ase.data import s22 from ase.calculators.tip3p import TIP3P, epsilon0, sigma0 from ase.calculators.qmmm import EIQMMM, LJInteractions, Embedding from gpaw import GPAW # Create system atoms = s22.create_s22_system('Water_dimer') atoms.center(vacuum=4.0) # Make QM atoms selection of first water molecule: qm_idx = range(3) # Set up interaction & embedding object interaction = LJInteractions({('O', 'O'): (epsilon0, sigma0)}) embedding = Embedding(rc=0.02) # Short range analytical potential cutoff # Set up calculator atoms.calc = EIQMMM(qm_idx, GPAW(txt='qm.out'), TIP3P(), interaction, embedding=embedding, vacuum=None, # if None, QM cell = MM cell output='qmmm.log') print(atoms.get_potential_energy())
True in (ch.contains(template) for ch in self.children) def contains_all(self, templates): return not False in (self.contains(t) for t in templates) def resolve(self, templates): for ch in self.children: result = ch.resolve(templates) if result: return result try: return (t for t in templates if t.type == self.root).next() except StopIteration: return False if __name__ == '__main__': f = open('charmmtypes.template') resolver = TypeResolver(f) from ase.data import s22 from bonds import Bonds for name in s22.s22: dimer = s22.create_s22_system(name) print print name dimer.info['bonds'] = Bonds(dimer, autodetect=True) for atom in dimer: print atom.symbol, resolver.resolve(atom)
def system(): return create_s22_system('Adenine-thymine_complex_stack')
def contains_all(self, templates): return not False in (self.contains(t) for t in templates) def resolve(self, templates): for ch in self.children: result = ch.resolve(templates) if result: return result try: return (t for t in templates if t.type == self.root).next() except StopIteration: return False if __name__ == "__main__": f = open("charmmtypes.template") resolver = TypeResolver(f) from ase.data import s22 from bonds import Bonds for name in s22.s22: dimer = s22.create_s22_system(name) print print name dimer.info["bonds"] = Bonds(dimer, autodetect=True) for atom in dimer: print atom.symbol, resolver.resolve(atom)
from ase import Atoms from gpaw import GPAW from ase.data import s22 from gpaw.mpi import rank from multiasecalc.mixer.selector import AtomListSelector from multiasecalc.mixer.mixer import Mixer, EnergyCalculation, ForceCalculation from multiasecalc.lammps.reaxff import ReaxFF from multiasecalc.utils import get_datafile import numpy as np dimer_name = "2-pyridoxine_2-aminopyridine_complex" atoms = s22.create_s22_system(dimer_name) atom_counts = s22.get_number_of_dimer_atoms(dimer_name) atoms_m1 = atoms[:atom_counts[0]] # first molecule atoms_m2 = atoms[atom_counts[0]:] # second molecule calc_gpaw = GPAW(nbands=-2, xc="PBE", txt="dimer_gpaw.gpaw.log") gpaw_cell = (15.0, 15.0, 15.0) atoms.set_cell(gpaw_cell) atoms_m1.set_cell(gpaw_cell) atoms_m2.set_cell(gpaw_cell) atoms.center() atoms_m1.center() atoms_m2.center() atoms.set_calculator(calc_gpaw) atoms_m1.set_calculator(calc_gpaw)
try: from ase.calculators.d3ef import d3ef except ImportError: fortran = False def testforce(system, fortran=False, bj=False): system.set_calculator(D3(fortran=fortran, bj=bj)) f1 = system.get_forces() f2 = numeric_forces(system, d=0.0001) assert abs(f1 - f2).max() < 1e-6 waterdim = create_s22_system('Water_dimer') slab = fcc111('Au', (1, 1, 4), vacuum=7.5) testforce(waterdim, fortran=False, bj=False) #testforce(slab, fortran=False, bj=False) # This is too slow! testforce(waterdim, fortran=False, bj=True) #testforce(slab, fortran=False, bj=True) # This is too slow! if fortran: testforce(waterdim, fortran=True, bj=False) testforce(slab, fortran=True, bj=False) testforce(waterdim, fortran=True, bj=True) testforce(slab, fortran=True, bj=True)
def atoms(): dimer = s22.create_s22_system("Water_dimer") dimer.constraints = FixBondLengths( [(3 * i + j, 3 * i + (j + 1) % 3) for i in range(2) for j in [0, 1, 2]] ) return dimer
def main(): # do all non-periodic calculations with Adenine-Thymine complex system = create_s22_system('Adenine-thymine_complex_stack') # Default is D3(zero) system.set_calculator(DFTD3()) close(system.get_potential_energy(), -0.6681154466652238) # Only check forces once, for the default settings. f_ref = np.array( [[0.0088385621657399, -0.0118387210205813, -0.0143242057174889], [-0.0346912282737323, 0.0177797757792533, -0.0442349785529711], [0.0022759961575945, -0.0087458217241648, -0.0051887171699909], [-0.0049317224619103, -0.0215152368018880, -0.0062290998430756], [-0.0013032612752381, -0.0356240144088481, 0.0203401124180720], [-0.0110305568118348, -0.0182773178473497, -0.0023730575217145], [0.0036258610447203, -0.0074994162928053, -0.0144058177906650], [0.0005289754841564, -0.0035901842246731, -0.0103580836569947], [0.0051775352510856, -0.0051076755874038, -0.0103428268442285], [0.0011299493448658, -0.0185829345539878, -0.0087205807334006], [0.0128459160503721, -0.0248356605575975, 0.0007946691695359], [-0.0063194401470256, -0.0058117310787239, -0.0067932156139914], [0.0013749100498893, -0.0118259631230572, -0.0235404547526578], [0.0219558160992901, -0.0087512938555865, -0.0226017156485839], [0.0001168268736984, -0.0138384169778581, -0.0014850073023105], [0.0037893625607261, 0.0117649062330659, 0.0162375798918204], [0.0011352730068862, 0.0142002748861793, 0.0129337874676760], [-0.0049945288501837, 0.0073929058490670, 0.0088391871214417], [0.0039715118075548, 0.0186949615105239, 0.0114822052853407], [-0.0008003587963147, 0.0161735976004718, 0.0050357997715004], [-0.0033142342134453, 0.0153658921418049, -0.0026233088963388], [-0.0025451124688653, 0.0067994927521733, -0.0017127589489137], [-0.0010451311609669, 0.0067173068779992, 0.0044413725566098], [-0.0030829302438095, 0.0112138539867057, 0.0151213034444885], [0.0117240581287903, 0.0161749855643631, 0.0173269837053235], [-0.0025949288306356, 0.0158830629834040, 0.0155589787340858], [0.0083784268665834, 0.0082132824775010, 0.0090603749323848], [-0.0019694065480327, 0.0115576523485515, 0.0083901101633852], [-0.0020036820791533, 0.0109276020920431, 0.0204922407855956], [-0.0062424587308054, 0.0069848349714167, 0.0088791235460659]]) array_close(system.get_forces(), f_ref) # calculate numerical forces, but use very loose comparison criteria! # dftd3 doesn't print enough digits to stdout to get good convergence f_numer = system.calc.calculate_numerical_forces(system, d=1e-4) array_close(f_numer, f_ref, releps=1e-2, abseps=1e-3) # D2 system.set_calculator(DFTD3(old=True)) close(system.get_potential_energy(), -0.8923443424663762) # D3(BJ) system.set_calculator(DFTD3(damping='bj')) close(system.get_potential_energy(), -1.211193213979179) # D3(zerom) system.set_calculator(DFTD3(damping='zerom')) close(system.get_potential_energy(), -2.4574447613705717) # D3(BJm) system.set_calculator(DFTD3(damping='bjm')) close(system.get_potential_energy(), -1.4662085277005799) # alternative tz parameters system.set_calculator(DFTD3(tz=True)) close(system.get_potential_energy(), -0.6160295884482619) # D3(zero, ABC) system.set_calculator(DFTD3(abc=True)) close(system.get_potential_energy(), -0.6528640090262864) # D3(zero) with revpbe parameters system.set_calculator(DFTD3(xc='revpbe')) close(system.get_potential_energy(), -1.5274869363442936) # Custom damping parameters system.set_calculator(DFTD3(s6=1.1, sr6=1.1, s8=0.6, sr8=0.9, alpha6=13.0)) close(system.get_potential_energy(), -1.082846357973487) # A couple of combinations, but not comprehensive # D3(BJ, ABC) system.set_calculator(DFTD3(damping='bj', abc=True)) close(system.get_potential_energy(), -1.1959417763402416) # D3(zerom) with B3LYP parameters system.set_calculator(DFTD3(damping='zerom', xc='b3-lyp')) close(system.get_potential_energy(), -1.3369234231047677) # use diamond for bulk system system = bulk('C') system.set_calculator(DFTD3()) close(system.get_potential_energy(), -0.2160072476277501) # Do one stress for the default settings s_ref = np.array([0.0182329043326, 0.0182329043326, 0.0182329043326, -3.22757439831e-14, -3.22766949320e-14, -3.22766949320e-14]) array_close(system.get_stress(), s_ref) # As with numerical forces, numerical stresses will not be very well # converged due to the limited number of digits printed to stdout # by dftd3. So, use very loose comparison criteria. s_numer = system.calc.calculate_numerical_stress(system, d=1e-4) array_close(s_numer, s_ref, releps=1e-2, abseps=1e-3)
from ase import Atoms from ase.data import s22 import numpy as np from SCME.CALC_SCME2 import CALC_SCME from ase_qmscme import ase_qmscme from gpaw import GPAW from ase.visualize import view from gpaw.mpi import rank, MASTER dimer = s22.create_s22_system("Water_dimer") # rotate the second water mol into the same x plane as # the first one, to make the potential curve easier to make center = dimer[0].position h = dimer[3].position[1] - dimer[0].position[1] l = np.linalg.norm(dimer[0].position - dimer[3].position) angle = np.arcsin(h / l) dimer.rotate("-z", a=angle, center=center) dimer.center(vacuum=5.0) path = "/zhome/c7/a/69784/SCME2015_Nov/QMSCME/" # and then i need to place another scme water mol FAR away so the program # actually initializes qmidx = 3 mp = 3 eps = 6.59e-3 sig = 3.15 LJ_qm = np.zeros((3, 2)) LJ_qm[0, 0] = eps
return { self.element1role: atoms.get_chemical_symbols()[i], self.element2role: atoms.get_chemical_symbols()[j], }[role] @pyqtSlot() def changed(self): self.dataChanged.emit(self.index(0), self.index(self.rowCount() - 1)) if __name__ == '__main__': import sys from ase.data import s22 try: atoms = s22.create_s22_system(sys.argv[1]) except: atoms = s22.create_s22_system('Adenine-thymine_complex_stack') try: if sys.argv[2] == 'charmm': typedata = charmmtypes.data if sys.argv[2] == 'compass': typedata = compasstypes.data except: typedata = charmmtypes.data atoms.info['bonds'] = Bonds(atoms, autodetect=True) type_resolver = TypeResolver(typedata) matches = [type_resolver.resolve(atom) for atom in atoms] atoms.info['atom_types'] = [m.type for m in matches]