WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit d5f15fc

Browse files
authored
Bug fix for constraints (#403)
1 parent 06d3fe2 commit d5f15fc

File tree

2 files changed

+92
-5
lines changed

2 files changed

+92
-5
lines changed

src/pylammpsmpi/wrapper/ase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def get_fixed_atom_boolean_vector(structure):
561561
if c_dict["name"] == "FixAtoms":
562562
fixed_atom_vector[c_dict["kwargs"]["indices"]] = [True, True, True]
563563
elif c_dict["name"] == "FixedPlane":
564-
if all(np.isin(c_dict["kwargs"]["direction"], [0, 1])):
564+
if all(np.isin(c_dict["kwargs"]["direction"], [0, 1, 1 / np.sqrt(2)])):
565565
if "indices" in c_dict["kwargs"]:
566566
fixed_atom_vector[c_dict["kwargs"]["indices"]] = np.array(
567567
c_dict["kwargs"]["direction"]

tests/test_ase_interface.py

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def setUpClass(cls):
416416
structure.symbols[2:] = "Al"
417417
cls.structure = structure
418418

419-
def test_selective_dynamics_mixed_calcmd(self):
419+
def test_selective_dynamics_mixed_calcmd_x(self):
420420
atoms = self.structure.copy()
421421
c1 = FixAtoms(indices=[atom.index for atom in atoms if atom.symbol == "Cu"])
422422
c2 = FixedPlane(
@@ -433,11 +433,98 @@ def test_selective_dynamics_mixed_calcmd(self):
433433
self.assertTrue(control_dict["velocity constraintxyz"], "set 0.0 0.0 0.0")
434434
self.assertTrue(control_dict["group constraintx"], "id 3 4")
435435
self.assertTrue(
436-
control_dict["fix constraintx"], "constraintx setforce 0.0 NULL NULL"
436+
control_dict["fix constraintx"], "constraintx setforce NULL NULL 0.0"
437+
)
438+
self.assertTrue(control_dict["velocity constraintx"], "set NULL NULL 0.0")
439+
440+
def test_selective_dynamics_mixed_calcmd_y(self):
441+
atoms = self.structure.copy()
442+
c1 = FixAtoms(indices=[atom.index for atom in atoms if atom.symbol == "Cu"])
443+
c2 = FixedPlane(
444+
[atom.index for atom in atoms if atom.symbol == "Al"],
445+
[0, 1, 0],
446+
)
447+
atoms.set_constraint([c1, c2])
448+
control_dict = set_selective_dynamics(structure=atoms, calc_md=True)
449+
self.assertEqual(len(control_dict), 6)
450+
self.assertTrue(control_dict["group constraintxyz"], "id 1 2")
451+
self.assertTrue(
452+
control_dict["fix constraintxyz"], "constraintxyz setforce 0.0 0.0 0.0"
453+
)
454+
self.assertTrue(control_dict["velocity constraintxyz"], "set 0.0 0.0 0.0")
455+
self.assertTrue(control_dict["group constrainty"], "id 3 4")
456+
self.assertTrue(
457+
control_dict["fix constrainty"], "constrainty setforce NULL 0.0 NULL"
458+
)
459+
self.assertTrue(control_dict["velocity constrainty"], "set NULL 0.0 NULL")
460+
461+
def test_selective_dynamics_mixed_calcmd_z(self):
462+
atoms = self.structure.copy()
463+
c1 = FixAtoms(indices=[atom.index for atom in atoms if atom.symbol == "Cu"])
464+
c2 = FixedPlane(
465+
[atom.index for atom in atoms if atom.symbol == "Al"],
466+
[0, 0, 1],
467+
)
468+
atoms.set_constraint([c1, c2])
469+
control_dict = set_selective_dynamics(structure=atoms, calc_md=True)
470+
self.assertEqual(len(control_dict), 6)
471+
self.assertTrue(control_dict["group constraintxyz"], "id 1 2")
472+
self.assertTrue(
473+
control_dict["fix constraintxyz"], "constraintxyz setforce 0.0 0.0 0.0"
474+
)
475+
self.assertTrue(control_dict["velocity constraintxyz"], "set 0.0 0.0 0.0")
476+
self.assertTrue(control_dict["group constraintz"], "id 3 4")
477+
self.assertTrue(
478+
control_dict["fix constraintz"], "constraintz setforce NULL NULL 0.0"
479+
)
480+
self.assertTrue(control_dict["velocity constraintz"], "set NULL NULL 0.0")
481+
482+
def test_selective_dynamics_calcmd_xy(self):
483+
atoms = self.structure.copy()
484+
c1 = FixedPlane(
485+
[atom.index for atom in atoms if atom.symbol == "Al"],
486+
[1, 1, 0],
487+
)
488+
atoms.set_constraint([c1])
489+
control_dict = set_selective_dynamics(structure=atoms, calc_md=True)
490+
self.assertEqual(len(control_dict), 3)
491+
self.assertTrue(control_dict["group constraintxy"], "id 3 4")
492+
self.assertTrue(
493+
control_dict["fix constraintxy"], "constraintxy setforce NULL 0.0 0.0"
494+
)
495+
self.assertTrue(control_dict["velocity constraintxy"], "set NULL 0.0 0.0")
496+
497+
def test_selective_dynamics_calcmd_xz(self):
498+
atoms = self.structure.copy()
499+
c1 = FixedPlane(
500+
[atom.index for atom in atoms if atom.symbol == "Al"],
501+
[1, 0, 1],
502+
)
503+
atoms.set_constraint([c1])
504+
control_dict = set_selective_dynamics(structure=atoms, calc_md=True)
505+
self.assertEqual(len(control_dict), 3)
506+
self.assertTrue(control_dict["group constraintxz"], "id 3 4")
507+
self.assertTrue(
508+
control_dict["fix constraintxz"], "constraintxz setforce NULL 0.0 0.0"
509+
)
510+
self.assertTrue(control_dict["velocity constraintxz"], "set NULL 0.0 0.0")
511+
512+
def test_selective_dynamics_calcmd_yz(self):
513+
atoms = self.structure.copy()
514+
c1 = FixedPlane(
515+
[atom.index for atom in atoms if atom.symbol == "Al"],
516+
[0, 1, 1],
517+
)
518+
atoms.set_constraint([c1])
519+
control_dict = set_selective_dynamics(structure=atoms, calc_md=True)
520+
self.assertEqual(len(control_dict), 3)
521+
self.assertTrue(control_dict["group constraintyz"], "id 3 4")
522+
self.assertTrue(
523+
control_dict["fix constraintyz"], "constraintyz setforce NULL 0.0 0.0"
437524
)
438-
self.assertTrue(control_dict["velocity constraintx"], "set 0.0 NULL NULL")
525+
self.assertTrue(control_dict["velocity constraintyz"], "set NULL 0.0 0.0")
439526

440-
def test_selective_dynamics_mixed(self):
527+
def test_selective_dynamics_mixed_x(self):
441528
atoms = self.structure.copy()
442529
c1 = FixAtoms(indices=[atom.index for atom in atoms if atom.symbol == "Cu"])
443530
c2 = FixedPlane(

0 commit comments

Comments
 (0)