def test_compare_atoms(self): coordinates = model.Coordinates(12.03, 11.01, 10.02) atom1 = model.Atom("C", coordinates) atom2 = model.Atom("C", coordinates) atom3 = model.Atom("Ce", coordinates) self.assertEqual(atom1, atom2) self.assertNotEqual(atom1, atom3)
def __make_example_molecule(self): coordinatesH1 = model.Coordinates(0.0, 0.0, 0.95) coordinatesH2 = model.Coordinates(0.89567, 0.00, -0.316663) coordinatesO1 = model.Coordinates(0.0, 0.0, 0.0) coordinatesO2 = model.Coordinates(4.0, 0.0, 0.0) atomH1 = model.Atom("H", coordinatesH1) atomH2 = model.Atom("H", coordinatesH2) atomO1 = model.Atom("O", coordinatesO1) atomO2 = model.Atom("O", coordinatesO2) return model.Molecule([atomH1, atomH2, atomO1, atomO2], "MOL")
def test_compare_molecules(self): coordinates1 = model.Coordinates() coordinates2 = model.Coordinates(1.0, 0.0, 0.0) coordinates3 = model.Coordinates(0.5, 1.0, 0.0) atom1 = model.Atom("H", coordinates1) atom2 = model.Atom("H", coordinates2) atom3 = model.Atom("H", coordinates3) molecule1 = model.Molecule([atom1, atom2], "MOL") molecule2 = model.Molecule([atom2, atom1], "MOL") molecule3 = model.Molecule([atom1, atom2, atom3], "MOL") self.assertEqual(molecule1, molecule2) self.assertNotEqual(molecule2, molecule3)
def test_xyz_tinker_reader(self): reader = readingutils.InputReader(PACKMOL_TINKER_FILE_NAME, tinker_format=True) reader.parse_packmol_input() system = reader.read_xyz_data() f_atom = model.Atom("F", model.Coordinates(1.714650, -1.415751, 0.421888), -0.13, 18.9984, "Ff") molecule = system.molecules[0][0] atoms = molecule.atoms self.assertIn(f_atom, atoms) self.assertEqual(system.xyz_file_name, "fsi-tinker/fsi-res.xyz") bonds = molecule.bonds self.assertIn((0, 3), bonds) self.assertIn((5, 8), bonds) angles = molecule.angles self.assertIn((4, 5, 6), angles) self.assertIn((1, 0, 4), angles) dihedrals = molecule.dihedrals self.assertIn((3, 0, 4, 5), dihedrals) self.assertIn((1, 0, 4, 5), dihedrals)
def test_determine_dihedrals(self): coordinatesO1 = model.Coordinates(0.0, 0.0, 0.0) coordinatesO2 = model.Coordinates(0.0, 0.0, 1.48) coordinatesH1 = model.Coordinates(0.895669, 0.0, -0.316667) coordinatesH2 = model.Coordinates(-0.895669, 0.0, 1.796667) atomO1 = model.Atom("O", coordinatesO1) atomO2 = model.Atom("O", coordinatesO2) atomH1 = model.Atom("H", coordinatesH1) atomH2 = model.Atom("H", coordinatesH2) molecule = model.Molecule([atomO1, atomO2, atomH1, atomH2], "MOL") molecule.determine_bonds(1.50) molecule.determine_angles() molecule.determine_dihedrals() dihedrals = molecule.dihedrals expected_dihedrals = ((2, 0, 1, 3),) self.assertEqual(dihedrals, expected_dihedrals)
def test_xyz_default_reader(self): reader = readingutils.InputReader(PACKMOL_FILE_NAME) reader.parse_packmol_input() system = reader.read_xyz_data() li_atom = model.Atom("Li", model.Coordinates(0.0, 0.0, 0.0), 1.00, 6.997, "kLi") molecule = model.Molecule([li_atom], "LI") molecules = system.molecules self.assertEqual(molecules[0][0], molecule) self.assertEqual(system.xyz_file_name, "li-ec/li-ec-01.xyz")
def __read_xyz_data_tinker(self): molecules = [] for (xyz_file_name, molecule_count) in self._xyz_data: xyz_file = open(xyz_file_name, 'r') atoms_number = int(xyz_file.readline().split()[0]) atoms = [] for xyz_line in xyz_file: xyz_line = xyz_line.split() if len(xyz_line) >= self.COORDINATE_LINE_COLUMNS_TINKER: atom_symbol = xyz_line[1] atom_coordinates = model.Coordinates( float(xyz_line[2]), float(xyz_line[3]), float(xyz_line[4])) atoms.append(model.Atom(atom_symbol, atom_coordinates)) xyz_file.close() if len(atoms) != atoms_number: print( '[WARNING] Difference between declared and read atoms number in file {}, declared: {}, read: {}' .format(xyz_file_name, atoms_number, len(atoms))) molecule = model.Molecule(atoms) self.__read_dat_data(xyz_file_name.replace('.xyz', '.dat'), molecule) if molecule.atoms_number > 1: self.__read_conn_data(xyz_file_name.replace('.xyz', '.conn'), molecule) molecules.append((molecule, molecule_count)) system = model.System(molecules, self._packmol_output_name) return system
def __read_xyz_data_default(self): molecules = [] for (xyz_file_name, molecule_count) in self._xyz_data: xyz_file = open(xyz_file_name, 'r') atoms_number = int(xyz_file.readline()) xyz_file.readline() # omit commentary line in XYZ file atoms = [] for xyz_line in xyz_file: xyz_line = xyz_line.split() if len(xyz_line) >= self.COORDINATE_LINE_COLUMNS: atom_symbol = xyz_line[0] atom_coordinates = model.Coordinates( float(xyz_line[1]), float(xyz_line[2]), float(xyz_line[3])) atoms.append(model.Atom(atom_symbol, atom_coordinates)) xyz_file.close() if len(atoms) != atoms_number: print( '[WARNING] Difference between declared and read atoms number in file {}, declared: {}, read: {}' .format(xyz_file_name, atoms_number, len(atoms))) molecule = model.Molecule(atoms) self.__read_dat_data(xyz_file_name.replace('.xyz', '.dat'), molecule) molecule.determine_angles() molecule.determine_dihedrals() molecules.append((molecule, molecule_count)) system = model.System(molecules, self._packmol_output_name) return system