def test_seed(self): tile_x = 1 tile_y = 1 thickness = 1.2 seed1 = 12345 seed2 = 54321 interface1 = mb.SilicaInterface(bulk_silica=AmorphousSilica(), tile_x=tile_x, tile_y=tile_y, thickness=thickness, seed=seed1) atom_names1 = np.array([atom.name for atom in interface1.particles()]) interface2 = mb.SilicaInterface(bulk_silica=AmorphousSilica(), tile_x=tile_x, tile_y=tile_y, thickness=thickness, seed=seed1) atom_names2 = np.array([atom.name for atom in interface2.particles()]) interface3 = mb.SilicaInterface(bulk_silica=AmorphousSilica(), tile_x=tile_x, tile_y=tile_y, thickness=thickness, seed=seed2) atom_names3 = np.array([atom.name for atom in interface3.particles()]) assert np.array_equal(atom_names1, atom_names2) assert not np.array_equal(atom_names1, atom_names3) assert np.array_equal(interface1.xyz, interface2.xyz) assert not np.array_equal(interface1.xyz, interface3.xyz)
def test_silica_interface(self): tile_x = 1 tile_y = 1 thickness = 0.6 interface = mb.SilicaInterface(bulk_silica=AmorphousSilica(), tile_x=tile_x, tile_y=tile_y, thickness=thickness) thickness_tolerance = 0.05 z = [ atom.pos[2] for atom in interface.particles() if atom.name == 'Si' ] assert abs(max(z) - min(z) - thickness) < thickness_tolerance density_tolerance = 0.1 area = interface.periodicity[0] * interface.periodicity[1] oh_count = len(list(interface.particles_by_name('OS'))) assert abs((oh_count / area) - 5.0) < density_tolerance
"""Label surface sites and add ports above them. """ for atom in self.particles(): if len(self.bond_graph.neighbors(atom)) == 1: if atom.name == 'O' and atom.pos[2] > thickness: atom.name = 'OS' port = mb.Port(anchor=atom) port.spin(np.pi/2, [1, 0, 0]) port.translate(np.array([0.0, 0.0, 0.1])) self.add(port, "port_{}".format(len(self.referenced_ports()))) def _adjust_stoichiometry(self): """Remove O's from underside of surface to yield a 2:1 Si:O ratio. """ num_O = len(list(self.particles_by_name('O'))) num_Si = len(list(self.particles_by_name('Si'))) n_deletions = num_O - 2*num_Si bottom_Os = [atom for atom in self.particles() if atom.name == 'O' and atom.pos[2] < self._O_buffer and len(self.bond_graph.neighbors(atom)) == 1] for _ in range(n_deletions): O1 = random.choice(bottom_Os) bottom_Os.remove(O1) self.remove(O1) if __name__ == "__main__": from mbuild.lib.bulk_materials import AmorphousSilica silica_interface = mb.SilicaInterface(bulk_silica=AmorphousSilica(), thickness=1.2) silica_interface.save('silica_interface.mol2', show_ports=True)