10 hasMagneticParticles = true
14 interactionParameters:
18 epsilon_magnetic = 1.2
28 magneticPrefactor = 100.7
30 dipoleOrientation = [1.0, 0.0, 0.0]
34 return Configuration(config)
37 def getParticles(filename = "test_StarPolymers_particles.vtf"):
42 particlePath = os.path.dirname(os.path.abspath(__file__))
43 particlePath +=
"/data/" + filename
47 with open(particlePath,
"r")
as vtf:
49 if line.startswith(
"atom"):
51 if line.startswith(
"bond"):
53 if line.startswith(
"timestep"):
55 components = line.split()
56 pos = [float(x)
for x
in components[0:3]]
57 vel = [float(x)
for x
in components[3:6]]
59 positions.append(Vector3DReal(pos))
60 velocities.append(Vector3DReal(vel))
62 ret = ParticleCollection()
63 ret.setPositionsAndVelocities(positions, velocities)
69 def test_constructor():
72 with pytest.raises(NotImplementedError):
74 config[
"structure.starCount"] = 2
78 with pytest.raises(TypeError):
81 with pytest.raises(TypeError):
82 StarPolymers({
"structure.starCount": 1})
84 with pytest.raises(TypeError):
88 sp = StarPolymers(config)
90 assert sp.getArmCountPerStar() == 5
91 config[
"structure.armCountPerStar"] = 2
92 assert sp.getArmCountPerStar() == 5
94 def test_getStarCount():
95 sp = StarPolymers(getConfig())
97 assert sp.getStarCount() == 1
98 assert sp.getStarCount() == 1
101 def test_getArmCountPerStar():
102 sp = StarPolymers(getConfig())
104 assert sp.getArmCountPerStar() == 5
105 assert sp.getArmCountPerStar() == 5
108 def test_getArmParticlesPerArm():
109 sp = StarPolymers(getConfig())
111 assert sp.getArmParticlesPerArm() == 3
112 assert sp.getArmParticlesPerArm() == 3
115 def test_getTotalParticleCountPerArm():
116 sp = StarPolymers(getConfig())
118 assert sp.getTotalParticleCountPerArm() == 3 + 1
119 assert sp.getTotalParticleCountPerArm() == 3 + 1
122 def test_hasMagneticParticles():
123 sp = StarPolymers(getConfig())
125 assert sp.hasMagneticParticles() ==
True
126 assert sp.hasMagneticParticles() ==
True
129 def test_getParticleMass():
130 sp = StarPolymers(getConfig())
132 assert sp.getParticleMass() == 4.5
133 assert sp.getParticleMass() == 4.5
136 def test_getTotalParticleCountPerStar():
137 sp = StarPolymers(getConfig())
139 assert sp.getTotalParticleCountPerStar() == 1 + 5 * (3 + 1)
142 def test_getTotalParticleCount():
143 sp = StarPolymers(getConfig())
145 expected = sp.getStarCount() * sp.getTotalParticleCountPerStar()
146 assert sp.getTotalParticleCount() == expected
147 assert sp.getTotalParticleCount() == expected
150 def test_getParticleType():
153 sp = StarPolymers(getConfig())
155 assert sp.getTotalParticleCount() == 21
157 with pytest.raises(IndexError):
158 sp.getParticleType(-1)
160 with pytest.raises(IndexError):
161 sp.getParticleType(sp.getTotalParticleCount())
163 with pytest.raises(IndexError):
164 sp.getParticleType(sp.getTotalParticleCount() + 1)
166 with pytest.raises(TypeError):
167 sp.getParticleType(0.0)
170 for _
in range(0, 3):
171 assert sp.getParticleType(0) ==
"Core"
173 assert sp.getParticleType(1) ==
"Arm"
174 assert sp.getParticleType(2) ==
"Arm"
175 assert sp.getParticleType(3) ==
"Arm"
176 assert sp.getParticleType(4) ==
"Magnetic"
178 assert sp.getParticleType(5) ==
"Arm"
179 assert sp.getParticleType(6) ==
"Arm"
180 assert sp.getParticleType(7) ==
"Arm"
181 assert sp.getParticleType(8) ==
"Magnetic"
183 assert sp.getParticleType(9) ==
"Arm"
184 assert sp.getParticleType(10) ==
"Arm"
185 assert sp.getParticleType(11) ==
"Arm"
186 assert sp.getParticleType(12) ==
"Magnetic"
188 assert sp.getParticleType(13) ==
"Arm"
189 assert sp.getParticleType(14) ==
"Arm"
190 assert sp.getParticleType(15) ==
"Arm"
191 assert sp.getParticleType(16) ==
"Magnetic"
193 assert sp.getParticleType(17) ==
"Arm"
194 assert sp.getParticleType(18) ==
"Arm"
195 assert sp.getParticleType(19) ==
"Arm"
196 assert sp.getParticleType(20) ==
"Magnetic"
199 def test_getParticleStructureIndices():
202 sp = StarPolymers(getConfig())
204 assert sp.getTotalParticleCount() == 21
206 with pytest.raises(IndexError):
207 sp.getParticleStructureIndices(-1)
209 with pytest.raises(IndexError):
210 sp.getParticleStructureIndices(sp.getTotalParticleCount())
212 with pytest.raises(IndexError):
213 sp.getParticleStructureIndices(sp.getTotalParticleCount() + 1)
215 with pytest.raises(TypeError):
216 sp.getParticleStructureIndices(0.0)
218 for _
in range(0, 3):
219 assert sp.getParticleStructureIndices(0) == [0,
None,
None]
221 assert sp.getParticleStructureIndices(1) == [0, 0, 0]
222 assert sp.getParticleStructureIndices(2) == [0, 0, 1]
223 assert sp.getParticleStructureIndices(3) == [0, 0, 2]
224 assert sp.getParticleStructureIndices(4) == [0, 0,
None]
226 assert sp.getParticleStructureIndices(5) == [0, 1, 0]
227 assert sp.getParticleStructureIndices(6) == [0, 1, 1]
228 assert sp.getParticleStructureIndices(7) == [0, 1, 2]
229 assert sp.getParticleStructureIndices(8) == [0, 1,
None]
231 assert sp.getParticleStructureIndices(9) == [0, 2, 0]
232 assert sp.getParticleStructureIndices(10) == [0, 2, 1]
233 assert sp.getParticleStructureIndices(11) == [0, 2, 2]
234 assert sp.getParticleStructureIndices(12) == [0, 2,
None]
236 assert sp.getParticleStructureIndices(13) == [0, 3, 0]
237 assert sp.getParticleStructureIndices(14) == [0, 3, 1]
238 assert sp.getParticleStructureIndices(15) == [0, 3, 2]
239 assert sp.getParticleStructureIndices(16) == [0, 3,
None]
241 assert sp.getParticleStructureIndices(17) == [0, 4, 0]
242 assert sp.getParticleStructureIndices(18) == [0, 4, 1]
243 assert sp.getParticleStructureIndices(19) == [0, 4, 2]
244 assert sp.getParticleStructureIndices(20) == [0, 4,
None]
247 def test_particlesAreBonded():
250 sp = StarPolymers(getConfig())
252 assert sp.getTotalParticleCount() == 21
254 with pytest.raises(IndexError):
255 sp.particlesAreBonded(-1, 0)
257 with pytest.raises(IndexError):
258 sp.particlesAreBonded(0, -1)
260 with pytest.raises(IndexError):
261 sp.particlesAreBonded(sp.getTotalParticleCount(), 0)
263 with pytest.raises(IndexError):
264 sp.particlesAreBonded(0, sp.getTotalParticleCount())
266 with pytest.raises(IndexError):
267 sp.particlesAreBonded(sp.getTotalParticleCount() + 1, 0)
269 with pytest.raises(IndexError):
270 sp.particlesAreBonded(0, sp.getTotalParticleCount() + 1)
272 with pytest.raises(TypeError):
273 sp.particlesAreBonded(0.0, 0)
275 with pytest.raises(TypeError):
276 sp.particlesAreBonded(0, 0.0)
279 for pID1
in range(0, sp.getTotalParticleCount()):
280 assert sp.particlesAreBonded(pID1, pID1) ==
False
282 for pID2
in range(pID1 + 1, sp.getTotalParticleCount()):
283 assert sp.particlesAreBonded(pID1, pID2) \
284 == sp.particlesAreBonded(pID2, pID1)
286 indices1 = sp.getParticleStructureIndices(pID1)
287 indices2 = sp.getParticleStructureIndices(pID2)
289 if indices1[0] != indices2[0]:
290 assert sp.particlesAreBonded(pID1, pID2) ==
False
293 if sp.getParticleType(pID1) ==
"Core":
294 assert sp.hasMagneticParticles()
295 bonded = indices2[2] == 0
296 assert sp.particlesAreBonded(pID1, pID2) == bonded
297 elif sp.getParticleType(pID1) ==
"Magnetic":
299 assert sp.particlesAreBonded(pID1, pID2) ==
False
301 if indices1[1] == indices2[1]:
302 bonded = pID2 - pID1 == 1
303 assert sp.particlesAreBonded(pID1, pID2) == bonded
305 assert sp.particlesAreBonded(pID1, pID2) ==
False
308 def test_setParticles():
313 sp = StarPolymers(getConfig())
315 particleCount = sp.getTotalParticleCount()
316 assert particleCount == 21
318 with pytest.raises(TypeError):
319 sp.setParticles(
None)
321 with pytest.raises(TypeError):
322 sp.setParticles([[0.0, 1.0, 2.0]
for _
in range(0, 21)])
324 with pytest.raises(ValueError):
325 particles = ParticleCollection()
326 positions = [Vector3DReal(i, 0, 0)
for i
in range(0, particleCount - 1)]
327 velocities = positions
328 particles.setPositionsAndVelocities(positions, velocities)
329 sp.setParticles(particles)
332 particles = getParticles()
333 sp.setParticles(particles)
335 assert sp._particles
is particles
338 def test_getMagneticClusters_getMagneticClusterCount():
341 particles = getParticles()
343 def test_raiseBecauseNoMagnets():
345 config[
"structure.hasMagneticParticles"] =
False
346 config[
"structure.armParticlesPerArm"] = \
347 config[
"structure.armParticlesPerArm"] + 1
348 mysp = StarPolymers(config)
350 with pytest.raises(ValueError):
351 mysp.getMagneticClusters(2.5)
353 with pytest.raises(ValueError):
354 mysp.getMagneticClusterCount(2.5)
355 test_raiseBecauseNoMagnets()
358 sp = StarPolymers(getConfig())
359 assert sp.getTotalParticleCount() == 21
361 with pytest.raises(ValueError):
362 sp.getMagneticClusters(2.5)
363 with pytest.raises(ValueError):
364 sp.getMagneticClusterCount(2.5)
367 sp.setParticles(particles)
370 with pytest.raises(TypeError):
371 sp.getMagneticClusters([1])
372 with pytest.raises(TypeError):
373 sp.getMagneticClusterCount([1])
375 with pytest.raises(ValueError):
376 sp.getMagneticClusters(-1)
377 with pytest.raises(ValueError):
378 sp.getMagneticClusterCount(-1)
380 with pytest.raises(ValueError):
381 sp.getMagneticClusters(-1.0)
382 with pytest.raises(ValueError):
383 sp.getMagneticClusterCount(-1.0)
387 for i
in [4, 8, 12, 16, 20]:
388 assert sp.getParticleType(i) ==
"Magnetic"
389 magnets.append(particles.getPosition(i))
391 def indexByPosition(position):
392 for index, pos
in enumerate(magnets):
398 expectedClustersCollection = \
400 0: [ [0], [1], [2], [3], [4] ],
401 0.8: [ [0], [1], [2], [3], [4] ],
402 0.9: [ [0, 3], [1], [2], [4] ],
403 3: [ [0, 3], [1], [2], [4] ],
404 3.3: [ [0, 3, 4], [1], [2] ],
405 7.8: [ [0, 3, 4], [1, 2] ],
406 7.9: [ [0, 1, 2, 3, 4] ],
407 100: [ [0, 1, 2, 3, 4] ]
411 for distance, expectedClusters
in expectedClustersCollection.items():
412 assert len(expectedClusters) == sp.getMagneticClusterCount(distance)
415 for cluster
in sp.getMagneticClusters(distance):
416 indices = [indexByPosition(pos)
for pos
in cluster]
417 clusterSet.add(frozenset(indices))
419 expectedClusterSet = set()
420 for cluster
in expectedClusters:
421 expectedClusterSet.add(frozenset(cluster))
423 assert clusterSet == expectedClusterSet
426 def test_getWCAPotentialParameterEpsilon():
430 config_nomagnetic = getConfig()
431 config_nomagnetic[
"structure.hasMagneticParticles"] =
False
432 sp = StarPolymers(config)
433 sp_nomagnetic = StarPolymers(config_nomagnetic)
435 with pytest.raises(TypeError):
436 sp.getWCAPotentialParameterEpsilon(0,
"Core")
437 with pytest.raises(TypeError):
438 sp.getWCAPotentialParameterEpsilon(
"Core", 0)
440 with pytest.raises(ValueError):
441 sp.getWCAPotentialParameterEpsilon(
"Core",
"Foo")
442 with pytest.raises(ValueError):
443 sp.getWCAPotentialParameterEpsilon(
"Foo",
"Core")
444 with pytest.raises(ValueError):
445 sp_nomagnetic.getWCAPotentialParameterEpsilon(
"Core",
"Magnetic")
446 with pytest.raises(ValueError):
447 sp_nomagnetic.getWCAPotentialParameterEpsilon(
"Magnetic",
"Core")
450 epsilon_C = config[
"interactionParameters.epsilon_core"]
451 epsilon_A = config[
"interactionParameters.epsilon_arm"]
452 epsilon_M = config[
"interactionParameters.epsilon_magnetic"]
454 epsilon_CC = epsilon_C
455 epsilon_AA = epsilon_A
456 epsilon_MM = epsilon_M
459 epsilon_CA = math.sqrt(epsilon_C * epsilon_A)
460 epsilon_CM = math.sqrt(epsilon_C * epsilon_M)
461 epsilon_AM = math.sqrt(epsilon_A * epsilon_M)
463 assert sp.getWCAPotentialParameterEpsilon(
"Core",
"Core") == epsilon_CC
464 assert sp.getWCAPotentialParameterEpsilon(
"Core",
"Arm") == epsilon_CA
465 assert sp.getWCAPotentialParameterEpsilon(
"Core",
"Magnetic") == epsilon_CM
467 assert sp.getWCAPotentialParameterEpsilon(
"Arm",
"Core") == epsilon_CA
468 assert sp.getWCAPotentialParameterEpsilon(
"Arm",
"Arm") == epsilon_AA
469 assert sp.getWCAPotentialParameterEpsilon(
"Arm",
"Magnetic") == epsilon_AM
471 assert sp.getWCAPotentialParameterEpsilon(
"Magnetic",
"Core") == epsilon_CM
472 assert sp.getWCAPotentialParameterEpsilon(
"Magnetic",
"Arm") == epsilon_AM
473 assert sp.getWCAPotentialParameterEpsilon(
"Magnetic",
"Magnetic") == \
477 def test_getWCAPotentialParameterSigma():
481 config_nomagnetic = getConfig()
482 config_nomagnetic[
"structure.hasMagneticParticles"] =
False
483 sp = StarPolymers(config)
484 sp_nomagnetic = StarPolymers(config_nomagnetic)
486 with pytest.raises(TypeError):
487 sp.getWCAPotentialParameterSigma(0,
"Core")
488 with pytest.raises(TypeError):
489 sp.getWCAPotentialParameterSigma(
"Core", 0)
491 with pytest.raises(ValueError):
492 sp.getWCAPotentialParameterSigma(
"Core",
"Foo")
493 with pytest.raises(ValueError):
494 sp.getWCAPotentialParameterSigma(
"Foo",
"Core")
495 with pytest.raises(ValueError):
496 sp_nomagnetic.getWCAPotentialParameterSigma(
"Core",
"Magnetic")
497 with pytest.raises(ValueError):
498 sp_nomagnetic.getWCAPotentialParameterSigma(
"Magnetic",
"Core")
501 sigma_C = config[
"interactionParameters.sigma_core"]
502 sigma_A = config[
"interactionParameters.sigma_arm"]
503 sigma_M = config[
"interactionParameters.sigma_magnetic"]
509 sigma_CA = (sigma_C + sigma_A) / 2.0
510 sigma_CM = (sigma_C + sigma_M) / 2.0
511 sigma_AM = (sigma_A + sigma_M) / 2.0
513 assert sp.getWCAPotentialParameterSigma(
"Core",
"Core") == sigma_CC
514 assert sp.getWCAPotentialParameterSigma(
"Core",
"Arm") == sigma_CA
515 assert sp.getWCAPotentialParameterSigma(
"Core",
"Magnetic") == sigma_CM
517 assert sp.getWCAPotentialParameterSigma(
"Arm",
"Core") == sigma_CA
518 assert sp.getWCAPotentialParameterSigma(
"Arm",
"Arm") == sigma_AA
519 assert sp.getWCAPotentialParameterSigma(
"Arm",
"Magnetic") == sigma_AM
521 assert sp.getWCAPotentialParameterSigma(
"Magnetic",
"Core") == sigma_CM
522 assert sp.getWCAPotentialParameterSigma(
"Magnetic",
"Arm") == sigma_AM
523 assert sp.getWCAPotentialParameterSigma(
"Magnetic",
"Magnetic") == sigma_MM
526 def test_getWCAPotentialParameterD():
530 config_nomagnetic = getConfig()
531 config_nomagnetic[
"structure.hasMagneticParticles"] =
False
532 sp = StarPolymers(config)
533 sp_nomagnetic = StarPolymers(config_nomagnetic)
535 with pytest.raises(TypeError):
536 sp.getWCAPotentialParameterD(0,
"Core")
537 with pytest.raises(TypeError):
538 sp.getWCAPotentialParameterD(
"Core", 0)
540 with pytest.raises(ValueError):
541 sp.getWCAPotentialParameterD(
"Core",
"Foo")
542 with pytest.raises(ValueError):
543 sp.getWCAPotentialParameterD(
"Foo",
"Core")
544 with pytest.raises(ValueError):
545 sp_nomagnetic.getWCAPotentialParameterD(
"Core",
"Magnetic")
546 with pytest.raises(ValueError):
547 sp_nomagnetic.getWCAPotentialParameterD(
"Magnetic",
"Core")
550 D_C = config[
"interactionParameters.D_core"]
551 D_A = config[
"interactionParameters.D_arm"]
552 D_M = config[
"interactionParameters.D_magnetic"]
558 D_CA = (D_C + D_A) / 2.0
559 D_CM = (D_C + D_M) / 2.0
560 D_AM = (D_A + D_M) / 2.0
562 assert sp.getWCAPotentialParameterD(
"Core",
"Core") == D_CC
563 assert sp.getWCAPotentialParameterD(
"Core",
"Arm") == D_CA
564 assert sp.getWCAPotentialParameterD(
"Core",
"Magnetic") == D_CM
566 assert sp.getWCAPotentialParameterD(
"Arm",
"Core") == D_CA
567 assert sp.getWCAPotentialParameterD(
"Arm",
"Arm") == D_AA
568 assert sp.getWCAPotentialParameterD(
"Arm",
"Magnetic") == D_AM
570 assert sp.getWCAPotentialParameterD(
"Magnetic",
"Core") == D_CM
571 assert sp.getWCAPotentialParameterD(
"Magnetic",
"Arm") == D_AM
572 assert sp.getWCAPotentialParameterD(
"Magnetic",
"Magnetic") == D_MM
575 def test_getWCAPotential():
579 config_nomagnetic = getConfig()
580 config_nomagnetic[
"structure.hasMagneticParticles"] =
False
581 sp = StarPolymers(config)
582 sp_nomagnetic = StarPolymers(config_nomagnetic)
584 with pytest.raises(TypeError):
585 sp.getWCAPotential(0,
"Core")
586 with pytest.raises(TypeError):
587 sp.getWCAPotential(
"Core", 0)
589 with pytest.raises(ValueError):
590 sp.getWCAPotential(
"Core",
"Foo")
591 with pytest.raises(ValueError):
592 sp.getWCAPotential(
"Foo",
"Core")
593 with pytest.raises(ValueError):
594 sp_nomagnetic.getWCAPotential(
"Core",
"Magnetic")
595 with pytest.raises(ValueError):
596 sp_nomagnetic.getWCAPotential(
"Magnetic",
"Core")
600 import WeeksChandlerAndersen_DistanceOffset
as WCA
601 types = [
"Core",
"Arm",
"Magnetic"]
604 epsilon = sp.getWCAPotentialParameterEpsilon(type1, type2)
605 sigma = sp.getWCAPotentialParameterSigma(type1, type2)
606 d = sp.getWCAPotentialParameterD(type1, type2)
608 wca = sp.getWCAPotential(type1, type2)
610 assert isinstance(wca, WCA)
611 assert wca.getEpsilon() == epsilon
612 assert wca.getSigma() == sigma
613 assert wca.getD() == d
616 wca = sp.getWCAPotential(type1, type2)
618 assert isinstance(wca, WCA)
619 assert wca.getEpsilon() == epsilon
620 assert wca.getSigma() == sigma
621 assert wca.getD() == d
624 def test_getFENEPotential():
628 config_nomagnetic = getConfig()
629 config_nomagnetic[
"structure.hasMagneticParticles"] =
False
630 sp = StarPolymers(config)
631 sp_nomagnetic = StarPolymers(config_nomagnetic)
633 with pytest.raises(TypeError):
634 sp.getFENEPotential(0,
"Core")
635 with pytest.raises(TypeError):
636 sp.getFENEPotential(
"Core", 0)
638 with pytest.raises(ValueError):
639 sp.getFENEPotential(
"Core",
"Foo")
640 with pytest.raises(ValueError):
641 sp.getFENEPotential(
"Foo",
"Core")
642 with pytest.raises(ValueError):
643 sp_nomagnetic.getFENEPotential(
"Core",
"Magnetic")
644 with pytest.raises(ValueError):
645 sp_nomagnetic.getFENEPotential(
"Magnetic",
"Core")
650 types = [
"Core",
"Arm",
"Magnetic"]
653 epsilon = sp.getWCAPotentialParameterEpsilon(type1, type2)
654 sigma = sp.getWCAPotentialParameterSigma(type1, type2)
655 d = sp.getWCAPotentialParameterD(type1, type2)
657 fene = sp.getFENEPotential(type1, type2)
659 assert isinstance(fene, FENE)
660 assert fene.getK() == pytest.approx(30 * epsilon * sigma ** -2)
661 assert fene.get_l_0() == d
662 assert fene.getR() == 1.5 * sigma
665 fene = sp.getFENEPotential(type1, type2)
667 assert isinstance(fene, FENE)
668 assert fene.getK() == pytest.approx(30 * epsilon * sigma ** -2)
669 assert fene.get_l_0() == d
670 assert fene.getR() == 1.5 * sigma
673 def test_getMagneticPotential():
677 config_nomagnetic = getConfig()
678 config_nomagnetic[
"structure.hasMagneticParticles"] =
False
679 sp = StarPolymers(config)
680 sp_nomagnetic = StarPolymers(config_nomagnetic)
682 with pytest.raises(RuntimeError):
683 sp_nomagnetic.getMagneticPotential()
687 import MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles \
691 prefactor = config[
"interactionParameters.magneticPrefactor"]
692 orientationX = config[
"interactionParameters.dipoleOrientation.[0]"]
693 orientationY = config[
"interactionParameters.dipoleOrientation.[1]"]
694 orientationZ = config[
"interactionParameters.dipoleOrientation.[2]"]
695 orientation = Vector3DReal(orientationX, orientationY, orientationZ)
697 potential = sp.getMagneticPotential()
699 assert isinstance(potential, Potential)
700 assert potential.getPrefactor() == prefactor
701 assert potential.getOrientation() == orientation
704 potential = sp.getMagneticPotential()
706 assert isinstance(potential, Potential)
707 assert potential.getPrefactor() == prefactor
708 assert potential.getOrientation() == orientation
711 def test_getPotentialEnergy():
714 particles = getParticles(
"test_StarPolymers_particles_2.vtf")
716 sp = StarPolymers(getConfig())
717 assert sp.getStarCount() == 1
718 assert sp.getTotalParticleCount() == 21
720 with pytest.raises(ValueError):
721 sp.getPotentialEnergy()
723 wca_CA = sp.getWCAPotential(
"Core",
"Arm")
724 wca_CM = sp.getWCAPotential(
"Core",
"Magnetic")
725 wca_AA = sp.getWCAPotential(
"Arm",
"Arm")
726 wca_AM = sp.getWCAPotential(
"Arm",
"Magnetic")
727 wca_MM = sp.getWCAPotential(
"Magnetic",
"Magnetic")
729 fene_CA = sp.getFENEPotential(
"Core",
"Arm")
730 fene_AA = sp.getFENEPotential(
"Arm",
"Arm")
731 fene_AM = sp.getFENEPotential(
"Arm",
"Magnetic")
733 magnetic = sp.getMagneticPotential()
735 arms = [ [1, 2, 3], [5, 6, 7], [9, 10, 11], [13, 14, 15], [17, 18, 19]]
736 magneticParticles = [4, 8, 12, 16, 20]
740 assert sp.getParticleType(p) ==
"Arm"
741 for p
in magneticParticles:
742 assert sp.getParticleType(p) ==
"Magnetic"
745 sp.setParticles(particles)
749 pos_C = particles.getPosition(0)
751 for i, p
in enumerate(arm):
752 r = pos_C - particles.getPosition(p)
754 expected += wca_CA.getPotential(r)
756 expected += fene_CA.getPotential(r)
757 for p
in magneticParticles:
758 r = pos_C - particles.getPosition(p)
759 expected += wca_CM.getPotential(r)
765 pos1 = particles.getPosition(p1)
769 r = pos1 - particles.getPosition(p2)
771 expected += wca_AA.getPotential(r)
774 expected += fene_AA.getPotential(r)
778 pos1 = particles.getPosition(p1)
779 for p2
in magneticParticles:
780 r = pos1 - particles.getPosition(p2)
782 expected += wca_AM.getPotential(r)
785 for p1
in magneticParticles:
786 pos1 = particles.getPosition(p1)
788 bonded = particles.getPosition(p1 - 1)
789 expected += fene_AM.getPotential(pos1 - bonded)
791 for p2
in magneticParticles:
794 r = pos1 - particles.getPosition(p2)
795 expected += wca_MM.getPotential(r)
796 expected += magnetic.getPotential(r)
798 assert sp.getPotentialEnergy() == expected
801 assert sp.getPotentialEnergy() == expected