sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
def _get_extra(self, attrs, exclude): """Read the extra properties, taking into account an exclude list""" result = {} for key in attrs.getNames(): if key not in exclude: result[str(key)] = str(attrs[key]) return result
Read the extra properties, taking into account an exclude list
entailment
def _read(self, filename, field_labels=None): """Read all the requested fields Arguments: | ``filename`` -- the filename of the FCHK file | ``field_labels`` -- when given, only these fields are read """ # if fields is None, all fields are read def ...
Read all the requested fields Arguments: | ``filename`` -- the filename of the FCHK file | ``field_labels`` -- when given, only these fields are read
entailment
def _analyze(self): """Convert a few elementary fields into a molecule object""" if ("Atomic numbers" in self.fields) and ("Current cartesian coordinates" in self.fields): self.molecule = Molecule( self.fields["Atomic numbers"], np.reshape(self.fields["Current...
Convert a few elementary fields into a molecule object
entailment
def get_optimization_coordinates(self): """Return the coordinates of the geometries at each point in the optimization""" coor_array = self.fields.get("Opt point 1 Geometries") if coor_array is None: return [] else: return np.reshape(coor_array, (-1, len(self...
Return the coordinates of the geometries at each point in the optimization
entailment
def get_optimized_molecule(self): """Return a molecule object of the optimal geometry""" opt_coor = self.get_optimization_coordinates() if len(opt_coor) == 0: return None else: return Molecule( self.molecule.numbers, opt_coor[-1], ...
Return a molecule object of the optimal geometry
entailment
def get_optimization_gradients(self): """Return the energy gradients of all geometries during an optimization""" grad_array = self.fields.get("Opt point 1 Gradient at each geome") if grad_array is None: return [] else: return np.reshape(grad_array, (-1, len(...
Return the energy gradients of all geometries during an optimization
entailment
def get_hessian(self): """Return the hessian""" force_const = self.fields.get("Cartesian Force Constants") if force_const is None: return None N = len(self.molecule.numbers) result = np.zeros((3*N, 3*N), float) counter = 0 for row in range(3*N): ...
Return the hessian
entailment
def copy_with(self, **kwargs): """Return a copy with (a few) changed attributes The keyword arguments are the attributes to be replaced by new values. All other attributes are copied (or referenced) from the original object. This only works if the constructor takes all ...
Return a copy with (a few) changed attributes The keyword arguments are the attributes to be replaced by new values. All other attributes are copied (or referenced) from the original object. This only works if the constructor takes all (read-only) attributes as arguments.
entailment
def _read(self, filename): """Internal routine that reads all data from the punch file.""" data = {} parsers = [ FirstDataParser(), CoordinateParser(), EnergyGradParser(), SkipApproxHessian(), HessianParser(), MassParser(), ] with open(filename) as f: ...
Internal routine that reads all data from the punch file.
entailment
def read(self, line, f, data): """See :meth:`PunchParser.read`""" self.used = True data["title"] = f.readline().strip() data["symmetry"] = f.readline().split()[0] if data["symmetry"] != "C1": raise NotImplementedError("Only C1 symmetry is supported.") symbols ...
See :meth:`PunchParser.read`
entailment
def read(self, line, f, data): """See :meth:`PunchParser.read`""" f.readline() f.readline() N = len(data["symbols"]) # if the data are already read before, just overwrite them numbers = data.get("numbers") if numbers is None: numbers = np.zeros(N, int)...
See :meth:`PunchParser.read`
entailment
def read(self, line, f, data): """See :meth:`PunchParser.read`""" data["energy"] = float(f.readline().split()[1]) N = len(data["symbols"]) # if the data are already read before, just overwrite them gradient = data.get("gradient") if gradient is None: gradient ...
See :meth:`PunchParser.read`
entailment
def read(self, line, f, data): """See :meth:`PunchParser.read`""" line = f.readline() assert(line == " $HESS\n") while line != " $END\n": line = f.readline()
See :meth:`PunchParser.read`
entailment
def read(self, line, f, data): """See :meth:`PunchParser.read`""" assert("hessian" not in data) f.readline() N = len(data["symbols"]) hessian = np.zeros((3*N, 3*N), float) tmp = hessian.ravel() counter = 0 while True: line = f.readline() ...
See :meth:`PunchParser.read`
entailment
def read(self, line, f, data): """See :meth:`PunchParser.read`""" N = len(data["symbols"]) masses = np.zeros(N, float) counter = 0 while counter < N: words = f.readline().split() for word in words: masses[counter] = float(word)*amu ...
See :meth:`PunchParser.read`
entailment
def setup_hydrocarbon_ff(graph): """Create a simple ForceField object for hydrocarbons based on the graph.""" # A) Define parameters. # the bond parameters: bond_params = { (6, 1): 310*kcalmol/angstrom**2, (6, 6): 220*kcalmol/angstrom**2, } # for every (a, b), also add (b, a) ...
Create a simple ForceField object for hydrocarbons based on the graph.
entailment
def add_to_hessian(self, coordinates, hessian): """Add the contributions of this energy term to the Hessian Arguments: | ``coordinates`` -- A numpy array with 3N Cartesian coordinates. | ``hessian`` -- A matrix for the full Hessian to which this energy ...
Add the contributions of this energy term to the Hessian Arguments: | ``coordinates`` -- A numpy array with 3N Cartesian coordinates. | ``hessian`` -- A matrix for the full Hessian to which this energy term has to add its contribution.
entailment
def hessian(self, coordinates): """Compute the force-field Hessian for the given coordinates. Argument: | ``coordinates`` -- A numpy array with the Cartesian atom coordinates, with shape (N,3). Returns: | ``hessian`` -- A numpy arr...
Compute the force-field Hessian for the given coordinates. Argument: | ``coordinates`` -- A numpy array with the Cartesian atom coordinates, with shape (N,3). Returns: | ``hessian`` -- A numpy array with the Hessian, with shape (3*N, ...
entailment
def compute_rotsym(molecule, graph, threshold=1e-3*angstrom): """Compute the rotational symmetry number Arguments: | ``molecule`` -- The molecule | ``graph`` -- The corresponding bond graph Optional argument: | ``threshold`` -- only when a rotation results in an rmsd be...
Compute the rotational symmetry number Arguments: | ``molecule`` -- The molecule | ``graph`` -- The corresponding bond graph Optional argument: | ``threshold`` -- only when a rotation results in an rmsd below the given threshold, the rotation is...
entailment
def quaternion_product(quat1, quat2): """Return the quaternion product of the two arguments""" return np.array([ quat1[0]*quat2[0] - np.dot(quat1[1:], quat2[1:]), quat1[0]*quat2[1] + quat2[0]*quat1[1] + quat1[2]*quat2[3] - quat1[3]*quat2[2], quat1[0]*quat2[2] + quat2[0]*quat1[2] + quat1[...
Return the quaternion product of the two arguments
entailment
def quaternion_rotation(quat, vector): """Apply the rotation represented by the quaternion to the vector Warning: This only works correctly for normalized quaternions. """ dp = np.dot(quat[1:], vector) cos = (2*quat[0]*quat[0] - 1) return np.array([ 2 * (quat[0] * (quat[2] * vector[2...
Apply the rotation represented by the quaternion to the vector Warning: This only works correctly for normalized quaternions.
entailment
def rotation_matrix_to_quaternion(rotation_matrix): """Compute the quaternion representing the rotation given by the matrix""" invert = (np.linalg.det(rotation_matrix) < 0) if invert: factor = -1 else: factor = 1 c2 = 0.25*(factor*np.trace(rotation_matrix) + 1) if c2 < 0: ...
Compute the quaternion representing the rotation given by the matrix
entailment
def quaternion_to_rotation_matrix(quaternion): """Compute the rotation matrix representated by the quaternion""" c, x, y, z = quaternion return np.array([ [c*c + x*x - y*y - z*z, 2*x*y - 2*c*z, 2*x*z + 2*c*y ], [2*x*y + 2*c*z, c*c - x*x + y*y - z*z, 2*y*z - 2*c*x ...
Compute the rotation matrix representated by the quaternion
entailment
def cosine(a, b): """Compute the cosine between two vectors The result is clipped within the range [-1, 1] """ result = np.dot(a, b) / np.linalg.norm(a) / np.linalg.norm(b) return np.clip(result, -1, 1)
Compute the cosine between two vectors The result is clipped within the range [-1, 1]
entailment
def random_unit(size=3): """Return a random unit vector of the given dimension Optional argument: size -- the number of dimensions of the unit vector [default=3] """ while True: result = np.random.normal(0, 1, size) length = np.linalg.norm(result) if length > 1e-3:...
Return a random unit vector of the given dimension Optional argument: size -- the number of dimensions of the unit vector [default=3]
entailment
def random_orthonormal(normal): """Return a random normalized vector orthogonal to the given vector""" u = normal_fns[np.argmin(np.fabs(normal))](normal) u /= np.linalg.norm(u) v = np.cross(normal, u) v /= np.linalg.norm(v) alpha = np.random.uniform(0.0, np.pi*2) return np.cos(alpha)*u + np....
Return a random normalized vector orthogonal to the given vector
entailment
def triangle_normal(a, b, c): """Return a vector orthogonal to the given triangle Arguments: a, b, c -- three 3D numpy vectors """ normal = np.cross(a - c, b - c) norm = np.linalg.norm(normal) return normal/norm
Return a vector orthogonal to the given triangle Arguments: a, b, c -- three 3D numpy vectors
entailment
def dot(r1, r2): """Compute the dot product Arguments: | ``r1``, ``r2`` -- two :class:`Vector3` objects (Returns a Scalar) """ if r1.size != r2.size: raise ValueError("Both arguments must have the same input size.") if r1.deriv != r2.deriv: raise ValueError("Both...
Compute the dot product Arguments: | ``r1``, ``r2`` -- two :class:`Vector3` objects (Returns a Scalar)
entailment
def cross(r1, r2): """Compute the cross product Arguments: | ``r1``, ``r2`` -- two :class:`Vector3` objects (Returns a Vector3) """ if r1.size != r2.size: raise ValueError("Both arguments must have the same input size.") if r1.deriv != r2.deriv: raise ValueError(...
Compute the cross product Arguments: | ``r1``, ``r2`` -- two :class:`Vector3` objects (Returns a Vector3)
entailment
def _opbend_transform_mean(rs, fn_low, deriv=0): """Compute the mean of the 3 opbends """ v = 0.0 d = np.zeros((4,3), float) dd = np.zeros((4,3,4,3), float) #loop over the 3 cyclic permutations for p in np.array([[0,1,2], [2,0,1], [1,2,0]]): opbend = _opbend_transform([rs[p[0]], rs[p...
Compute the mean of the 3 opbends
entailment
def _bond_length_low(r, deriv): """Similar to bond_length, but with a relative vector""" r = Vector3(3, deriv, r, (0, 1, 2)) d = r.norm() return d.results()
Similar to bond_length, but with a relative vector
entailment
def _bend_cos_low(a, b, deriv): """Similar to bend_cos, but with relative vectors""" a = Vector3(6, deriv, a, (0, 1, 2)) b = Vector3(6, deriv, b, (3, 4, 5)) a /= a.norm() b /= b.norm() return dot(a, b).results()
Similar to bend_cos, but with relative vectors
entailment
def _bend_angle_low(a, b, deriv): """Similar to bend_angle, but with relative vectors""" result = _bend_cos_low(a, b, deriv) return _cos_to_angle(result, deriv)
Similar to bend_angle, but with relative vectors
entailment
def _dihed_cos_low(a, b, c, deriv): """Similar to dihed_cos, but with relative vectors""" a = Vector3(9, deriv, a, (0, 1, 2)) b = Vector3(9, deriv, b, (3, 4, 5)) c = Vector3(9, deriv, c, (6, 7, 8)) b /= b.norm() tmp = b.copy() tmp *= dot(a, b) a -= tmp tmp = b.copy() tmp *= dot(c...
Similar to dihed_cos, but with relative vectors
entailment
def _dihed_angle_low(av, bv, cv, deriv): """Similar to dihed_cos, but with relative vectors""" a = Vector3(9, deriv, av, (0, 1, 2)) b = Vector3(9, deriv, bv, (3, 4, 5)) c = Vector3(9, deriv, cv, (6, 7, 8)) b /= b.norm() tmp = b.copy() tmp *= dot(a, b) a -= tmp tmp = b.copy() tmp ...
Similar to dihed_cos, but with relative vectors
entailment
def _opdist_low(av, bv, cv, deriv): """Similar to opdist, but with relative vectors""" a = Vector3(9, deriv, av, (0, 1, 2)) b = Vector3(9, deriv, bv, (3, 4, 5)) c = Vector3(9, deriv, cv, (6, 7, 8)) n = cross(a, b) n /= n.norm() dist = dot(c, n) return dist.results()
Similar to opdist, but with relative vectors
entailment
def _opbend_cos_low(a, b, c, deriv): """Similar to opbend_cos, but with relative vectors""" a = Vector3(9, deriv, a, (0, 1, 2)) b = Vector3(9, deriv, b, (3, 4, 5)) c = Vector3(9, deriv, c, (6, 7, 8)) n = cross(a,b) n /= n.norm() c /= c.norm() temp = dot(n,c) result = temp.copy() ...
Similar to opbend_cos, but with relative vectors
entailment
def _opbend_angle_low(a, b, c, deriv=0): """Similar to opbend_angle, but with relative vectors""" result = _opbend_cos_low(a, b, c, deriv) sign = np.sign(np.linalg.det([a, b, c])) return _cos_to_angle(result, deriv, sign)
Similar to opbend_angle, but with relative vectors
entailment
def _cos_to_angle(result, deriv, sign=1): """Convert a cosine and its derivatives to an angle and its derivatives""" v = np.arccos(np.clip(result[0], -1, 1)) if deriv == 0: return v*sign, if abs(result[0]) >= 1: factor1 = 0 else: factor1 = -1.0/np.sqrt(1-result[0]**2) d =...
Convert a cosine and its derivatives to an angle and its derivatives
entailment
def _sin_to_angle(result, deriv, side=1): """Convert a sine and its derivatives to an angle and its derivatives""" v = np.arcsin(np.clip(result[0], -1, 1)) sign = side if sign == -1: if v < 0: offset = -np.pi else: offset = np.pi else: offset = 0.0 ...
Convert a sine and its derivatives to an angle and its derivatives
entailment
def copy(self): """Return a deep copy""" result = Scalar(self.size, self.deriv) result.v = self.v if self.deriv > 0: result.d[:] = self.d[:] if self.deriv > 1: result.dd[:] = self.dd[:] return result
Return a deep copy
entailment
def results(self): """Return the value and optionally derivative and second order derivative""" if self.deriv == 0: return self.v, if self.deriv == 1: return self.v, self.d if self.deriv == 2: return self.v, self.d, self.dd
Return the value and optionally derivative and second order derivative
entailment
def inv(self): """In place invert""" self.v = 1/self.v tmp = self.v**2 if self.deriv > 1: self.dd[:] = tmp*(2*self.v*np.outer(self.d, self.d) - self.dd) if self.deriv > 0: self.d[:] = -tmp*self.d[:]
In place invert
entailment
def copy(self): """Return a deep copy""" result = Vector3(self.size, self.deriv) result.x.v = self.x.v result.y.v = self.y.v result.z.v = self.z.v if self.deriv > 0: result.x.d[:] = self.x.d result.y.d[:] = self.y.d result.z.d[:] = self...
Return a deep copy
entailment
def norm(self): """Return a Scalar object with the norm of this vector""" result = Scalar(self.size, self.deriv) result.v = np.sqrt(self.x.v**2 + self.y.v**2 + self.z.v**2) if self.deriv > 0: result.d += self.x.v*self.x.d result.d += self.y.v*self.y.d ...
Return a Scalar object with the norm of this vector
entailment
def _get_line(self): """Get a line or raise StopIteration""" line = self._f.readline() if len(line) == 0: raise StopIteration return line
Get a line or raise StopIteration
entailment
def _read_frame(self): """Read one frame""" # Read the first line, ignore the title and try to get the time. The # time field is optional. line = self._get_line() pos = line.rfind("t=") if pos >= 0: time = float(line[pos+2:])*picosecond else: ...
Read one frame
entailment
def _skip_frame(self): """Skip one frame""" self._get_line() num_atoms = int(self._get_line()) if self.num_atoms is not None and self.num_atoms != num_atoms: raise ValueError("The number of atoms must be the same over the entire file.") for i in range(num_atoms+1): ...
Skip one frame
entailment
def setup_ics(graph): """Make a list of internal coordinates based on the graph Argument: | ``graph`` -- A Graph instance. The list of internal coordinates will include all bond lengths, all bending angles, and all dihedral angles. """ ics = [] # A) Collect all bonds. ...
Make a list of internal coordinates based on the graph Argument: | ``graph`` -- A Graph instance. The list of internal coordinates will include all bond lengths, all bending angles, and all dihedral angles.
entailment
def compute_jacobian(ics, coordinates): """Construct a Jacobian for the given internal and Cartesian coordinates Arguments: | ``ics`` -- A list of internal coordinate objects. | ``coordinates`` -- A numpy array with Cartesian coordinates, shape=(N,3) The ...
Construct a Jacobian for the given internal and Cartesian coordinates Arguments: | ``ics`` -- A list of internal coordinate objects. | ``coordinates`` -- A numpy array with Cartesian coordinates, shape=(N,3) The return value will be a numpy array with the Jac...
entailment
def fill_jacobian_column(self, jaccol, coordinates): """Fill in a column of the Jacobian. Arguments: | ``jaccol`` -- The column of Jacobian to which the result must be added. | ``coordinates`` -- A numpy array with Cartesian coordinates, ...
Fill in a column of the Jacobian. Arguments: | ``jaccol`` -- The column of Jacobian to which the result must be added. | ``coordinates`` -- A numpy array with Cartesian coordinates, shape=(N,3)
entailment
def compute_similarity(a, b, margin=1.0, cutoff=10.0): """Compute the similarity between two molecules based on their descriptors Arguments: a -- the similarity measure of the first molecule b -- the similarity measure of the second molecule margin -- the sensitivity when co...
Compute the similarity between two molecules based on their descriptors Arguments: a -- the similarity measure of the first molecule b -- the similarity measure of the second molecule margin -- the sensitivity when comparing distances (default = 1.0) cutoff -- don't c...
entailment
def from_molecule(cls, molecule, labels=None): """Initialize a similarity descriptor Arguments: molecule -- a Molecules object labels -- a list with integer labels used to identify atoms of the same type. When not given, the atom numbers from ...
Initialize a similarity descriptor Arguments: molecule -- a Molecules object labels -- a list with integer labels used to identify atoms of the same type. When not given, the atom numbers from the molecule are used.
entailment
def from_molecular_graph(cls, molecular_graph, labels=None): """Initialize a similarity descriptor Arguments: molecular_graphs -- A MolecularGraphs object labels -- a list with integer labels used to identify atoms of the same type. When not giv...
Initialize a similarity descriptor Arguments: molecular_graphs -- A MolecularGraphs object labels -- a list with integer labels used to identify atoms of the same type. When not given, the atom numbers from the molecular graph a...
entailment
def from_coordinates(cls, coordinates, labels): """Initialize a similarity descriptor Arguments: coordinates -- a Nx3 numpy array labels -- a list with integer labels used to identify atoms of the same type """ from molmod.ext im...
Initialize a similarity descriptor Arguments: coordinates -- a Nx3 numpy array labels -- a list with integer labels used to identify atoms of the same type
entailment
def load_chk(filename): '''Load a checkpoint file Argument: | filename -- the file to load from The return value is a dictionary whose keys are field labels and the values can be None, string, integer, float, boolean or an array of strings, integers, booleans or floats. ...
Load a checkpoint file Argument: | filename -- the file to load from The return value is a dictionary whose keys are field labels and the values can be None, string, integer, float, boolean or an array of strings, integers, booleans or floats. The file format is similar t...
entailment
def dump_chk(filename, data): '''Dump a checkpoint file Argument: | filename -- the file to write to | data -- a dictionary whose keys are field labels and the values can be None, string, integer, float, boolean, an array/list of strings, integers, fl...
Dump a checkpoint file Argument: | filename -- the file to write to | data -- a dictionary whose keys are field labels and the values can be None, string, integer, float, boolean, an array/list of strings, integers, floats or booleans. The file fo...
entailment
def clear(self): """Clear the contents of the data structure""" self.title = None self.numbers = np.zeros(0, int) self.atom_types = [] # the atom_types in the second column, used to associate ff parameters self.charges = [] # ff charges self.names = [] # a name that is un...
Clear the contents of the data structure
entailment
def read_from_file(self, filename): """Load a PSF file""" self.clear() with open(filename) as f: # A) check the first line line = next(f) if not line.startswith("PSF"): raise FileFormatError("Error while reading: A PSF file must start with a li...
Load a PSF file
entailment
def _get_name(self, graph, group=None): """Convert a molecular graph into a unique name This method is not sensitive to the order of the atoms in the graph. """ if group is not None: graph = graph.get_subgraph(group, normalize=True) fingerprint = graph.fingerprin...
Convert a molecular graph into a unique name This method is not sensitive to the order of the atoms in the graph.
entailment
def dump(self, f): """Dump the data structure to a file-like object""" # header print("PSF", file=f) print(file=f) # title print(" 1 !NTITLE", file=f) print(self.title, file=f) print(file=f) # atoms print("% 7i !NATOM" % len(self.num...
Dump the data structure to a file-like object
entailment
def add_molecule(self, molecule, atom_types=None, charges=None, split=True): """Add the graph of the molecule to the data structure The molecular graph is estimated from the molecular geometry based on interatomic distances. Argument: | ``molecule`` -- a Molecule...
Add the graph of the molecule to the data structure The molecular graph is estimated from the molecular geometry based on interatomic distances. Argument: | ``molecule`` -- a Molecule instance Optional arguments: | ``atom_types`` -- a list with ...
entailment
def add_molecular_graph(self, molecular_graph, atom_types=None, charges=None, split=True, molecule=None): """Add the molecular graph to the data structure Argument: | ``molecular_graph`` -- a MolecularGraph instance Optional arguments: | ``atom_types`` -- a li...
Add the molecular graph to the data structure Argument: | ``molecular_graph`` -- a MolecularGraph instance Optional arguments: | ``atom_types`` -- a list with atom type strings | ``charges`` -- The net atom charges | ``split`` -- When True,...
entailment
def get_groups(self): """Return a list of groups of atom indexes Each atom in a group belongs to the same molecule or residue. """ groups = [] for a_index, m_index in enumerate(self.molecules): if m_index >= len(groups): groups.append([a_index]) ...
Return a list of groups of atom indexes Each atom in a group belongs to the same molecule or residue.
entailment
def iter_halfs_bond(graph): """Select a random bond (pair of atoms) that divides the molecule in two""" for atom1, atom2 in graph.edges: try: affected_atoms1, affected_atoms2 = graph.get_halfs(atom1, atom2) yield affected_atoms1, affected_atoms2, (atom1, atom2) except Gra...
Select a random bond (pair of atoms) that divides the molecule in two
entailment
def iter_halfs_bend(graph): """Select randomly two consecutive bonds that divide the molecule in two""" for atom2 in range(graph.num_vertices): neighbors = list(graph.neighbors[atom2]) for index1, atom1 in enumerate(neighbors): for atom3 in neighbors[index1+1:]: try: ...
Select randomly two consecutive bonds that divide the molecule in two
entailment
def iter_halfs_double(graph): """Select two random non-consecutive bonds that divide the molecule in two""" edges = graph.edges for index1, (atom_a1, atom_b1) in enumerate(edges): for atom_a2, atom_b2 in edges[:index1]: try: affected_atoms1, affected_atoms2, hinge_atoms =...
Select two random non-consecutive bonds that divide the molecule in two
entailment
def generate_manipulations( molecule, bond_stretch_factor=0.15, torsion_amplitude=np.pi, bending_amplitude=0.30 ): """Generate a (complete) set of manipulations The result can be used as input for the functions 'randomize_molecule' and 'single_random_manipulation' Arguments: ...
Generate a (complete) set of manipulations The result can be used as input for the functions 'randomize_molecule' and 'single_random_manipulation' Arguments: molecule -- a reference geometry of the molecule, with graph attribute bond_stretch_factor -- ...
entailment
def check_nonbond(molecule, thresholds): """Check whether all nonbonded atoms are well separated. If a nonbond atom pair is found that has an interatomic distance below the given thresholds. The thresholds dictionary has the following format: {frozenset([atom_number1, atom_number2]): distance}...
Check whether all nonbonded atoms are well separated. If a nonbond atom pair is found that has an interatomic distance below the given thresholds. The thresholds dictionary has the following format: {frozenset([atom_number1, atom_number2]): distance} When random geometries are generated fo...
entailment
def randomize_molecule(molecule, manipulations, nonbond_thresholds, max_tries=1000): """Return a randomized copy of the molecule. If no randomized molecule can be generated that survives the nonbond check after max_tries repetitions, None is returned. In case of success, the randomized molecul...
Return a randomized copy of the molecule. If no randomized molecule can be generated that survives the nonbond check after max_tries repetitions, None is returned. In case of success, the randomized molecule is returned. The original molecule is not altered.
entailment
def randomize_molecule_low(molecule, manipulations): """Return a randomized copy of the molecule, without the nonbond check.""" manipulations = copy.copy(manipulations) shuffle(manipulations) coordinates = molecule.coordinates.copy() for manipulation in manipulations: manipulation.apply(coo...
Return a randomized copy of the molecule, without the nonbond check.
entailment
def single_random_manipulation(molecule, manipulations, nonbond_thresholds, max_tries=1000): """Apply a single random manipulation. If no randomized molecule can be generated that survives the nonbond check after max_tries repetitions, None is returned. In case of success, the randomized molec...
Apply a single random manipulation. If no randomized molecule can be generated that survives the nonbond check after max_tries repetitions, None is returned. In case of success, the randomized molecule and the corresponding transformation is returned. The original molecule is not altered.
entailment
def single_random_manipulation_low(molecule, manipulations): """Return a randomized copy of the molecule, without the nonbond check.""" manipulation = sample(manipulations, 1)[0] coordinates = molecule.coordinates.copy() transformation = manipulation.apply(coordinates) return molecule.copy_with(coo...
Return a randomized copy of the molecule, without the nonbond check.
entailment
def random_dimer(molecule0, molecule1, thresholds, shoot_max): """Create a random dimer. molecule0 and molecule1 are placed in one reference frame at random relative positions. Interatomic distances are above the thresholds. Initially a dimer is created where one interatomic distance approxima...
Create a random dimer. molecule0 and molecule1 are placed in one reference frame at random relative positions. Interatomic distances are above the thresholds. Initially a dimer is created where one interatomic distance approximates the threshold value. Then the molecules are given an additi...
entailment
def read_from_file(cls, filename): """Construct a MolecularDistortion object from a file""" with open(filename) as f: lines = list(line for line in f if line[0] != '#') r = [] t = [] for line in lines[:3]: values = list(float(word) for word in line.split()...
Construct a MolecularDistortion object from a file
entailment
def apply(self, coordinates): """Apply this distortion to Cartesian coordinates""" for i in self.affected_atoms: coordinates[i] = self.transformation*coordinates[i]
Apply this distortion to Cartesian coordinates
entailment
def write_to_file(self, filename): """Write the object to a file""" r = self.transformation.r t = self.transformation.t with open(filename, "w") as f: print("# A (random) transformation of a part of a molecule:", file=f) print("# The translation vector is in atomi...
Write the object to a file
entailment
def apply(self, coordinates): """Generate, apply and return a random manipulation""" transform = self.get_transformation(coordinates) result = MolecularDistortion(self.affected_atoms, transform) result.apply(coordinates) return result
Generate, apply and return a random manipulation
entailment
def get_transformation(self, coordinates): """Construct a transformation object""" atom1, atom2 = self.hinge_atoms direction = coordinates[atom1] - coordinates[atom2] direction /= np.linalg.norm(direction) direction *= np.random.uniform(-self.max_amplitude, self.max_amplitude) ...
Construct a transformation object
entailment
def get_transformation(self, coordinates): """Construct a transformation object""" atom1, atom2 = self.hinge_atoms center = coordinates[atom1] axis = coordinates[atom1] - coordinates[atom2] axis /= np.linalg.norm(axis) angle = np.random.uniform(-self.max_amplitude, self.m...
Construct a transformation object
entailment
def get_transformation(self, coordinates): """Construct a transformation object""" atom1, atom2, atom3 = self.hinge_atoms center = coordinates[atom2] a = coordinates[atom1] - coordinates[atom2] b = coordinates[atom3] - coordinates[atom2] axis = np.cross(a, b) norm...
Construct a transformation object
entailment
def get_transformation(self, coordinates): """Construct a transformation object""" atom1, atom2, atom3, atom4 = self.hinge_atoms a = coordinates[atom1] - coordinates[atom2] a /= np.linalg.norm(a) b = coordinates[atom3] - coordinates[atom4] b /= np.linalg.norm(b) d...
Construct a transformation object
entailment
def iter_surrounding(self, center_key): """Iterate over all bins surrounding the given bin""" for shift in self.neighbor_indexes: key = tuple(np.add(center_key, shift).astype(int)) if self.integer_cell is not None: key = self.wrap_key(key) bin = self._...
Iterate over all bins surrounding the given bin
entailment
def wrap_key(self, key): """Translate the key into the central cell This method is only applicable in case of a periodic system. """ return tuple(np.round( self.integer_cell.shortest_vector(key) ).astype(int))
Translate the key into the central cell This method is only applicable in case of a periodic system.
entailment
def _setup_grid(self, cutoff, unit_cell, grid): """Choose a proper grid for the binning process""" if grid is None: # automatically choose a decent grid if unit_cell is None: grid = cutoff/2.9 else: # The following would be faster, but ...
Choose a proper grid for the binning process
entailment
def parse_unit(expression): """Evaluate a python expression string containing constants Argument: | ``expression`` -- A string containing a numerical expressions including unit conversions. In addition to the variables in this module, also the following ...
Evaluate a python expression string containing constants Argument: | ``expression`` -- A string containing a numerical expressions including unit conversions. In addition to the variables in this module, also the following shorthands are supported:
entailment
def parents(self): """ Returns an simple FIFO queue with the ancestors and itself. """ q = self.__parent__.parents() q.put(self) return q
Returns an simple FIFO queue with the ancestors and itself.
entailment
def url(self): """ Returns the whole URL from the base to this node. """ path = None nodes = self.parents() while not nodes.empty(): path = urljoin(path, nodes.get().path()) return path
Returns the whole URL from the base to this node.
entailment
def auth_required(self): """ If any ancestor required an authentication, this node needs it too. """ if self._auth: return self._auth, self return self.__parent__.auth_required()
If any ancestor required an authentication, this node needs it too.
entailment
def _check_graph(self, graph): """the atomic numbers must match""" if graph.num_vertices != self.size: raise TypeError("The number of vertices in the graph does not " "match the length of the atomic numbers array.") # In practice these are typically the same arrays us...
the atomic numbers must match
entailment
def from_file(cls, filename): """Construct a molecule object read from the given file. The file format is inferred from the extensions. Currently supported formats are: ``*.cml``, ``*.fchk``, ``*.pdb``, ``*.sdf``, ``*.xyz`` If a file contains more than one molecule, only the f...
Construct a molecule object read from the given file. The file format is inferred from the extensions. Currently supported formats are: ``*.cml``, ``*.fchk``, ``*.pdb``, ``*.sdf``, ``*.xyz`` If a file contains more than one molecule, only the first one is read. ...
entailment
def com(self): """the center of mass of the molecule""" return (self.coordinates*self.masses.reshape((-1,1))).sum(axis=0)/self.mass
the center of mass of the molecule
entailment
def inertia_tensor(self): """the intertia tensor of the molecule""" result = np.zeros((3,3), float) for i in range(self.size): r = self.coordinates[i] - self.com # the diagonal term result.ravel()[::4] += self.masses[i]*(r**2).sum() # the outer pro...
the intertia tensor of the molecule
entailment
def chemical_formula(self): """the chemical formula of the molecule""" counts = {} for number in self.numbers: counts[number] = counts.get(number, 0)+1 items = [] for number, count in sorted(counts.items(), reverse=True): if count == 1: ite...
the chemical formula of the molecule
entailment
def set_default_masses(self): """Set self.masses based on self.numbers and periodic table.""" self.masses = np.array([periodic[n].mass for n in self.numbers])
Set self.masses based on self.numbers and periodic table.
entailment
def set_default_symbols(self): """Set self.symbols based on self.numbers and the periodic table.""" self.symbols = tuple(periodic[n].symbol for n in self.numbers)
Set self.symbols based on self.numbers and the periodic table.
entailment
def write_to_file(self, filename): """Write the molecular geometry to a file. The file format is inferred from the extensions. Currently supported formats are: ``*.xyz``, ``*.cml`` Argument: | ``filename`` -- a filename """ # TODO: give all file f...
Write the molecular geometry to a file. The file format is inferred from the extensions. Currently supported formats are: ``*.xyz``, ``*.cml`` Argument: | ``filename`` -- a filename
entailment
def rmsd(self, other): """Compute the RMSD between two molecules. Arguments: | ``other`` -- Another molecule with the same atom numbers Return values: | ``transformation`` -- the transformation that brings 'self' into overlap ...
Compute the RMSD between two molecules. Arguments: | ``other`` -- Another molecule with the same atom numbers Return values: | ``transformation`` -- the transformation that brings 'self' into overlap with 'other' | ``other...
entailment
def compute_rotsym(self, threshold=1e-3*angstrom): """Compute the rotational symmetry number. Optional argument: | ``threshold`` -- only when a rotation results in an rmsd below the given threshold, the rotation is considered to transform the ...
Compute the rotational symmetry number. Optional argument: | ``threshold`` -- only when a rotation results in an rmsd below the given threshold, the rotation is considered to transform the molecule onto itself.
entailment
def _get_current_label(self): """Get the label from the last line read""" if len(self._last) == 0: raise StopIteration return self._last[:self._last.find(":")]
Get the label from the last line read
entailment