def missing_features(*args): """Returns a list of the missing features in the argument""" if len(args) == 1 and not isinstance(args[0], str) and hasattr(args[0], "__iter__"): return set(args[0]) - set(features()) return set(args) - set(features())
def has_features(*args): """Tests whether a list of features is a subset of the compiled-in features""" if len(args) == 1 and not isinstance(args[0], str) and hasattr(args[0], "__iter__"): return set(args[0]) < set(features()) return set(args) < set(features())
def test_has_features(self): for feature in code_info.features(): self.assertTrue(has_features(feature)) for feature in code_info.all_features() - set(code_info.features()): self.assertFalse(has_features(feature)) with self.assertRaises(RuntimeError) as _: has_features("NotAFeature")
def has_features(*args): """Tests whether a list of features is a subset of the compiled-in features""" if len(args) == 1 and not isinstance(args[0], str) and hasattr( args[0], "__iter__"): check_set = set(args[0]) else: check_set = set(args) if not check_set < all_features(): raise RuntimeError("'{}' is not a feature".format( ','.join(check_set - all_features()))) return check_set < set(features())
import espressomd._system as es import espressomd from espressomd import thermostat from espressomd import code_info from espressomd import analyze from espressomd import integrate from espressomd import lb import numpy as np print(""" ======================================================= = lbf.py = ======================================================= Program Information:""") print(code_info.features()) system = espressomd.System() system.time_step = 0.01 system.skin = 0.1 box_l = 50 system.box_l =[box_l, box_l, box_l] system.periodic = [1,1,1] system.part.add(id=0, pos=[box_l/2.0,box_l/2.0,box_l/2.0], fix=[1,1,1]) # system.part.add(id=0, pos=[box_l/2.0,box_l/2.0,box_l/2.0], ext_force=[0,0,1]) lbf = lb.LBFluid(agrid=1, fric=1, dens=1, visc=1, tau=0.01, ext_force=[0,0,-1.0/(box_l**3)]) system.actors.add(lbf)
import espressomd from espressomd import thermostat from espressomd import code_info from espressomd import analyze from espressomd import integrate from espressomd import electrostatics from espressomd import electrostatic_extensions import numpy print(""" ======================================================= = p3m.py = ======================================================= Program Information:""") print(code_info.features()) dev = "cpu" # System parameters ############################################################# # 10 000 Particles box_l = 10.7437 density = 0.7 # Interaction parameters (repulsive Lennard Jones) ############################################################# lj_eps = 1.0 lj_sig = 1.0
self.assertTrue(self.bondsMatch(tnIn,tnOut,params,outParams), bondClass(**params).typeName()+": value set and value gotten back differ for bond id "+str(bondId)+": "+params.__str__()+" vs. "+outParams.__str__()) return func def test_aa_bondedInterSetterGetter(self): self.system.bondedInter[0]=HarmonicBond(k=0,r_0=0) bond=self.system.bondedInter[0] self.assertTrue(isinstance(bond,HarmonicBond),"The bond was created as harmonic bond but the instance gotten back is of different type.") test_fene = generateTestForBondParams(0,FeneBond,{"r_0":1.1, "k":5.2, "d_r_max":3.}) test_fene2 = generateTestForBondParams(1,FeneBond,{"r_0":1.1, "k":5.2, "d_r_max":3.}) test_harmonic = generateTestForBondParams(0,HarmonicBond,{"r_0":1.1, "k":5.2}) test_harmonic2 = generateTestForBondParams(0,HarmonicBond,{"r_0":1.1, "k":5.2, "r_cut":1.3}) test_dihedral = generateTestForBondParams(0,Dihedral,{"mult":3.0, "bend":5.2,"phase":3.}) test_angle_harm = generateTestForBondParams(0,Angle_Harmonic,{"bend":5.2, "phi0":3.2}) test_angle_cos = generateTestForBondParams(0,Angle_Cosine,{"bend":5.2, "phi0":3.2}) test_angle_cossquare = generateTestForBondParams(0,Angle_Cossquare,{"bend":5.2, "phi0":0.}) test_subt_lj = generateTestForBondParams(0,Subt_Lj,{"k":5.2, "r":3.2}) test_stretching_force = generateTestForBondParams(0,Stretching_Force,{"r0":5.2, "ks":3.2}) test_area_force_local = generateTestForBondParams(0,Area_Force_Local,{"A0_l":5.2, "ka_l":3.2}) test_bending_force = generateTestForBondParams(0,Bending_Force,{"phi0":5.2, "kb":3.2}) test_volume_force = generateTestForBondParams(0,Volume_Force,{"V0":5.2, "kv":3.2}) test_area_force_global = generateTestForBondParams(0,Area_Force_Global,{"A0_g":5.2, "ka_g":3.2}) test_stretchlin_force = generateTestForBondParams(0,Stretchlin_Force,{"r0":5.2, "kslin":3.2}) if __name__ == "__main__": print("Features: ",code_info.features()) ut.main()
class ParticleProperties(ut.TestCase): # def __init__(self,particleId): # self.pid=particleId # the system which will be tested system = espressomd.System() # Particle id to work on pid = 17 # Error tolerance when comparing arrays/tuples... tol = 1E-9 def bondsMatch(self, inType, outType, inParams, outParams): """Check, if the bond type set and gotten back as well as the bond parameters set and gotten back match. Only check keys present in inParams. """ if inType != outType: return False for k in list(inParams.keys()): if k not in outParams: return False if outParams[k] != inParams[k]: return False return True def setUp(self): if not self.system.part.exists(self.pid): self.system.part.add(id=self.pid, pos=(0, 0, 0, 0)) def generateTestForBondParams(_bondId, _bondClass, _params): """Generates test cases for checking bond parameters set and gotten back from Es actually match. Only keys which are present in _params are checked 1st arg: Id of the bonded ia in Espresso to test on, i.e., 0,2,1... 2nd: Class of the bond potential to test, ie.e, FeneBond, HarmonicBond 3rd: Bond parameters as dictionary, i.e., {"k"=1.,"r_0"=0. """ bondId = _bondId bondClass = _bondClass params = _params def func(self): # This code is run at the execution of the generated function. # It will use the state of the variables in the outer function, # which was there, when the outer function was called self.system.bonded_inter[bondId] = bondClass(**params) outBond = self.system.bonded_inter[bondId] tnIn = bondClass(**params).type_number() tnOut = outBond.type_number() outParams = outBond.params self.assertTrue( self.bondsMatch(tnIn, tnOut, params, outParams), bondClass(**params).type_name() + ": value set and value gotten back differ for bond id " + str(bondId) + ": " + params.__str__() + " vs. " + outParams.__str__()) return func test_fene = generateTestForBondParams(0, FeneBond, { "r_0": 1.1, "k": 5.2, "d_r_max": 3. }) test_fene2 = generateTestForBondParams(1, FeneBond, { "r_0": 1.1, "k": 5.2, "d_r_max": 3. }) test_harmonic = generateTestForBondParams(0, HarmonicBond, { "r_0": 1.1, "k": 5.2 }) test_harmonic2 = generateTestForBondParams(0, HarmonicBond, { "r_0": 1.1, "k": 5.2, "r_cut": 1.3 }) if "ROTATION" in code_info.features(): test_harmonic_dumbbell = generateTestForBondParams( 0, HarmonicDumbbellBond, { "k1": 1.1, "k2": 2.2, "r_0": 1.5 }) test_harmonic_dumbbell2 = generateTestForBondParams( 0, HarmonicDumbbellBond, { "k1": 1.1, "k2": 2.2, "r_0": 1.5, "r_cut": 1.9 }) test_dihedral = generateTestForBondParams(0, Dihedral, { "mult": 3.0, "bend": 5.2, "phase": 3. }) if "BOND_ANGLE" in espressomd.features(): test_angle_harm = generateTestForBondParams(0, Angle_Harmonic, { "bend": 5.2, "phi0": 3.2 }) test_angle_cos = generateTestForBondParams(0, Angle_Cosine, { "bend": 5.2, "phi0": 3.2 }) test_angle_cossquare = generateTestForBondParams( 0, Angle_Cossquare, { "bend": 5.2, "phi0": 0. }) if "LENNARD_JONES" in espressomd.features(): test_subt_lj = generateTestForBondParams(0, Subt_Lj, { "k": 5.2, "r": 3.2 }) if "TABULATED" in espressomd.features(): test_tabulated = generateTestForBondParams(0, Tabulated, { "type": "distance", "filename": "lj1.tab" })
if "BOND_ANGLE" in espressomd.features(): test_angle_harm = generateTestForBondParams(0, Angle_Harmonic, { "bend": 5.2, "phi0": 3.2 }) test_angle_cos = generateTestForBondParams(0, Angle_Cosine, { "bend": 5.2, "phi0": 3.2 }) test_angle_cossquare = generateTestForBondParams( 0, Angle_Cossquare, { "bend": 5.2, "phi0": 0. }) if "LENNARD_JONES" in espressomd.features(): test_subt_lj = generateTestForBondParams(0, Subt_Lj, { "k": 5.2, "r": 3.2 }) if "TABULATED" in espressomd.features(): test_tabulated = generateTestForBondParams(0, Tabulated, { "type": "distance", "filename": "lj1.tab" }) if __name__ == "__main__": print("Features: ", code_info.features()) ut.main()
# along with this program. If not, see <http://www.gnu.org/licenses/>. # from __future__ import print_function import espressomd._system as es import espressomd from espressomd import thermostat from espressomd import code_info import numpy as np print(""" ======================================================= = slice_input.py = ======================================================= Program Information:""") print(code_info.features()) dev = "cpu" # System parameters ############################################################# box_l = 10.0 # Integration parameters ############################################################# system = espressomd.System() system.time_step = 0.01 system.cell_system.skin = 0.4
# from __future__ import print_function import espressomd._system as es import espressomd from espressomd import code_info from espressomd import electrostatics from espressomd import electrostatic_extensions import numpy print(""" ======================================================= = store_properties.py = ======================================================= Program Information:""") print(code_info.features()) if not "ELECTROSTATICS" in code_info.features(): raise Exception("Sample script requires ELECTROSTATICS") dev = "cpu" # System parameters ############################################################# # 10 000 Particles box_l = 10.7437 density = 0.7 # Interaction parameters (repulsive Lennard Jones) #############################################################
import espressomd._system as es import espressomd from espressomd import thermostat from espressomd import code_info from espressomd import integrate from espressomd import electrostatics from espressomd import electrostatic_extensions import numpy print(""" ======================================================= = store_properties.py = ======================================================= Program Information:""") print(code_info.features()) if not "ELECTROSTATICS" in code_info.features(): raise Exception("Sample script requires ELECTROSTATICS") dev = "cpu" # System parameters ############################################################# # 10 000 Particles box_l = 10.7437 density = 0.7 # Interaction parameters (repulsive Lennard Jones) #############################################################
if method not in implemented_methods: print("Please select an electrostatics method in the script.") exit() # Distinguish between different methods if method == "p3m": p3m = electrostatics.P3M(bjerrum_length=10.0, accuracy=1e-3) system.actors.add(p3m) print("P3M parameter:\n") p3m_params = p3m.get_params() for key in p3m_params.keys(): print("{} = {}".format(key, p3m_params[key])) # elif method == "memd": # TODO if "ROTATION" in code_info.features(): deg_free = 6 else: deg_free = 3 # Integration parameters integ_steps = 200 int_n_times = 20 # Warmup integration loop print("\nWarmup") for cap in xrange(20, 200, 20): print("t={0}, E={1}".format(system.time, system.analysis.energy()['total'])) system.non_bonded_inter.set_force_cap(cap) integrate.integrate(integ_steps)