def test_centering_benzene_molecule_to_given_coordinates(): """Tests molecule center for benzene""" benzene = Molecule(read=benzene_xyz) benzene.center([5, 0, -5]) assert np.allclose(benzene.get_center(), [5, 0, -5]) benzene.center() assert np.allclose(benzene.get_center(), [0, 0, 0]) benzene.translate([0, 0, 7]) assert np.allclose(benzene.get_center(), [0, 0, 7]) benzene.rotate(([0, 0, 0], [0, 1, 0]), np.pi / 2) assert np.allclose(benzene.get_center(), [7, 0, 0]) benzene.rotate(([0, 0, 0], [0, 1, 0]), np.pi / 2, center=True) assert np.allclose(benzene.get_center(), [7, 0, 0])
def setup_lammps(opts): """Write LAMMPS simulation files.""" # Read structure information coords = np.array(opts['cjson']['atoms']['coords']['3d']) atoms = [ periodictable.elements[i].symbol for i in opts['cjson']['atoms']['elements']['number'] ] nanocar = Molecule(atoms=atoms, coordinates=np.array(coords).reshape( (int(len(coords) / 3)), 3)) opts['box_x'], opts['box_y'], opts[ 'box_z'] = opts['box_x'] * 10, opts['box_y'] * 10, opts['box_z'] * 10 nanocar.set_cell([opts['box_x'], opts['box_y'], opts['box_z'], 90, 90, 90]) nanocar.center([opts['box_x'] / 2, opts['box_y'] / 2, opts['box_z'] / 2]) if not os.path.isdir(opts['dir']): # try removing the last part of the path (a file) parent = (Path(opts['dir']).parent.absolute()) if not os.path.isdir(parent): opts['dir'] = PLUGIN_DIR print('Directory not found! Using plug-in directory -> %s' % PLUGIN_DIR) else: opts['dir'] = parent data_file = os.path.join(opts['dir'], 'data.nanocar') write_data_file(data_file, nanocar) # Write input file surface_info = read_surface_info() surface_ids = surface_info['id'] surface_atoms = surface_ids[1] - surface_ids[0] num_atoms = len(nanocar.atoms) if surface_ids[0] == 1: mol_ids = [num_atoms - surface_atoms, num_atoms] else: mol_ids = [1, num_atoms - surface_atoms - 1] input_file = os.path.join(opts['dir'], 'in.nanocar') inp_parameters = { 'sim_length': opts['sim_length'], 'ts': opts['timestep'], 'mol_ids': mol_ids, 'surface_ids': surface_ids, 'T': 300 } write_input_file(input_file, nanocar, inp_parameters)
def build_nanocar(opts): """Builds Nanocar molecule.""" chassis = Molecule(read=os.path.join(chassis_dir, '%s.xyz' % opts['chassis'])) chassis.center([opts['center-x'], opts['center-y'], opts['center-z']]) return mol2xyz(chassis)
def test_benzene_reflection_yz_plane_should_change_x_axis_position(): mol = Molecule(read=benzene_xyz) mol.center([5, 0, 0]) mol.reflect('yz') assert np.allclose(mol.get_center(), [-5, 0, 0])