예제 #1
0
 def value_for_coords_and_displacements(self, pairs, internal_coord, cart_coords):
     cart_coords = tuple(cart_coords)
     disps = [0] * (len(internal_coord.atoms) * 3)
     for coord, ndeltas in pairs:
         idx = internal_coord.internal_indices_for_coordinates(coord)[0]
         disps[idx] = ndeltas
     coord_idxs = internal_coord.internal_indices_for_coordinates(*cart_coords)
     dispcoord = self.coordinate_with_cartesian_displacements(internal_coord, disps)
     if len(cart_coords) == 0:
         # For some reason, BondAngle thinks it's a subclass of PeriodicCoordinate (!?)
         if hasattr(dispcoord, 'possible_values_for_xyz'):
             baseval = internal_coord.value_for_xyz(
                 Matrix([a.pos for a in internal_coord.atoms])
             )
             pos_vals = dispcoord.possible_values_for_xyz(
                 Matrix([a.pos for a in dispcoord.atoms])
             )
             # Including the half-periods makes this work...
             # TODO fix and/or justify this
             val = min(*(pos_vals + tuple(p+math.pi for p in pos_vals)), key=lambda p: abs(p - baseval))
             # No need to convert angular units, since value_for_xyz always returns Radians
             return val
         else:
             val = dispcoord.value
             if hasunits(internal_coord) and internal_coord.units.genre is AngularUnit:
                 val *= dispcoord.units.to(Radians)
             return val
     else:
         B = dispcoord.get_b_tensor(max_order=len(cart_coords))
         return B[tuple(coord_idxs)]
예제 #2
0
파일: atom.py 프로젝트: SahanGH/psi4public
 def __init__(self, symbol, position, **kwargs):
     self._init_common(**kwargs)
     self.symbol = symbol
     if hasunits(position):
         if 'units' not in kwargs:
             self._cartesian_units = position.units
         elif self._cartesian_units != kwargs['units']:
             position = position.in_units(self._cartesian_units)
     self.position = Vector(position, copy=True, units=self.cartesian_units)
예제 #3
0
 def __init__(self, symbol, position, **kwargs):
     self._init_common(**kwargs)
     self.symbol = symbol
     if hasunits(position):
         if 'units' not in kwargs:
             self._cartesian_units = position.units
         elif self._cartesian_units != kwargs['units']:
             position = position.in_units(self._cartesian_units)
     self.position = Vector(position, copy=True, units=self.cartesian_units)
예제 #4
0
 def __init__(self, molecule, coords=None, units=None):
     self._b_tensor_for_cart_rep = {}
     self.molecule = molecule
     self._init_units(units)
     self.coords = []
     for i, coord in enumerate(coords or []):
         cunits=self.units[coord.default_delta.units.genre] if hasunits(coord.default_delta) else None
         new_coord = coord.copy_for_representation(self, index=i, units=cunits)
         self.coords.append(new_coord)
     self.molecule.internal_representations.append(self)
예제 #5
0
 def __init__(self, molecule, coords=None, units=None):
     self._b_tensor_for_cart_rep = {}
     self.molecule = molecule
     self._init_units(units)
     self.coords = []
     for i, coord in enumerate(coords or []):
         cunits = self.units[coord.default_delta.units.genre] if hasunits(
             coord.default_delta) else None
         new_coord = coord.copy_for_representation(self,
                                                   index=i,
                                                   units=cunits)
         self.coords.append(new_coord)
     self.molecule.internal_representations.append(self)
예제 #6
0
 def __str__(self):
     namestrs = []
     valstrs = []
     it = np.nditer(self, flags=['multi_index'])
     for x in it:
         namestrs.append(", ".join(shortstr(self.representation[i]) for i in it.multi_index))
         valstrs.append("{: .8f}{}".format(float(x), (" " + str(self.units) if hasunits(self) else '')))
     width=max(len(s) for s in namestrs) + 4
     ret_val = self.__class__.__name__ + ":\n"
     for name, val in zip(namestrs, valstrs):
         ret_val += ("{:>"+str(width)+"}: {}\n").format(name, val)
     ret_val += "  for representation:\n{}".format(indent(str(self.representation)))
     return ret_val
예제 #7
0
 def __str__(self):
     namestrs = []
     valstrs = []
     it = np.nditer(self, flags=['multi_index'])
     for x in it:
         namestrs.append(", ".join(
             shortstr(self.representation[i]) for i in it.multi_index))
         valstrs.append("{: .8f}{}".format(
             float(x), (" " + str(self.units) if hasunits(self) else '')))
     width = max(len(s) for s in namestrs) + 4
     ret_val = self.__class__.__name__ + ":\n"
     for name, val in zip(namestrs, valstrs):
         ret_val += ("{:>" + str(width) + "}: {}\n").format(name, val)
     ret_val += "  for representation:\n{}".format(
         indent(str(self.representation)))
     return ret_val
예제 #8
0
 def value(self, new_val):
     if hasunits(new_val):
         self._value = new_val.in_units(self.units).value
     else:
         self._value = new_val
예제 #9
0
 def value(self, new_val):
     if hasunits(new_val):
         self._value = new_val.in_units(self.units).value
     else:
         self._value = new_val