def test_example08(self):
        nice_measures = [[1.976, 3.699], [6.955, 0.602]]
        molecules, options = classic_inputs.read_old_input(
            'data/shape/example08.dat')
        central_atom = options['%central_atom']
        reference_polyhedron = []
        if options['%labels'] != 0:
            for number in options['%labels']:
                if int(number) == 0:
                    for ref in file_io.get_geometry_from_file_ref(
                            'data/shape/example08.ref', read_multiple=True):
                        reference_polyhedron.append(ref)
                else:
                    reference_polyhedron.append(
                        shape.tools.get_shape_label(int(number),
                                                    options['%n_atoms']))

        results = [[
            shape.Shape(molecule).measure(reference_polyhedron[0],
                                          central_atom=central_atom)
            for molecule in molecules
        ],
                   [
                       shape.Shape(molecule).measure(reference_polyhedron[1],
                                                     central_atom=central_atom)
                       for molecule in molecules
                   ]]

        calculated_results = np.column_stack((results[0], results[1]))
        self.assertTrue(
            np.allclose(nice_measures, calculated_results, atol=1e-2))
    def test_example05(self):
        nice_gen_coord = [84., 84., 25.4, 79.1, 23.7, 25., 54.6]
        nice_measures = [[12.011, 0.954], [12.012, 0.957], [1.142, 11.245],
                         [10.707, 1.236], [0.993, 12.826], [1.105, 11.783],
                         [5.203, 5.085]]
        nice_dev_path = [7.2, 7.2, 6.5, 5.5, 10.6, 8.1, 8.6]
        nice_path_coordinates = np.array([[0., 16.737], [0.035, 15.355],
                                          [0.144, 14.002], [0.329, 12.681],
                                          [0.593, 11.398], [0.94, 10.158],
                                          [1.371, 8.966], [1.89, 7.828],
                                          [2.497, 6.748], [3.195, 5.732],
                                          [3.984, 4.785], [4.865, 3.911],
                                          [5.837, 3.116], [6.901, 2.403],
                                          [8.055, 1.777], [9.298, 1.241],
                                          [10.626, 0.798], [12.038, 0.45],
                                          [13.53, 0.201], [15.097, 0.05],
                                          [16.737, 0.]])

        molecules, options = classic_inputs.read_old_input(
            'data/shape/example05.dat')
        reference_polyhedron = []
        for number in options['%labels']:
            reference_polyhedron.append(
                shape.tools.get_shape_label(int(number), options['%n_atoms']))

        results = [[
            shape.Shape(molecule).measure(
                reference_polyhedron[0], central_atom=options['%central_atom'])
            for molecule in molecules
        ],
                   [
                       shape.Shape(molecule).measure(
                           reference_polyhedron[1],
                           central_atom=options['%central_atom'])
                       for molecule in molecules
                   ]]
        dev_path = [
            molecule.get_path_deviation(reference_polyhedron[0],
                                        reference_polyhedron[1],
                                        central_atom=options['%central_atom'])
            for molecule in molecules
        ]
        gen_coord = [
            molecule.get_generalized_coordinate(
                reference_polyhedron[0],
                reference_polyhedron[1],
                central_atom=options['%central_atom'])
            for molecule in molecules
        ]
        map = maps.get_shape_map(reference_polyhedron[0],
                                 reference_polyhedron[1],
                                 num_points=20)

        self.assertTrue(np.allclose(nice_gen_coord, gen_coord, atol=1e-1))
        calculated_results = np.column_stack((results[0], results[1]))
        self.assertTrue(
            np.allclose(nice_measures, calculated_results, atol=1e-1))
        self.assertTrue(np.allclose(nice_dev_path, dev_path, atol=1e-1))
        self.assertTrue(
            np.allclose(nice_path_coordinates.T, map[:2], atol=1e-1))
    def test_example02(self):
        nice_measures = [[5.271, 36.847], [5.184, 36.789], [5.047, 36.698],
                         [5.234, 36.822], [5.1, 36.733]]
        molecules, options = classic_inputs.read_old_input(
            'data/shape/example02.dat')
        reference_polyhedron = []
        for number in options['%labels']:
            reference_polyhedron.append(
                shape.tools.get_shape_label(int(number), options['%n_atoms']))

        results = [[
            shape.Shape(molecule).measure(reference_polyhedron[0],
                                          options['%central_atom'])
            for molecule in molecules
        ],
                   [
                       shape.Shape(molecule).measure(reference_polyhedron[1],
                                                     options['%central_atom'])
                       for molecule in molecules
                   ]]
        calculated_results = np.column_stack((results[0], results[1]))
        self.assertTrue(
            np.allclose(nice_measures, calculated_results, atol=1e-3))
    def test_example01(self):
        molecules, options = classic_inputs.read_old_input(
            'data/shape/example01.dat')
        reference_polyhedron = []
        for number in options['%labels']:
            reference_polyhedron.append(
                shape.tools.get_shape_label(int(number), options['%n_atoms']))

        results = [[
            shape.Shape(molecule).measure(
                reference_polyhedron[0], central_atom=options['%central_atom'])
            for molecule in molecules
        ],
                   [
                       shape.Shape(molecule).measure(
                           reference_polyhedron[1],
                           central_atom=options['%central_atom'])
                       for molecule in molecules
                   ]]
        calculated_results = np.column_stack((results[0], results[1]))
        nice_measures = [[31.375, 0.97], [33.44, 0.16]]
        self.assertTrue(
            np.allclose(nice_measures, calculated_results, atol=1e-3))
Пример #5
0
    def __init__(self,
                 positions,
                 symbols=(),
                 name='',
                 connectivity=None,
                 connectivity_thresh=1.2):

        # self._central_atom = None
        self._symbols = []
        self._positions = []
        self._atom_groups = list(symbols)
        self._name = name

        # TODO: This is a mess!
        for symbol in symbols:
            try:
                int(symbol)
                self._symbols.append(
                    tools.atomic_number_to_element(int(symbol)))
            except (ValueError, TypeError):
                self._symbols.append(symbol.capitalize())
                for ida, a in enumerate(symbol):
                    try:
                        int(a)
                        self._symbols[-1] = self._symbols[-1][:ida]
                        break
                    except (ValueError, TypeError, IndexError):
                        pass

        try:
            float(positions[0])
            for symbol in positions:
                self._positions.append(float(symbol))
            self._positions = list(chunks(self._positions, 3))
        except (ValueError, TypeError, IndexError):
            for symbol in positions:
                self._positions.append([float(j) for j in symbol])

        self._positions = np.array(self._positions)
        if connectivity is None:
            self._connectivity = generate_connectivity_from_geometry(
                self, thresh=connectivity_thresh)
        else:
            self._connectivity = connectivity

        self._shape = shape.Shape(self)
        self._symmetry = Symmetry(self)
Пример #6
0
    def execute(self):
        if self.filename is None:
            self.results.setPlainText('WARNING. No input file selected')
            self.results.repaint()
            # print('WARNING. No input file selected, choose one before running')
        else:
            # if self.directory is None:
            text = "SHAPE's measure " + self.label + "\n"
            for geometry in self.geometries:
                text += '{:10} {:10.3f}'.format(
                    geometry.name,
                    shape.Shape(geometry).measure(self.label,
                                                  self.central_atom)) + '\n'

            self.results.setPlainText(text)
            self.results.repaint()
            self.save_button.setEnabled(True)
Пример #7
0
fragments_list = file_io.get_geometry_from_file_cor(
    '../old_examples/coord.cor', read_multiple=True)

# Call shape as method of Geometry class
print_shape_data(geometries_list)
print_shape_data(fragments_list)

# Check multiple calls of shape one calculatioin
methane = geometries_list[0]
for i in range(100):
    measure = methane.get_shape_measure('SP-4', central_atom=1)

print('final measure: {}'.format(measure))

# Call shape as method of Shape class (semi function call)
print('measure:', shape.Shape(methane).measure('SP-4', central_atom=1))
print('structure:\n', shape.Shape(methane).structure('SP-4', central_atom=1))

# test symgroup
print('\nSYMMETRY' '\n--------')

geometries_list = file_io.get_geometry_from_file_pdb(
    '../old_examples/methane.pdb', read_multiple=True)
print('measure C3: {} '.format(geometries_list[0].get_symmetry_measure('c3')))

# Check multiple calls of symgroup one calculatioin
for i in range(100):
    measure = methane.get_symmetry_measure('C3', central_atom=1)

print('measure: {:^10.3f} '.format(measure))
print('measure: {:^10.3f} '.format(
 def test_example04(self):
     nice_measures = [[31.375, 0.97], [33.44, 0.16]]
     nice_structures = [[2.63702000e+00, 9.00254000e+00, 1.50230800e+01],
                        [4.04611899e+00, 8.76816018e+00, 1.39529277e+01],
                        [2.90730181e+00, 8.13748396e+00, 1.65607229e+01],
                        [1.17328859e+00, 8.36062228e+00, 1.42286293e+01],
                        [2.42137060e+00, 1.07438936e+01, 1.53500401e+01],
                        [-3.47837193e-17, -9.20929468e-18, 2.51183874e-17],
                        [3.77908106e-01, 9.50150647e-01, -8.46343078e-01],
                        [-3.77908106e-01, -9.50150647e-01, 8.46343078e-01],
                        [-1.14966271e+00, 6.33326997e-01, 1.97661211e-01],
                        [1.14966271e+00, -6.33326997e-01, -1.97661211e-01],
                        [2.63702000e+00, 9.00254000e+00, 1.50230800e+01],
                        [3.76728743e+00, 7.46687014e+00, 1.40425715e+01],
                        [4.02414490e+00, 8.97967996e+00, 1.66578721e+01],
                        [1.24989510e+00, 9.02540004e+00, 1.33882879e+01],
                        [1.50675257e+00, 1.05382099e+01, 1.60035885e+01],
                        [9.74091060e-17, 1.01739088e-17, -5.98080786e-17],
                        [5.66862241e-01, 1.42522607e+00, -1.26951447e+00],
                        [-5.66862241e-01, -1.42522607e+00, 1.26951447e+00],
                        [-1.72449417e+00, 9.49990377e-01, 2.96491640e-01],
                        [1.72449417e+00, -9.49990377e-01, -2.96491640e-01]]
     molecules, options = classic_inputs.read_old_input(
         'data/shape/example04.dat')
     reference_polyhedron = []
     for number in options['%labels']:
         reference_polyhedron.append(
             shape.tools.get_shape_label(int(number), options['%n_atoms']))
     results = [[
         shape.Shape(molecule).structure(
             reference_polyhedron[0], central_atom=options['%central_atom'])
         for molecule in molecules
     ]]
     calculated_results = np.concatenate((results[0][0], results[0][1]))
     results.append([
         shape.Shape(molecule).structure(
             reference_polyhedron[1], central_atom=options['%central_atom'])
         for molecule in molecules
     ])
     calculated_results = np.concatenate(
         (calculated_results, np.concatenate(
             (results[1][0], results[1][1]))))
     results = []
     results.append([
         shape.Shape(molecule).measure(
             reference_polyhedron[0], central_atom=options['%central_atom'])
         for molecule in molecules
     ])
     results.append([
         shape.Shape(molecule).measure(
             reference_polyhedron[1], central_atom=options['%central_atom'])
         for molecule in molecules
     ])
     calculated_results = [
         calculated_results,
         np.column_stack((results[0], results[1]))
     ]
     self.assertTrue(
         np.allclose(nice_structures, calculated_results[0], atol=1e-3))
     self.assertTrue(
         np.allclose(nice_measures, calculated_results[1], atol=1e-3))