repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
molmod/molmod
molmod/io/atrj.py
SectionFile._skip_section
def _skip_section(self): """Skip a section""" self._last = self._f.readline() while len(self._last) > 0 and len(self._last[0].strip()) == 0: self._last = self._f.readline()
python
def _skip_section(self): """Skip a section""" self._last = self._f.readline() while len(self._last) > 0 and len(self._last[0].strip()) == 0: self._last = self._f.readline()
[ "def", "_skip_section", "(", "self", ")", ":", "self", ".", "_last", "=", "self", ".", "_f", ".", "readline", "(", ")", "while", "len", "(", "self", ".", "_last", ")", ">", "0", "and", "len", "(", "self", ".", "_last", "[", "0", "]", ".", "stri...
Skip a section
[ "Skip", "a", "section" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/atrj.py#L51-L55
molmod/molmod
molmod/io/atrj.py
SectionFile._read_section
def _read_section(self): """Read and return an entire section""" lines = [self._last[self._last.find(":")+1:]] self._last = self._f.readline() while len(self._last) > 0 and len(self._last[0].strip()) == 0: lines.append(self._last) self._last = self._f.readline() ...
python
def _read_section(self): """Read and return an entire section""" lines = [self._last[self._last.find(":")+1:]] self._last = self._f.readline() while len(self._last) > 0 and len(self._last[0].strip()) == 0: lines.append(self._last) self._last = self._f.readline() ...
[ "def", "_read_section", "(", "self", ")", ":", "lines", "=", "[", "self", ".", "_last", "[", "self", ".", "_last", ".", "find", "(", "\":\"", ")", "+", "1", ":", "]", "]", "self", ".", "_last", "=", "self", ".", "_f", ".", "readline", "(", ")",...
Read and return an entire section
[ "Read", "and", "return", "an", "entire", "section" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/atrj.py#L57-L64
molmod/molmod
molmod/io/atrj.py
SectionFile.get_next
def get_next(self, label): """Get the next section with the given label""" while self._get_current_label() != label: self._skip_section() return self._read_section()
python
def get_next(self, label): """Get the next section with the given label""" while self._get_current_label() != label: self._skip_section() return self._read_section()
[ "def", "get_next", "(", "self", ",", "label", ")", ":", "while", "self", ".", "_get_current_label", "(", ")", "!=", "label", ":", "self", ".", "_skip_section", "(", ")", "return", "self", ".", "_read_section", "(", ")" ]
Get the next section with the given label
[ "Get", "the", "next", "section", "with", "the", "given", "label" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/atrj.py#L66-L70
molmod/molmod
molmod/io/atrj.py
ATRJReader._read_frame
def _read_frame(self): """Read a single frame from the trajectory""" self._secfile.get_next("Frame Number") frame = ATRJFrame() # Read the time and energy energy_lines = self._secfile.get_next("Time/Energy") energy_words = energy_lines[0].split() frame.time = floa...
python
def _read_frame(self): """Read a single frame from the trajectory""" self._secfile.get_next("Frame Number") frame = ATRJFrame() # Read the time and energy energy_lines = self._secfile.get_next("Time/Energy") energy_words = energy_lines[0].split() frame.time = floa...
[ "def", "_read_frame", "(", "self", ")", ":", "self", ".", "_secfile", ".", "get_next", "(", "\"Frame Number\"", ")", "frame", "=", "ATRJFrame", "(", ")", "# Read the time and energy", "energy_lines", "=", "self", ".", "_secfile", ".", "get_next", "(", "\"Time/...
Read a single frame from the trajectory
[ "Read", "a", "single", "frame", "from", "the", "trajectory" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/atrj.py#L107-L127
molmod/molmod
molmod/io/cube.py
get_cube_points
def get_cube_points(origin, axes, nrep): '''Generate the Cartesian coordinates of the points in a cube file *Arguemnts:* origin The cartesian coordinate for the origin of the grid. axes The 3 by 3 array with the grid spacings as rows. nrep The numb...
python
def get_cube_points(origin, axes, nrep): '''Generate the Cartesian coordinates of the points in a cube file *Arguemnts:* origin The cartesian coordinate for the origin of the grid. axes The 3 by 3 array with the grid spacings as rows. nrep The numb...
[ "def", "get_cube_points", "(", "origin", ",", "axes", ",", "nrep", ")", ":", "points", "=", "np", ".", "zeros", "(", "(", "nrep", "[", "0", "]", ",", "nrep", "[", "1", "]", ",", "nrep", "[", "2", "]", ",", "3", ")", ",", "float", ")", "points...
Generate the Cartesian coordinates of the points in a cube file *Arguemnts:* origin The cartesian coordinate for the origin of the grid. axes The 3 by 3 array with the grid spacings as rows. nrep The number of grid points along each axis.
[ "Generate", "the", "Cartesian", "coordinates", "of", "the", "points", "in", "a", "cube", "file" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cube.py#L37-L56
molmod/molmod
molmod/io/cube.py
Cube.from_file
def from_file(cls, filename): '''Create a cube object by loading data from a file. *Arguemnts:* filename The file to load. It must contain the header with the description of the grid and the molecule. ''' with open(filename) as f: ...
python
def from_file(cls, filename): '''Create a cube object by loading data from a file. *Arguemnts:* filename The file to load. It must contain the header with the description of the grid and the molecule. ''' with open(filename) as f: ...
[ "def", "from_file", "(", "cls", ",", "filename", ")", ":", "with", "open", "(", "filename", ")", "as", "f", ":", "molecule", ",", "origin", ",", "axes", ",", "nrep", ",", "subtitle", ",", "nuclear_charges", "=", "read_cube_header", "(", "f", ")", "data...
Create a cube object by loading data from a file. *Arguemnts:* filename The file to load. It must contain the header with the description of the grid and the molecule.
[ "Create", "a", "cube", "object", "by", "loading", "data", "from", "a", "file", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cube.py#L167-L190
molmod/molmod
molmod/io/cube.py
Cube.write_to_file
def write_to_file(self, fn): '''Write the cube to a file in the Gaussian cube format.''' with open(fn, 'w') as f: f.write(' {}\n'.format(self.molecule.title)) f.write(' {}\n'.format(self.subtitle)) def write_grid_line(n, v): f.write('%5i % 11.6f % 11....
python
def write_to_file(self, fn): '''Write the cube to a file in the Gaussian cube format.''' with open(fn, 'w') as f: f.write(' {}\n'.format(self.molecule.title)) f.write(' {}\n'.format(self.subtitle)) def write_grid_line(n, v): f.write('%5i % 11.6f % 11....
[ "def", "write_to_file", "(", "self", ",", "fn", ")", ":", "with", "open", "(", "fn", ",", "'w'", ")", "as", "f", ":", "f", ".", "write", "(", "' {}\\n'", ".", "format", "(", "self", ".", "molecule", ".", "title", ")", ")", "f", ".", "write", "(...
Write the cube to a file in the Gaussian cube format.
[ "Write", "the", "cube", "to", "a", "file", "in", "the", "Gaussian", "cube", "format", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cube.py#L226-L258
molmod/molmod
molmod/io/cube.py
Cube.copy
def copy(self, newdata=None): '''Return a copy of the cube with optionally new data.''' if newdata is None: newdata = self.data.copy() return self.__class__( self.molecule, self.origin.copy(), self.axes.copy(), self.nrep.copy(), newdata, self.subtitle, self.nu...
python
def copy(self, newdata=None): '''Return a copy of the cube with optionally new data.''' if newdata is None: newdata = self.data.copy() return self.__class__( self.molecule, self.origin.copy(), self.axes.copy(), self.nrep.copy(), newdata, self.subtitle, self.nu...
[ "def", "copy", "(", "self", ",", "newdata", "=", "None", ")", ":", "if", "newdata", "is", "None", ":", "newdata", "=", "self", ".", "data", ".", "copy", "(", ")", "return", "self", ".", "__class__", "(", "self", ".", "molecule", ",", "self", ".", ...
Return a copy of the cube with optionally new data.
[ "Return", "a", "copy", "of", "the", "cube", "with", "optionally", "new", "data", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cube.py#L260-L267
molmod/molmod
molmod/io/cp2k.py
CP2KSection._consistent
def _consistent(self): """Checks the constency between self.__index and self.__order""" if len(self.__order) != sum(len(values) for values in self.__index.values()): return False import copy tmp = copy.copy(self.__order) for key, values in self.__index.items(): ...
python
def _consistent(self): """Checks the constency between self.__index and self.__order""" if len(self.__order) != sum(len(values) for values in self.__index.values()): return False import copy tmp = copy.copy(self.__order) for key, values in self.__index.items(): ...
[ "def", "_consistent", "(", "self", ")", ":", "if", "len", "(", "self", ".", "__order", ")", "!=", "sum", "(", "len", "(", "values", ")", "for", "values", "in", "self", ".", "__index", ".", "values", "(", ")", ")", ":", "return", "False", "import", ...
Checks the constency between self.__index and self.__order
[ "Checks", "the", "constency", "between", "self", ".", "__index", "and", "self", ".", "__order" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L63-L80
molmod/molmod
molmod/io/cp2k.py
CP2KSection.append
def append(self, child): """Add a child section or keyword""" if not (isinstance(child, CP2KSection) or isinstance(child, CP2KKeyword)): raise TypeError("The child must be a CP2KSection or a CP2KKeyword, got: %s." % child) l = self.__index.setdefault(child.name, []) l.append(...
python
def append(self, child): """Add a child section or keyword""" if not (isinstance(child, CP2KSection) or isinstance(child, CP2KKeyword)): raise TypeError("The child must be a CP2KSection or a CP2KKeyword, got: %s." % child) l = self.__index.setdefault(child.name, []) l.append(...
[ "def", "append", "(", "self", ",", "child", ")", ":", "if", "not", "(", "isinstance", "(", "child", ",", "CP2KSection", ")", "or", "isinstance", "(", "child", ",", "CP2KKeyword", ")", ")", ":", "raise", "TypeError", "(", "\"The child must be a CP2KSection or...
Add a child section or keyword
[ "Add", "a", "child", "section", "or", "keyword" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L177-L183
molmod/molmod
molmod/io/cp2k.py
CP2KSection.dump_children
def dump_children(self, f, indent=''): """Dump the children of the current section to a file-like object""" for child in self.__order: child.dump(f, indent+' ')
python
def dump_children(self, f, indent=''): """Dump the children of the current section to a file-like object""" for child in self.__order: child.dump(f, indent+' ')
[ "def", "dump_children", "(", "self", ",", "f", ",", "indent", "=", "''", ")", ":", "for", "child", "in", "self", ".", "__order", ":", "child", ".", "dump", "(", "f", ",", "indent", "+", "' '", ")" ]
Dump the children of the current section to a file-like object
[ "Dump", "the", "children", "of", "the", "current", "section", "to", "a", "file", "-", "like", "object" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L193-L196
molmod/molmod
molmod/io/cp2k.py
CP2KSection.dump
def dump(self, f, indent=''): """Dump this section and its children to a file-like object""" print(("%s&%s %s" % (indent, self.__name, self.section_parameters)).rstrip(), file=f) self.dump_children(f, indent) print("%s&END %s" % (indent, self.__name), file=f)
python
def dump(self, f, indent=''): """Dump this section and its children to a file-like object""" print(("%s&%s %s" % (indent, self.__name, self.section_parameters)).rstrip(), file=f) self.dump_children(f, indent) print("%s&END %s" % (indent, self.__name), file=f)
[ "def", "dump", "(", "self", ",", "f", ",", "indent", "=", "''", ")", ":", "print", "(", "(", "\"%s&%s %s\"", "%", "(", "indent", ",", "self", ".", "__name", ",", "self", ".", "section_parameters", ")", ")", ".", "rstrip", "(", ")", ",", "file", "...
Dump this section and its children to a file-like object
[ "Dump", "this", "section", "and", "its", "children", "to", "a", "file", "-", "like", "object" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L198-L202
molmod/molmod
molmod/io/cp2k.py
CP2KSection.readline
def readline(self, f): """A helper method that only reads uncommented lines""" while True: line = f.readline() if len(line) == 0: raise EOFError line = line[:line.find('#')] line = line.strip() if len(line) > 0: ...
python
def readline(self, f): """A helper method that only reads uncommented lines""" while True: line = f.readline() if len(line) == 0: raise EOFError line = line[:line.find('#')] line = line.strip() if len(line) > 0: ...
[ "def", "readline", "(", "self", ",", "f", ")", ":", "while", "True", ":", "line", "=", "f", ".", "readline", "(", ")", "if", "len", "(", "line", ")", "==", "0", ":", "raise", "EOFError", "line", "=", "line", "[", ":", "line", ".", "find", "(", ...
A helper method that only reads uncommented lines
[ "A", "helper", "method", "that", "only", "reads", "uncommented", "lines" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L204-L213
molmod/molmod
molmod/io/cp2k.py
CP2KSection.load_children
def load_children(self, f): """Load the children of this section from a file-like object""" while True: line = self.readline(f) if line[0] == '&': if line[1:].startswith("END"): check_name = line[4:].strip().upper() if check...
python
def load_children(self, f): """Load the children of this section from a file-like object""" while True: line = self.readline(f) if line[0] == '&': if line[1:].startswith("END"): check_name = line[4:].strip().upper() if check...
[ "def", "load_children", "(", "self", ",", "f", ")", ":", "while", "True", ":", "line", "=", "self", ".", "readline", "(", "f", ")", "if", "line", "[", "0", "]", "==", "'&'", ":", "if", "line", "[", "1", ":", "]", ".", "startswith", "(", "\"END\...
Load the children of this section from a file-like object
[ "Load", "the", "children", "of", "this", "section", "from", "a", "file", "-", "like", "object" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L215-L232
molmod/molmod
molmod/io/cp2k.py
CP2KSection.load
def load(self, f, line=None): """Load this section from a file-like object""" if line is None: # in case the file contains only a fragment of an input file, # this is useful. line = f.readlin() words = line[1:].split() self.__name = words[0].upper() ...
python
def load(self, f, line=None): """Load this section from a file-like object""" if line is None: # in case the file contains only a fragment of an input file, # this is useful. line = f.readlin() words = line[1:].split() self.__name = words[0].upper() ...
[ "def", "load", "(", "self", ",", "f", ",", "line", "=", "None", ")", ":", "if", "line", "is", "None", ":", "# in case the file contains only a fragment of an input file,", "# this is useful.", "line", "=", "f", ".", "readlin", "(", ")", "words", "=", "line", ...
Load this section from a file-like object
[ "Load", "this", "section", "from", "a", "file", "-", "like", "object" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L235-L247
molmod/molmod
molmod/io/cp2k.py
CP2KKeyword.dump
def dump(self, f, indent=''): """Dump this keyword to a file-like object""" if self.__unit is None: print(("%s%s %s" % (indent, self.__name, self.__value)).rstrip(), file=f) else: print(("%s%s [%s] %s" % (indent, self.__name, self.__unit, self.__value)).rstrip(), file=f)
python
def dump(self, f, indent=''): """Dump this keyword to a file-like object""" if self.__unit is None: print(("%s%s %s" % (indent, self.__name, self.__value)).rstrip(), file=f) else: print(("%s%s [%s] %s" % (indent, self.__name, self.__unit, self.__value)).rstrip(), file=f)
[ "def", "dump", "(", "self", ",", "f", ",", "indent", "=", "''", ")", ":", "if", "self", ".", "__unit", "is", "None", ":", "print", "(", "(", "\"%s%s %s\"", "%", "(", "indent", ",", "self", ".", "__name", ",", "self", ".", "__value", ")", ")", "...
Dump this keyword to a file-like object
[ "Dump", "this", "keyword", "to", "a", "file", "-", "like", "object" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L273-L278
molmod/molmod
molmod/io/cp2k.py
CP2KKeyword.load
def load(self, line): """Load this keyword from a file-like object""" words = line.split() try: float(words[0]) self.__name = "" self.__value = " ".join(words) except ValueError: self.__name = words[0].upper() if len(words) > 2 ...
python
def load(self, line): """Load this keyword from a file-like object""" words = line.split() try: float(words[0]) self.__name = "" self.__value = " ".join(words) except ValueError: self.__name = words[0].upper() if len(words) > 2 ...
[ "def", "load", "(", "self", ",", "line", ")", ":", "words", "=", "line", ".", "split", "(", ")", "try", ":", "float", "(", "words", "[", "0", "]", ")", "self", ".", "__name", "=", "\"\"", "self", ".", "__value", "=", "\" \"", ".", "join", "(", ...
Load this keyword from a file-like object
[ "Load", "this", "keyword", "from", "a", "file", "-", "like", "object" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L280-L293
molmod/molmod
molmod/io/cp2k.py
CP2KKeyword.set_value
def set_value(self, value): """Set the value associated with the keyword""" if not isinstance(value, str): raise TypeError("A value must be a string, got %s." % value) self.__value = value
python
def set_value(self, value): """Set the value associated with the keyword""" if not isinstance(value, str): raise TypeError("A value must be a string, got %s." % value) self.__value = value
[ "def", "set_value", "(", "self", ",", "value", ")", ":", "if", "not", "isinstance", "(", "value", ",", "str", ")", ":", "raise", "TypeError", "(", "\"A value must be a string, got %s.\"", "%", "value", ")", "self", ".", "__value", "=", "value" ]
Set the value associated with the keyword
[ "Set", "the", "value", "associated", "with", "the", "keyword" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L296-L300
molmod/molmod
molmod/io/cp2k.py
CP2KInputFile.read_from_file
def read_from_file(filename): """ Arguments: | ``filename`` -- the filename of the input file Use as follows:: >>> if = CP2KInputFile.read_from_file("somefile.inp") >>> for section in if: ... print section.name """ ...
python
def read_from_file(filename): """ Arguments: | ``filename`` -- the filename of the input file Use as follows:: >>> if = CP2KInputFile.read_from_file("somefile.inp") >>> for section in if: ... print section.name """ ...
[ "def", "read_from_file", "(", "filename", ")", ":", "with", "open", "(", "filename", ")", "as", "f", ":", "result", "=", "CP2KInputFile", "(", ")", "try", ":", "while", "True", ":", "result", ".", "load_children", "(", "f", ")", "except", "EOFError", "...
Arguments: | ``filename`` -- the filename of the input file Use as follows:: >>> if = CP2KInputFile.read_from_file("somefile.inp") >>> for section in if: ... print section.name
[ "Arguments", ":", "|", "filename", "--", "the", "filename", "of", "the", "input", "file" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L323-L341
molmod/molmod
molmod/io/cpmd.py
CPMDTrajectoryReader._read_frame
def _read_frame(self): """Read and return the next time frame""" pos = np.zeros((self.num_atoms, 3), float) vel = np.zeros((self.num_atoms, 3), float) for i in range(self.num_atoms): line = next(self._f) words = line.split() pos[i, 0] = float(words[1])...
python
def _read_frame(self): """Read and return the next time frame""" pos = np.zeros((self.num_atoms, 3), float) vel = np.zeros((self.num_atoms, 3), float) for i in range(self.num_atoms): line = next(self._f) words = line.split() pos[i, 0] = float(words[1])...
[ "def", "_read_frame", "(", "self", ")", ":", "pos", "=", "np", ".", "zeros", "(", "(", "self", ".", "num_atoms", ",", "3", ")", ",", "float", ")", "vel", "=", "np", ".", "zeros", "(", "(", "self", ".", "num_atoms", ",", "3", ")", ",", "float", ...
Read and return the next time frame
[ "Read", "and", "return", "the", "next", "time", "frame" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cpmd.py#L64-L77
molmod/molmod
molmod/transformations.py
check_matrix
def check_matrix(m): """Check the sanity of the given 4x4 transformation matrix""" if m.shape != (4, 4): raise ValueError("The argument must be a 4x4 array.") if max(abs(m[3, 0:3])) > eps: raise ValueError("The given matrix does not have correct translational part") if abs(m[3, 3] - 1.0)...
python
def check_matrix(m): """Check the sanity of the given 4x4 transformation matrix""" if m.shape != (4, 4): raise ValueError("The argument must be a 4x4 array.") if max(abs(m[3, 0:3])) > eps: raise ValueError("The given matrix does not have correct translational part") if abs(m[3, 3] - 1.0)...
[ "def", "check_matrix", "(", "m", ")", ":", "if", "m", ".", "shape", "!=", "(", "4", ",", "4", ")", ":", "raise", "ValueError", "(", "\"The argument must be a 4x4 array.\"", ")", "if", "max", "(", "abs", "(", "m", "[", "3", ",", "0", ":", "3", "]", ...
Check the sanity of the given 4x4 transformation matrix
[ "Check", "the", "sanity", "of", "the", "given", "4x4", "transformation", "matrix" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L48-L55
molmod/molmod
molmod/transformations.py
superpose
def superpose(ras, rbs, weights=None): """Compute the transformation that minimizes the RMSD between the points ras and rbs Arguments: | ``ras`` -- a ``np.array`` with 3D coordinates of geometry A, shape=(N,3) | ``rbs`` -- a ``np.array`` with 3D coordinates of geom...
python
def superpose(ras, rbs, weights=None): """Compute the transformation that minimizes the RMSD between the points ras and rbs Arguments: | ``ras`` -- a ``np.array`` with 3D coordinates of geometry A, shape=(N,3) | ``rbs`` -- a ``np.array`` with 3D coordinates of geom...
[ "def", "superpose", "(", "ras", ",", "rbs", ",", "weights", "=", "None", ")", ":", "if", "weights", "is", "None", ":", "ma", "=", "ras", ".", "mean", "(", "axis", "=", "0", ")", "mb", "=", "rbs", ".", "mean", "(", "axis", "=", "0", ")", "else...
Compute the transformation that minimizes the RMSD between the points ras and rbs Arguments: | ``ras`` -- a ``np.array`` with 3D coordinates of geometry A, shape=(N,3) | ``rbs`` -- a ``np.array`` with 3D coordinates of geometry B, shape=(N,3) ...
[ "Compute", "the", "transformation", "that", "minimizes", "the", "RMSD", "between", "the", "points", "ras", "and", "rbs" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L434-L477
molmod/molmod
molmod/transformations.py
fit_rmsd
def fit_rmsd(ras, rbs, weights=None): """Fit geometry rbs onto ras, returns more info than superpose Arguments: | ``ras`` -- a numpy array with 3D coordinates of geometry A, shape=(N,3) | ``rbs`` -- a numpy array with 3D coordinates of geometry B, ...
python
def fit_rmsd(ras, rbs, weights=None): """Fit geometry rbs onto ras, returns more info than superpose Arguments: | ``ras`` -- a numpy array with 3D coordinates of geometry A, shape=(N,3) | ``rbs`` -- a numpy array with 3D coordinates of geometry B, ...
[ "def", "fit_rmsd", "(", "ras", ",", "rbs", ",", "weights", "=", "None", ")", ":", "transformation", "=", "superpose", "(", "ras", ",", "rbs", ",", "weights", ")", "rbs_trans", "=", "transformation", "*", "rbs", "rmsd", "=", "compute_rmsd", "(", "ras", ...
Fit geometry rbs onto ras, returns more info than superpose Arguments: | ``ras`` -- a numpy array with 3D coordinates of geometry A, shape=(N,3) | ``rbs`` -- a numpy array with 3D coordinates of geometry B, shape=(N,3) Optional arguments:...
[ "Fit", "geometry", "rbs", "onto", "ras", "returns", "more", "info", "than", "superpose" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L480-L507
molmod/molmod
molmod/transformations.py
Translation.inv
def inv(self): """The inverse translation""" result = Translation(-self.t) result._cache_inv = self return result
python
def inv(self): """The inverse translation""" result = Translation(-self.t) result._cache_inv = self return result
[ "def", "inv", "(", "self", ")", ":", "result", "=", "Translation", "(", "-", "self", ".", "t", ")", "result", ".", "_cache_inv", "=", "self", "return", "result" ]
The inverse translation
[ "The", "inverse", "translation" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L94-L98
molmod/molmod
molmod/transformations.py
Translation.apply_to
def apply_to(self, x, columns=False): """Apply this translation to the given object The argument can be several sorts of objects: * ``np.array`` with shape (3, ) * ``np.array`` with shape (N, 3) * ``np.array`` with shape (3, N), use ``columns=True`` * ``T...
python
def apply_to(self, x, columns=False): """Apply this translation to the given object The argument can be several sorts of objects: * ``np.array`` with shape (3, ) * ``np.array`` with shape (N, 3) * ``np.array`` with shape (3, N), use ``columns=True`` * ``T...
[ "def", "apply_to", "(", "self", ",", "x", ",", "columns", "=", "False", ")", ":", "if", "isinstance", "(", "x", ",", "np", ".", "ndarray", ")", "and", "len", "(", "x", ".", "shape", ")", "==", "2", "and", "x", ".", "shape", "[", "0", "]", "==...
Apply this translation to the given object The argument can be several sorts of objects: * ``np.array`` with shape (3, ) * ``np.array`` with shape (N, 3) * ``np.array`` with shape (3, N), use ``columns=True`` * ``Translation`` * ``Rotation`` ...
[ "Apply", "this", "translation", "to", "the", "given", "object" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L100-L133
molmod/molmod
molmod/transformations.py
Translation.compare
def compare(self, other, t_threshold=1e-3): """Compare two translations The RMSD of the translation vectors is computed. The return value is True when the RMSD is below the threshold, i.e. when the two translations are almost identical. """ return compute_rmsd(s...
python
def compare(self, other, t_threshold=1e-3): """Compare two translations The RMSD of the translation vectors is computed. The return value is True when the RMSD is below the threshold, i.e. when the two translations are almost identical. """ return compute_rmsd(s...
[ "def", "compare", "(", "self", ",", "other", ",", "t_threshold", "=", "1e-3", ")", ":", "return", "compute_rmsd", "(", "self", ".", "t", ",", "other", ".", "t", ")", "<", "t_threshold" ]
Compare two translations The RMSD of the translation vectors is computed. The return value is True when the RMSD is below the threshold, i.e. when the two translations are almost identical.
[ "Compare", "two", "translations" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L137-L144
molmod/molmod
molmod/transformations.py
Rotation._check_r
def _check_r(self, r): """the columns must orthogonal""" if abs(np.dot(r[:, 0], r[:, 0]) - 1) > eps or \ abs(np.dot(r[:, 0], r[:, 0]) - 1) > eps or \ abs(np.dot(r[:, 0], r[:, 0]) - 1) > eps or \ np.dot(r[:, 0], r[:, 1]) > eps or \ np.dot(r[:, 1], r[:, 2]) ...
python
def _check_r(self, r): """the columns must orthogonal""" if abs(np.dot(r[:, 0], r[:, 0]) - 1) > eps or \ abs(np.dot(r[:, 0], r[:, 0]) - 1) > eps or \ abs(np.dot(r[:, 0], r[:, 0]) - 1) > eps or \ np.dot(r[:, 0], r[:, 1]) > eps or \ np.dot(r[:, 1], r[:, 2]) ...
[ "def", "_check_r", "(", "self", ",", "r", ")", ":", "if", "abs", "(", "np", ".", "dot", "(", "r", "[", ":", ",", "0", "]", ",", "r", "[", ":", ",", "0", "]", ")", "-", "1", ")", ">", "eps", "or", "abs", "(", "np", ".", "dot", "(", "r"...
the columns must orthogonal
[ "the", "columns", "must", "orthogonal" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L153-L161
molmod/molmod
molmod/transformations.py
Rotation.random
def random(cls): """Return a random rotation""" axis = random_unit() angle = np.random.uniform(0,2*np.pi) invert = bool(np.random.randint(0,2)) return Rotation.from_properties(angle, axis, invert)
python
def random(cls): """Return a random rotation""" axis = random_unit() angle = np.random.uniform(0,2*np.pi) invert = bool(np.random.randint(0,2)) return Rotation.from_properties(angle, axis, invert)
[ "def", "random", "(", "cls", ")", ":", "axis", "=", "random_unit", "(", ")", "angle", "=", "np", ".", "random", ".", "uniform", "(", "0", ",", "2", "*", "np", ".", "pi", ")", "invert", "=", "bool", "(", "np", ".", "random", ".", "randint", "(",...
Return a random rotation
[ "Return", "a", "random", "rotation" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L186-L191
molmod/molmod
molmod/transformations.py
Rotation.from_properties
def from_properties(cls, angle, axis, invert): """Initialize a rotation based on the properties""" norm = np.linalg.norm(axis) if norm > 0: x = axis[0] / norm y = axis[1] / norm z = axis[2] / norm c = np.cos(angle) s = np.sin(angle) ...
python
def from_properties(cls, angle, axis, invert): """Initialize a rotation based on the properties""" norm = np.linalg.norm(axis) if norm > 0: x = axis[0] / norm y = axis[1] / norm z = axis[2] / norm c = np.cos(angle) s = np.sin(angle) ...
[ "def", "from_properties", "(", "cls", ",", "angle", ",", "axis", ",", "invert", ")", ":", "norm", "=", "np", ".", "linalg", ".", "norm", "(", "axis", ")", "if", "norm", ">", "0", ":", "x", "=", "axis", "[", "0", "]", "/", "norm", "y", "=", "a...
Initialize a rotation based on the properties
[ "Initialize", "a", "rotation", "based", "on", "the", "properties" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L194-L210
molmod/molmod
molmod/transformations.py
Rotation.properties
def properties(self): """Rotation properties: angle, axis, invert""" # determine wether an inversion rotation has been applied invert = (np.linalg.det(self.r) < 0) factor = {True: -1, False: 1}[invert] # get the rotation data # trace(r) = 1+2*cos(angle) cos_angle ...
python
def properties(self): """Rotation properties: angle, axis, invert""" # determine wether an inversion rotation has been applied invert = (np.linalg.det(self.r) < 0) factor = {True: -1, False: 1}[invert] # get the rotation data # trace(r) = 1+2*cos(angle) cos_angle ...
[ "def", "properties", "(", "self", ")", ":", "# determine wether an inversion rotation has been applied", "invert", "=", "(", "np", ".", "linalg", ".", "det", "(", "self", ".", "r", ")", "<", "0", ")", "factor", "=", "{", "True", ":", "-", "1", ",", "Fals...
Rotation properties: angle, axis, invert
[ "Rotation", "properties", ":", "angle", "axis", "invert" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L213-L238
molmod/molmod
molmod/transformations.py
Rotation.matrix
def matrix(self): """The 4x4 matrix representation of this rotation""" result = np.identity(4, float) result[0:3, 0:3] = self.r return result
python
def matrix(self): """The 4x4 matrix representation of this rotation""" result = np.identity(4, float) result[0:3, 0:3] = self.r return result
[ "def", "matrix", "(", "self", ")", ":", "result", "=", "np", ".", "identity", "(", "4", ",", "float", ")", "result", "[", "0", ":", "3", ",", "0", ":", "3", "]", "=", "self", ".", "r", "return", "result" ]
The 4x4 matrix representation of this rotation
[ "The", "4x4", "matrix", "representation", "of", "this", "rotation" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L241-L245
molmod/molmod
molmod/transformations.py
Rotation.inv
def inv(self): """The inverse rotation""" result = Rotation(self.r.transpose()) result._cache_inv = self return result
python
def inv(self): """The inverse rotation""" result = Rotation(self.r.transpose()) result._cache_inv = self return result
[ "def", "inv", "(", "self", ")", ":", "result", "=", "Rotation", "(", "self", ".", "r", ".", "transpose", "(", ")", ")", "result", ".", "_cache_inv", "=", "self", "return", "result" ]
The inverse rotation
[ "The", "inverse", "rotation" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L248-L252
molmod/molmod
molmod/transformations.py
Rotation.apply_to
def apply_to(self, x, columns=False): """Apply this rotation to the given object The argument can be several sorts of objects: * ``np.array`` with shape (3, ) * ``np.array`` with shape (N, 3) * ``np.array`` with shape (3, N), use ``columns=True`` * ``Tran...
python
def apply_to(self, x, columns=False): """Apply this rotation to the given object The argument can be several sorts of objects: * ``np.array`` with shape (3, ) * ``np.array`` with shape (N, 3) * ``np.array`` with shape (3, N), use ``columns=True`` * ``Tran...
[ "def", "apply_to", "(", "self", ",", "x", ",", "columns", "=", "False", ")", ":", "if", "isinstance", "(", "x", ",", "np", ".", "ndarray", ")", "and", "len", "(", "x", ".", "shape", ")", "==", "2", "and", "x", ".", "shape", "[", "0", "]", "==...
Apply this rotation to the given object The argument can be several sorts of objects: * ``np.array`` with shape (3, ) * ``np.array`` with shape (N, 3) * ``np.array`` with shape (3, N), use ``columns=True`` * ``Translation`` * ``Rotation`` * ...
[ "Apply", "this", "rotation", "to", "the", "given", "object" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L254-L287
molmod/molmod
molmod/transformations.py
Rotation.compare
def compare(self, other, r_threshold=1e-3): """Compare two rotations The RMSD of the rotation matrices is computed. The return value is True when the RMSD is below the threshold, i.e. when the two rotations are almost identical. """ return compute_rmsd(self.r, o...
python
def compare(self, other, r_threshold=1e-3): """Compare two rotations The RMSD of the rotation matrices is computed. The return value is True when the RMSD is below the threshold, i.e. when the two rotations are almost identical. """ return compute_rmsd(self.r, o...
[ "def", "compare", "(", "self", ",", "other", ",", "r_threshold", "=", "1e-3", ")", ":", "return", "compute_rmsd", "(", "self", ".", "r", ",", "other", ".", "r", ")", "<", "r_threshold" ]
Compare two rotations The RMSD of the rotation matrices is computed. The return value is True when the RMSD is below the threshold, i.e. when the two rotations are almost identical.
[ "Compare", "two", "rotations" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L291-L298
molmod/molmod
molmod/transformations.py
Complete.from_properties
def from_properties(cls, angle, axis, invert, translation): """Initialize a transformation based on the properties""" rot = Rotation.from_properties(angle, axis, invert) return Complete(rot.r, translation)
python
def from_properties(cls, angle, axis, invert, translation): """Initialize a transformation based on the properties""" rot = Rotation.from_properties(angle, axis, invert) return Complete(rot.r, translation)
[ "def", "from_properties", "(", "cls", ",", "angle", ",", "axis", ",", "invert", ",", "translation", ")", ":", "rot", "=", "Rotation", ".", "from_properties", "(", "angle", ",", "axis", ",", "invert", ")", "return", "Complete", "(", "rot", ".", "r", ","...
Initialize a transformation based on the properties
[ "Initialize", "a", "transformation", "based", "on", "the", "properties" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L333-L336
molmod/molmod
molmod/transformations.py
Complete.cast
def cast(cls, c): """Convert the first argument into a Complete object""" if isinstance(c, Complete): return c elif isinstance(c, Translation): return Complete(np.identity(3, float), c.t) elif isinstance(c, Rotation): return Complete(c.r, np.zeros(3, f...
python
def cast(cls, c): """Convert the first argument into a Complete object""" if isinstance(c, Complete): return c elif isinstance(c, Translation): return Complete(np.identity(3, float), c.t) elif isinstance(c, Rotation): return Complete(c.r, np.zeros(3, f...
[ "def", "cast", "(", "cls", ",", "c", ")", ":", "if", "isinstance", "(", "c", ",", "Complete", ")", ":", "return", "c", "elif", "isinstance", "(", "c", ",", "Translation", ")", ":", "return", "Complete", "(", "np", ".", "identity", "(", "3", ",", ...
Convert the first argument into a Complete object
[ "Convert", "the", "first", "argument", "into", "a", "Complete", "object" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L339-L346
molmod/molmod
molmod/transformations.py
Complete.about_axis
def about_axis(cls, center, angle, axis, invert=False): """Create transformation that represents a rotation about an axis Arguments: | ``center`` -- Point on the axis | ``angle`` -- Rotation angle | ``axis`` -- Rotation axis | ``invert`` -- Whe...
python
def about_axis(cls, center, angle, axis, invert=False): """Create transformation that represents a rotation about an axis Arguments: | ``center`` -- Point on the axis | ``angle`` -- Rotation angle | ``axis`` -- Rotation axis | ``invert`` -- Whe...
[ "def", "about_axis", "(", "cls", ",", "center", ",", "angle", ",", "axis", ",", "invert", "=", "False", ")", ":", "return", "Translation", "(", "center", ")", "*", "Rotation", ".", "from_properties", "(", "angle", ",", "axis", ",", "invert", ")", "*", ...
Create transformation that represents a rotation about an axis Arguments: | ``center`` -- Point on the axis | ``angle`` -- Rotation angle | ``axis`` -- Rotation axis | ``invert`` -- When True, an inversion rotation is constructed ...
[ "Create", "transformation", "that", "represents", "a", "rotation", "about", "an", "axis" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L349-L361
molmod/molmod
molmod/transformations.py
Complete.properties
def properties(self): """Transformation properties: angle, axis, invert, translation""" rot = Rotation(self.r) angle, axis, invert = rot.properties return angle, axis, invert, self.t
python
def properties(self): """Transformation properties: angle, axis, invert, translation""" rot = Rotation(self.r) angle, axis, invert = rot.properties return angle, axis, invert, self.t
[ "def", "properties", "(", "self", ")", ":", "rot", "=", "Rotation", "(", "self", ".", "r", ")", "angle", ",", "axis", ",", "invert", "=", "rot", ".", "properties", "return", "angle", ",", "axis", ",", "invert", ",", "self", ".", "t" ]
Transformation properties: angle, axis, invert, translation
[ "Transformation", "properties", ":", "angle", "axis", "invert", "translation" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L372-L376
molmod/molmod
molmod/transformations.py
Complete.inv
def inv(self): """The inverse transformation""" result = Complete(self.r.transpose(), np.dot(self.r.transpose(), -self.t)) result._cache_inv = self return result
python
def inv(self): """The inverse transformation""" result = Complete(self.r.transpose(), np.dot(self.r.transpose(), -self.t)) result._cache_inv = self return result
[ "def", "inv", "(", "self", ")", ":", "result", "=", "Complete", "(", "self", ".", "r", ".", "transpose", "(", ")", ",", "np", ".", "dot", "(", "self", ".", "r", ".", "transpose", "(", ")", ",", "-", "self", ".", "t", ")", ")", "result", ".", ...
The inverse transformation
[ "The", "inverse", "transformation" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L379-L383
molmod/molmod
molmod/transformations.py
Complete.compare
def compare(self, other, t_threshold=1e-3, r_threshold=1e-3): """Compare two transformations The RMSD values of the rotation matrices and the translation vectors are computed. The return value is True when the RMSD values are below the thresholds, i.e. when the two transformati...
python
def compare(self, other, t_threshold=1e-3, r_threshold=1e-3): """Compare two transformations The RMSD values of the rotation matrices and the translation vectors are computed. The return value is True when the RMSD values are below the thresholds, i.e. when the two transformati...
[ "def", "compare", "(", "self", ",", "other", ",", "t_threshold", "=", "1e-3", ",", "r_threshold", "=", "1e-3", ")", ":", "return", "compute_rmsd", "(", "self", ".", "t", ",", "other", ".", "t", ")", "<", "t_threshold", "and", "compute_rmsd", "(", "self...
Compare two transformations The RMSD values of the rotation matrices and the translation vectors are computed. The return value is True when the RMSD values are below the thresholds, i.e. when the two transformations are almost identical.
[ "Compare", "two", "transformations" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/transformations.py#L423-L431
molmod/molmod
molmod/io/lammps.py
LAMMPSDumpReader._read_frame
def _read_frame(self): """Read and return the next time frame""" # Read one frame, we assume that the current file position is at the # line 'ITEM: TIMESTEP' and that this line marks the beginning of a # time frame. line = next(self._f) if line != 'ITEM: TIMESTEP\n': ...
python
def _read_frame(self): """Read and return the next time frame""" # Read one frame, we assume that the current file position is at the # line 'ITEM: TIMESTEP' and that this line marks the beginning of a # time frame. line = next(self._f) if line != 'ITEM: TIMESTEP\n': ...
[ "def", "_read_frame", "(", "self", ")", ":", "# Read one frame, we assume that the current file position is at the", "# line 'ITEM: TIMESTEP' and that this line marks the beginning of a", "# time frame.", "line", "=", "next", "(", "self", ".", "_f", ")", "if", "line", "!=", "...
Read and return the next time frame
[ "Read", "and", "return", "the", "next", "time", "frame" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/lammps.py#L72-L115
molmod/molmod
molmod/io/lammps.py
LAMMPSDumpReader._skip_frame
def _skip_frame(self): """Skip the next time frame""" for line in self._f: if line == 'ITEM: ATOMS\n': break for i in range(self.num_atoms): next(self._f)
python
def _skip_frame(self): """Skip the next time frame""" for line in self._f: if line == 'ITEM: ATOMS\n': break for i in range(self.num_atoms): next(self._f)
[ "def", "_skip_frame", "(", "self", ")", ":", "for", "line", "in", "self", ".", "_f", ":", "if", "line", "==", "'ITEM: ATOMS\\n'", ":", "break", "for", "i", "in", "range", "(", "self", ".", "num_atoms", ")", ":", "next", "(", "self", ".", "_f", ")" ...
Skip the next time frame
[ "Skip", "the", "next", "time", "frame" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/lammps.py#L117-L123
molmod/molmod
molmod/periodic.py
PeriodicData._add_atom_info
def _add_atom_info(self, atom_info): """Add an atom info object to the database""" self.atoms_by_number[atom_info.number] = atom_info self.atoms_by_symbol[atom_info.symbol.lower()] = atom_info
python
def _add_atom_info(self, atom_info): """Add an atom info object to the database""" self.atoms_by_number[atom_info.number] = atom_info self.atoms_by_symbol[atom_info.symbol.lower()] = atom_info
[ "def", "_add_atom_info", "(", "self", ",", "atom_info", ")", ":", "self", ".", "atoms_by_number", "[", "atom_info", ".", "number", "]", "=", "atom_info", "self", ".", "atoms_by_symbol", "[", "atom_info", ".", "symbol", ".", "lower", "(", ")", "]", "=", "...
Add an atom info object to the database
[ "Add", "an", "atom", "info", "object", "to", "the", "database" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/periodic.py#L118-L121
molmod/molmod
molmod/clusters.py
RuleCluster.update
def update(self, other): """Extend the current cluster with data from another cluster""" Cluster.update(self, other) self.rules.extend(other.rules)
python
def update(self, other): """Extend the current cluster with data from another cluster""" Cluster.update(self, other) self.rules.extend(other.rules)
[ "def", "update", "(", "self", ",", "other", ")", ":", "Cluster", ".", "update", "(", "self", ",", "other", ")", "self", ".", "rules", ".", "extend", "(", "other", ".", "rules", ")" ]
Extend the current cluster with data from another cluster
[ "Extend", "the", "current", "cluster", "with", "data", "from", "another", "cluster" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/clusters.py#L86-L89
molmod/molmod
molmod/clusters.py
ClusterFactory.add_related
def add_related(self, *objects): """Add related items The arguments can be individual items or cluster objects containing several items. When two groups of related items share one or more common members, they will be merged into one cluster. """ mast...
python
def add_related(self, *objects): """Add related items The arguments can be individual items or cluster objects containing several items. When two groups of related items share one or more common members, they will be merged into one cluster. """ mast...
[ "def", "add_related", "(", "self", ",", "*", "objects", ")", ":", "master", "=", "None", "# this will become the common cluster of all related items", "slaves", "=", "set", "(", "[", "]", ")", "# set of clusters that are going to be merged in the master", "solitaire", "="...
Add related items The arguments can be individual items or cluster objects containing several items. When two groups of related items share one or more common members, they will be merged into one cluster.
[ "Add", "related", "items" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/clusters.py#L105-L151
molmod/molmod
molmod/io/dlpoly.py
DLPolyHistoryReader._read_frame
def _read_frame(self): """Read a single frame from the trajectory""" # auxiliary read function def read_three(msg): """Read three words as floating point numbers""" line = next(self._f) try: return [float(line[:12]), float(line[12:24]), float(l...
python
def _read_frame(self): """Read a single frame from the trajectory""" # auxiliary read function def read_three(msg): """Read three words as floating point numbers""" line = next(self._f) try: return [float(line[:12]), float(line[12:24]), float(l...
[ "def", "_read_frame", "(", "self", ")", ":", "# auxiliary read function", "def", "read_three", "(", "msg", ")", ":", "\"\"\"Read three words as floating point numbers\"\"\"", "line", "=", "next", "(", "self", ".", "_f", ")", "try", ":", "return", "[", "float", "...
Read a single frame from the trajectory
[ "Read", "a", "single", "frame", "from", "the", "trajectory" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/dlpoly.py#L112-L190
molmod/molmod
molmod/io/dlpoly.py
DLPolyOutputReader.goto_next_frame
def goto_next_frame(self): """Continue reading until the next frame is reached""" marked = False while True: line = next(self._f)[:-1] if marked and len(line) > 0 and not line.startswith(" --------"): try: step = int(line[:10]) ...
python
def goto_next_frame(self): """Continue reading until the next frame is reached""" marked = False while True: line = next(self._f)[:-1] if marked and len(line) > 0 and not line.startswith(" --------"): try: step = int(line[:10]) ...
[ "def", "goto_next_frame", "(", "self", ")", ":", "marked", "=", "False", "while", "True", ":", "line", "=", "next", "(", "self", ".", "_f", ")", "[", ":", "-", "1", "]", "if", "marked", "and", "len", "(", "line", ")", ">", "0", "and", "not", "l...
Continue reading until the next frame is reached
[ "Continue", "reading", "until", "the", "next", "frame", "is", "reached" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/dlpoly.py#L253-L264
molmod/molmod
molmod/io/dlpoly.py
DLPolyOutputReader._read_frame
def _read_frame(self): """Read a single frame from the trajectory""" # optionally skip the equilibration if self.skip_equi_period: while True: step, line = self.goto_next_frame() self._counter += 1 if step >= self.equi_period: ...
python
def _read_frame(self): """Read a single frame from the trajectory""" # optionally skip the equilibration if self.skip_equi_period: while True: step, line = self.goto_next_frame() self._counter += 1 if step >= self.equi_period: ...
[ "def", "_read_frame", "(", "self", ")", ":", "# optionally skip the equilibration", "if", "self", ".", "skip_equi_period", ":", "while", "True", ":", "step", ",", "line", "=", "self", ".", "goto_next_frame", "(", ")", "self", ".", "_counter", "+=", "1", "if"...
Read a single frame from the trajectory
[ "Read", "a", "single", "frame", "from", "the", "trajectory" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/dlpoly.py#L266-L300
molmod/molmod
molmod/io/xyz.py
XYZReader._read_frame
def _read_frame(self): """Read a frame from the XYZ file""" size = self.read_size() title = self._f.readline()[:-1] if self.symbols is None: symbols = [] coordinates = np.zeros((size, 3), float) for counter in range(size): line = self._f.readline(...
python
def _read_frame(self): """Read a frame from the XYZ file""" size = self.read_size() title = self._f.readline()[:-1] if self.symbols is None: symbols = [] coordinates = np.zeros((size, 3), float) for counter in range(size): line = self._f.readline(...
[ "def", "_read_frame", "(", "self", ")", ":", "size", "=", "self", ".", "read_size", "(", ")", "title", "=", "self", ".", "_f", ".", "readline", "(", ")", "[", ":", "-", "1", "]", "if", "self", ".", "symbols", "is", "None", ":", "symbols", "=", ...
Read a frame from the XYZ file
[ "Read", "a", "frame", "from", "the", "XYZ", "file" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/xyz.py#L99-L125
molmod/molmod
molmod/io/xyz.py
XYZReader._skip_frame
def _skip_frame(self): """Skip a single frame from the trajectory""" size = self.read_size() for i in range(size+1): line = self._f.readline() if len(line) == 0: raise StopIteration
python
def _skip_frame(self): """Skip a single frame from the trajectory""" size = self.read_size() for i in range(size+1): line = self._f.readline() if len(line) == 0: raise StopIteration
[ "def", "_skip_frame", "(", "self", ")", ":", "size", "=", "self", ".", "read_size", "(", ")", "for", "i", "in", "range", "(", "size", "+", "1", ")", ":", "line", "=", "self", ".", "_f", ".", "readline", "(", ")", "if", "len", "(", "line", ")", ...
Skip a single frame from the trajectory
[ "Skip", "a", "single", "frame", "from", "the", "trajectory" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/xyz.py#L127-L133
molmod/molmod
molmod/io/xyz.py
XYZReader.get_first_molecule
def get_first_molecule(self): """Get the first molecule from the trajectory This can be useful to configure your program before handeling the actual trajectory. """ title, coordinates = self._first molecule = Molecule(self.numbers, coordinates, title, symbols=self....
python
def get_first_molecule(self): """Get the first molecule from the trajectory This can be useful to configure your program before handeling the actual trajectory. """ title, coordinates = self._first molecule = Molecule(self.numbers, coordinates, title, symbols=self....
[ "def", "get_first_molecule", "(", "self", ")", ":", "title", ",", "coordinates", "=", "self", ".", "_first", "molecule", "=", "Molecule", "(", "self", ".", "numbers", ",", "coordinates", ",", "title", ",", "symbols", "=", "self", ".", "symbols", ")", "re...
Get the first molecule from the trajectory This can be useful to configure your program before handeling the actual trajectory.
[ "Get", "the", "first", "molecule", "from", "the", "trajectory" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/xyz.py#L135-L143
molmod/molmod
molmod/io/xyz.py
XYZWriter.dump
def dump(self, title, coordinates): """Dump a frame to the trajectory file Arguments: | ``title`` -- the title of the frame | ``coordinates`` -- a numpy array with coordinates in atomic units """ print("% 8i" % len(self.symbols), file=self._f) prin...
python
def dump(self, title, coordinates): """Dump a frame to the trajectory file Arguments: | ``title`` -- the title of the frame | ``coordinates`` -- a numpy array with coordinates in atomic units """ print("% 8i" % len(self.symbols), file=self._f) prin...
[ "def", "dump", "(", "self", ",", "title", ",", "coordinates", ")", ":", "print", "(", "\"% 8i\"", "%", "len", "(", "self", ".", "symbols", ")", ",", "file", "=", "self", ".", "_f", ")", "print", "(", "str", "(", "title", ")", ",", "file", "=", ...
Dump a frame to the trajectory file Arguments: | ``title`` -- the title of the frame | ``coordinates`` -- a numpy array with coordinates in atomic units
[ "Dump", "a", "frame", "to", "the", "trajectory", "file" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/xyz.py#L180-L190
molmod/molmod
molmod/io/xyz.py
XYZFile.get_molecule
def get_molecule(self, index=0): """Get a molecule from the trajectory Optional argument: | ``index`` -- The frame index [default=0] """ return Molecule(self.numbers, self.geometries[index], self.titles[index], symbols=self.symbols)
python
def get_molecule(self, index=0): """Get a molecule from the trajectory Optional argument: | ``index`` -- The frame index [default=0] """ return Molecule(self.numbers, self.geometries[index], self.titles[index], symbols=self.symbols)
[ "def", "get_molecule", "(", "self", ",", "index", "=", "0", ")", ":", "return", "Molecule", "(", "self", ".", "numbers", ",", "self", ".", "geometries", "[", "index", "]", ",", "self", ".", "titles", "[", "index", "]", ",", "symbols", "=", "self", ...
Get a molecule from the trajectory Optional argument: | ``index`` -- The frame index [default=0]
[ "Get", "a", "molecule", "from", "the", "trajectory" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/xyz.py#L247-L253
molmod/molmod
molmod/io/xyz.py
XYZFile.write_to_file
def write_to_file(self, f, file_unit=angstrom): """Write the trajectory to a file Argument: | ``f`` -- a filename or a file-like object to write to Optional argument: | ``file_unit`` -- the unit of the values written to file [de...
python
def write_to_file(self, f, file_unit=angstrom): """Write the trajectory to a file Argument: | ``f`` -- a filename or a file-like object to write to Optional argument: | ``file_unit`` -- the unit of the values written to file [de...
[ "def", "write_to_file", "(", "self", ",", "f", ",", "file_unit", "=", "angstrom", ")", ":", "xyz_writer", "=", "XYZWriter", "(", "f", ",", "self", ".", "symbols", ",", "file_unit", "=", "file_unit", ")", "for", "title", ",", "coordinates", "in", "zip", ...
Write the trajectory to a file Argument: | ``f`` -- a filename or a file-like object to write to Optional argument: | ``file_unit`` -- the unit of the values written to file [default=angstrom]
[ "Write", "the", "trajectory", "to", "a", "file" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/xyz.py#L255-L267
molmod/molmod
molmod/io/common.py
slice_match
def slice_match(sub, counter): """Efficiently test if counter is in ``xrange(*sub)`` Arguments: | ``sub`` -- a slice object | ``counter`` -- an integer The function returns True if the counter is in ``xrange(sub.start, sub.stop, sub.step)``. """ if sub.start is not...
python
def slice_match(sub, counter): """Efficiently test if counter is in ``xrange(*sub)`` Arguments: | ``sub`` -- a slice object | ``counter`` -- an integer The function returns True if the counter is in ``xrange(sub.start, sub.stop, sub.step)``. """ if sub.start is not...
[ "def", "slice_match", "(", "sub", ",", "counter", ")", ":", "if", "sub", ".", "start", "is", "not", "None", "and", "counter", "<", "sub", ".", "start", ":", "return", "False", "if", "sub", ".", "stop", "is", "not", "None", "and", "counter", ">=", "...
Efficiently test if counter is in ``xrange(*sub)`` Arguments: | ``sub`` -- a slice object | ``counter`` -- an integer The function returns True if the counter is in ``xrange(sub.start, sub.stop, sub.step)``.
[ "Efficiently", "test", "if", "counter", "is", "in", "xrange", "(", "*", "sub", ")" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/common.py#L38-L60
molmod/molmod
molmod/minimizer.py
check_anagrad
def check_anagrad(fun, x0, epsilon, threshold): """Check the analytical gradient using finite differences Arguments: | ``fun`` -- the function to be tested, more info below | ``x0`` -- the reference point around which the function should be tested | ``epsilo...
python
def check_anagrad(fun, x0, epsilon, threshold): """Check the analytical gradient using finite differences Arguments: | ``fun`` -- the function to be tested, more info below | ``x0`` -- the reference point around which the function should be tested | ``epsilo...
[ "def", "check_anagrad", "(", "fun", ",", "x0", ",", "epsilon", ",", "threshold", ")", ":", "N", "=", "len", "(", "x0", ")", "f0", ",", "ana_grad", "=", "fun", "(", "x0", ",", "do_gradient", "=", "True", ")", "for", "i", "in", "range", "(", "N", ...
Check the analytical gradient using finite differences Arguments: | ``fun`` -- the function to be tested, more info below | ``x0`` -- the reference point around which the function should be tested | ``epsilon`` -- a small scalar used for the finite differences...
[ "Check", "the", "analytical", "gradient", "using", "finite", "differences" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1577-L1605
molmod/molmod
molmod/minimizer.py
check_delta
def check_delta(fun, x, dxs, period=None): """Check the difference between two function values using the analytical gradient Arguments: | ``fun`` -- The function to be tested, more info below. | ``x`` -- The argument vector. | ``dxs`` -- A matrix where each row is a vector of s...
python
def check_delta(fun, x, dxs, period=None): """Check the difference between two function values using the analytical gradient Arguments: | ``fun`` -- The function to be tested, more info below. | ``x`` -- The argument vector. | ``dxs`` -- A matrix where each row is a vector of s...
[ "def", "check_delta", "(", "fun", ",", "x", ",", "dxs", ",", "period", "=", "None", ")", ":", "dn1s", "=", "[", "]", "dn2s", "=", "[", "]", "dnds", "=", "[", "]", "for", "dx", "in", "dxs", ":", "f0", ",", "grad0", "=", "fun", "(", "x", ",",...
Check the difference between two function values using the analytical gradient Arguments: | ``fun`` -- The function to be tested, more info below. | ``x`` -- The argument vector. | ``dxs`` -- A matrix where each row is a vector of small differences to be adde...
[ "Check", "the", "difference", "between", "two", "function", "values", "using", "the", "analytical", "gradient" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1608-L1675
molmod/molmod
molmod/minimizer.py
compute_fd_hessian
def compute_fd_hessian(fun, x0, epsilon, anagrad=True): """Compute the Hessian using the finite difference method Arguments: | ``fun`` -- the function for which the Hessian should be computed, more info below | ``x0`` -- the point at which the Hessian must be compu...
python
def compute_fd_hessian(fun, x0, epsilon, anagrad=True): """Compute the Hessian using the finite difference method Arguments: | ``fun`` -- the function for which the Hessian should be computed, more info below | ``x0`` -- the point at which the Hessian must be compu...
[ "def", "compute_fd_hessian", "(", "fun", ",", "x0", ",", "epsilon", ",", "anagrad", "=", "True", ")", ":", "N", "=", "len", "(", "x0", ")", "def", "compute_gradient", "(", "x", ")", ":", "if", "anagrad", ":", "return", "fun", "(", "x", ",", "do_gra...
Compute the Hessian using the finite difference method Arguments: | ``fun`` -- the function for which the Hessian should be computed, more info below | ``x0`` -- the point at which the Hessian must be computed | ``epsilon`` -- a small scalar step size used to...
[ "Compute", "the", "Hessian", "using", "the", "finite", "difference", "method" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1678-L1722
molmod/molmod
molmod/minimizer.py
ConjugateGradient.update
def update(self, gradient, step): """Update the search direction given the latest gradient and step""" do_sd = self.gradient_old is None self.gradient_old = self.gradient self.gradient = gradient if do_sd: self._update_sd() else: self._update_cg()
python
def update(self, gradient, step): """Update the search direction given the latest gradient and step""" do_sd = self.gradient_old is None self.gradient_old = self.gradient self.gradient = gradient if do_sd: self._update_sd() else: self._update_cg()
[ "def", "update", "(", "self", ",", "gradient", ",", "step", ")", ":", "do_sd", "=", "self", ".", "gradient_old", "is", "None", "self", ".", "gradient_old", "=", "self", ".", "gradient", "self", ".", "gradient", "=", "gradient", "if", "do_sd", ":", "sel...
Update the search direction given the latest gradient and step
[ "Update", "the", "search", "direction", "given", "the", "latest", "gradient", "and", "step" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L150-L158
molmod/molmod
molmod/minimizer.py
ConjugateGradient._update_cg
def _update_cg(self): """Update the conjugate gradient""" beta = self._beta() # Automatic direction reset if beta < 0: self.direction = -self.gradient self.status = "SD" else: self.direction = self.direction * beta - self.gradient s...
python
def _update_cg(self): """Update the conjugate gradient""" beta = self._beta() # Automatic direction reset if beta < 0: self.direction = -self.gradient self.status = "SD" else: self.direction = self.direction * beta - self.gradient s...
[ "def", "_update_cg", "(", "self", ")", ":", "beta", "=", "self", ".", "_beta", "(", ")", "# Automatic direction reset", "if", "beta", "<", "0", ":", "self", ".", "direction", "=", "-", "self", ".", "gradient", "self", ".", "status", "=", "\"SD\"", "els...
Update the conjugate gradient
[ "Update", "the", "conjugate", "gradient" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L168-L177
molmod/molmod
molmod/minimizer.py
QuasiNewton.update
def update(self, gradient, step): """Update the search direction given the latest gradient and step""" self.old_gradient = self.gradient self.gradient = gradient N = len(self.gradient) if self.inv_hessian is None: # update the direction self.direction = -s...
python
def update(self, gradient, step): """Update the search direction given the latest gradient and step""" self.old_gradient = self.gradient self.gradient = gradient N = len(self.gradient) if self.inv_hessian is None: # update the direction self.direction = -s...
[ "def", "update", "(", "self", ",", "gradient", ",", "step", ")", ":", "self", ".", "old_gradient", "=", "self", ".", "gradient", "self", ".", "gradient", "=", "gradient", "N", "=", "len", "(", "self", ".", "gradient", ")", "if", "self", ".", "inv_hes...
Update the search direction given the latest gradient and step
[ "Update", "the", "search", "direction", "given", "the", "latest", "gradient", "and", "step" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L200-L224
molmod/molmod
molmod/minimizer.py
LineSearch.limit_step
def limit_step(self, step): """Clip the a step within the maximum allowed range""" if self.qmax is None: return step else: return np.clip(step, -self.qmax, self.qmax)
python
def limit_step(self, step): """Clip the a step within the maximum allowed range""" if self.qmax is None: return step else: return np.clip(step, -self.qmax, self.qmax)
[ "def", "limit_step", "(", "self", ",", "step", ")", ":", "if", "self", ".", "qmax", "is", "None", ":", "return", "step", "else", ":", "return", "np", ".", "clip", "(", "step", ",", "-", "self", ".", "qmax", ",", "self", ".", "qmax", ")" ]
Clip the a step within the maximum allowed range
[ "Clip", "the", "a", "step", "within", "the", "maximum", "allowed", "range" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L251-L256
molmod/molmod
molmod/minimizer.py
GoldenLineSearch._bracket
def _bracket(self, qinit, f0, fun): """Find a bracket that does contain the minimum""" self.num_bracket = 0 qa = qinit fa = fun(qa) counter = 0 if fa >= f0: while True: self.num_bracket += 1 #print " bracket shrink" ...
python
def _bracket(self, qinit, f0, fun): """Find a bracket that does contain the minimum""" self.num_bracket = 0 qa = qinit fa = fun(qa) counter = 0 if fa >= f0: while True: self.num_bracket += 1 #print " bracket shrink" ...
[ "def", "_bracket", "(", "self", ",", "qinit", ",", "f0", ",", "fun", ")", ":", "self", ".", "num_bracket", "=", "0", "qa", "=", "qinit", "fa", "=", "fun", "(", "qa", ")", "counter", "=", "0", "if", "fa", ">=", "f0", ":", "while", "True", ":", ...
Find a bracket that does contain the minimum
[ "Find", "a", "bracket", "that", "does", "contain", "the", "minimum" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L337-L376
molmod/molmod
molmod/minimizer.py
GoldenLineSearch._golden
def _golden(self, triplet, fun): """Reduce the size of the bracket until the minimum is found""" self.num_golden = 0 (qa, fa), (qb, fb), (qc, fc) = triplet while True: self.num_golden += 1 qd = qa + (qb-qa)*phi/(1+phi) fd = fun(qd) if fd < ...
python
def _golden(self, triplet, fun): """Reduce the size of the bracket until the minimum is found""" self.num_golden = 0 (qa, fa), (qb, fb), (qc, fc) = triplet while True: self.num_golden += 1 qd = qa + (qb-qa)*phi/(1+phi) fd = fun(qd) if fd < ...
[ "def", "_golden", "(", "self", ",", "triplet", ",", "fun", ")", ":", "self", ".", "num_golden", "=", "0", "(", "qa", ",", "fa", ")", ",", "(", "qb", ",", "fb", ")", ",", "(", "qc", ",", "fc", ")", "=", "triplet", "while", "True", ":", "self",...
Reduce the size of the bracket until the minimum is found
[ "Reduce", "the", "size", "of", "the", "bracket", "until", "the", "minimum", "is", "found" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L378-L393
molmod/molmod
molmod/minimizer.py
Preconditioner.update
def update(self, counter, f, x_orig, gradient_orig): """Perform an update of the linear transformation Arguments: | ``counter`` -- the iteration counter of the minimizer | ``f`` -- the function value at ``x_orig`` | ``x_orig`` -- the unknowns in original coo...
python
def update(self, counter, f, x_orig, gradient_orig): """Perform an update of the linear transformation Arguments: | ``counter`` -- the iteration counter of the minimizer | ``f`` -- the function value at ``x_orig`` | ``x_orig`` -- the unknowns in original coo...
[ "def", "update", "(", "self", ",", "counter", ",", "f", ",", "x_orig", ",", "gradient_orig", ")", ":", "if", "counter", "-", "self", ".", "last_update", ">", "self", ".", "each", ":", "grad_rms", "=", "np", ".", "sqrt", "(", "(", "gradient_orig", "**...
Perform an update of the linear transformation Arguments: | ``counter`` -- the iteration counter of the minimizer | ``f`` -- the function value at ``x_orig`` | ``x_orig`` -- the unknowns in original coordinates | ``gradient_orig`` -- the gradient in or...
[ "Perform", "an", "update", "of", "the", "linear", "transformation" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L579-L600
molmod/molmod
molmod/minimizer.py
DiagonalPreconditioner.update
def update(self, counter, f, x_orig, gradient_orig): """Perform an update of the linear transformation Arguments: | ``counter`` -- the iteration counter of the minimizer | ``f`` -- the function value at ``x_orig`` | ``x_orig`` -- the unknowns in original coo...
python
def update(self, counter, f, x_orig, gradient_orig): """Perform an update of the linear transformation Arguments: | ``counter`` -- the iteration counter of the minimizer | ``f`` -- the function value at ``x_orig`` | ``x_orig`` -- the unknowns in original coo...
[ "def", "update", "(", "self", ",", "counter", ",", "f", ",", "x_orig", ",", "gradient_orig", ")", ":", "do_update", "=", "Preconditioner", ".", "update", "(", "self", ",", "counter", ",", "f", ",", "x_orig", ",", "gradient_orig", ")", "if", "do_update", ...
Perform an update of the linear transformation Arguments: | ``counter`` -- the iteration counter of the minimizer | ``f`` -- the function value at ``x_orig`` | ``x_orig`` -- the unknowns in original coordinates | ``gradient_orig`` -- the gradient in or...
[ "Perform", "an", "update", "of", "the", "linear", "transformation" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L655-L691
molmod/molmod
molmod/minimizer.py
FullPreconditioner.update
def update(self, counter, f, x_orig, gradient_orig): """Perform an update of the linear transformation Arguments: | ``counter`` -- the iteration counter of the minimizer | ``f`` -- the function value at ``x_orig`` | ``x_orig`` -- the unknowns in original coo...
python
def update(self, counter, f, x_orig, gradient_orig): """Perform an update of the linear transformation Arguments: | ``counter`` -- the iteration counter of the minimizer | ``f`` -- the function value at ``x_orig`` | ``x_orig`` -- the unknowns in original coo...
[ "def", "update", "(", "self", ",", "counter", ",", "f", ",", "x_orig", ",", "gradient_orig", ")", ":", "if", "Preconditioner", ".", "update", "(", "self", ",", "counter", ",", "f", ",", "x_orig", ",", "gradient_orig", ")", ":", "# determine a new precondit...
Perform an update of the linear transformation Arguments: | ``counter`` -- the iteration counter of the minimizer | ``f`` -- the function value at ``x_orig`` | ``x_orig`` -- the unknowns in original coordinates | ``gradient_orig`` -- the gradient in or...
[ "Perform", "an", "update", "of", "the", "linear", "transformation" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L740-L762
molmod/molmod
molmod/minimizer.py
FullPreconditioner.do
def do(self, x_orig): """Transform the unknowns to preconditioned coordinates This method also transforms the gradient to original coordinates """ if self.scales is None: return x_orig else: return np.dot(self.rotation.transpose(), x_orig)*self.scales
python
def do(self, x_orig): """Transform the unknowns to preconditioned coordinates This method also transforms the gradient to original coordinates """ if self.scales is None: return x_orig else: return np.dot(self.rotation.transpose(), x_orig)*self.scales
[ "def", "do", "(", "self", ",", "x_orig", ")", ":", "if", "self", ".", "scales", "is", "None", ":", "return", "x_orig", "else", ":", "return", "np", ".", "dot", "(", "self", ".", "rotation", ".", "transpose", "(", ")", ",", "x_orig", ")", "*", "se...
Transform the unknowns to preconditioned coordinates This method also transforms the gradient to original coordinates
[ "Transform", "the", "unknowns", "to", "preconditioned", "coordinates" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L764-L772
molmod/molmod
molmod/minimizer.py
FullPreconditioner.undo
def undo(self, x_prec): """Transform the unknowns to original coordinates This method also transforms the gradient to preconditioned coordinates """ if self.scales is None: return x_prec else: return np.dot(self.rotation, x_prec/self.scales)
python
def undo(self, x_prec): """Transform the unknowns to original coordinates This method also transforms the gradient to preconditioned coordinates """ if self.scales is None: return x_prec else: return np.dot(self.rotation, x_prec/self.scales)
[ "def", "undo", "(", "self", ",", "x_prec", ")", ":", "if", "self", ".", "scales", "is", "None", ":", "return", "x_prec", "else", ":", "return", "np", ".", "dot", "(", "self", ".", "rotation", ",", "x_prec", "/", "self", ".", "scales", ")" ]
Transform the unknowns to original coordinates This method also transforms the gradient to preconditioned coordinates
[ "Transform", "the", "unknowns", "to", "original", "coordinates" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L774-L782
molmod/molmod
molmod/minimizer.py
ConvergenceCondition.get_header
def get_header(self): """Returns the header for screen logging of the minimization""" result = " " if self.step_rms is not None: result += " Step RMS" if self.step_max is not None: result += " Step MAX" if self.grad_rms is not None: resul...
python
def get_header(self): """Returns the header for screen logging of the minimization""" result = " " if self.step_rms is not None: result += " Step RMS" if self.step_max is not None: result += " Step MAX" if self.grad_rms is not None: resul...
[ "def", "get_header", "(", "self", ")", ":", "result", "=", "\" \"", "if", "self", ".", "step_rms", "is", "not", "None", ":", "result", "+=", "\" Step RMS\"", "if", "self", ".", "step_max", "is", "not", "None", ":", "result", "+=", "\" Step MAX\"", ...
Returns the header for screen logging of the minimization
[ "Returns", "the", "header", "for", "screen", "logging", "of", "the", "minimization" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L820-L835
molmod/molmod
molmod/minimizer.py
LineWrapper.configure
def configure(self, x0, axis): """Configure the 1D function for a line search Arguments: x0 -- the reference point (q=0) axis -- a unit vector in the direction of the line search """ self.x0 = x0 self.axis = axis
python
def configure(self, x0, axis): """Configure the 1D function for a line search Arguments: x0 -- the reference point (q=0) axis -- a unit vector in the direction of the line search """ self.x0 = x0 self.axis = axis
[ "def", "configure", "(", "self", ",", "x0", ",", "axis", ")", ":", "self", ".", "x0", "=", "x0", "self", ".", "axis", "=", "axis" ]
Configure the 1D function for a line search Arguments: x0 -- the reference point (q=0) axis -- a unit vector in the direction of the line search
[ "Configure", "the", "1D", "function", "for", "a", "line", "search" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L958-L966
molmod/molmod
molmod/minimizer.py
Constraints._compute_equations
def _compute_equations(self, x, verbose=False): '''Compute the values and the normals (gradients) of active constraints. Arguments: | ``x`` -- The unknowns. ''' # compute the error and the normals. normals = [] values = [] signs = [] error ...
python
def _compute_equations(self, x, verbose=False): '''Compute the values and the normals (gradients) of active constraints. Arguments: | ``x`` -- The unknowns. ''' # compute the error and the normals. normals = [] values = [] signs = [] error ...
[ "def", "_compute_equations", "(", "self", ",", "x", ",", "verbose", "=", "False", ")", ":", "# compute the error and the normals.", "normals", "=", "[", "]", "values", "=", "[", "]", "signs", "=", "[", "]", "error", "=", "0.0", "if", "verbose", ":", "pri...
Compute the values and the normals (gradients) of active constraints. Arguments: | ``x`` -- The unknowns.
[ "Compute", "the", "values", "and", "the", "normals", "(", "gradients", ")", "of", "active", "constraints", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1073-L1113
molmod/molmod
molmod/minimizer.py
Constraints._rough_shake
def _rough_shake(self, x, normals, values, error): '''Take a robust, but not very efficient step towards the constraints. Arguments: | ``x`` -- The unknowns. | ``normals`` -- A numpy array with the gradients of the active constraints. Each row is ...
python
def _rough_shake(self, x, normals, values, error): '''Take a robust, but not very efficient step towards the constraints. Arguments: | ``x`` -- The unknowns. | ``normals`` -- A numpy array with the gradients of the active constraints. Each row is ...
[ "def", "_rough_shake", "(", "self", ",", "x", ",", "normals", ",", "values", ",", "error", ")", ":", "counter", "=", "0", "while", "error", ">", "self", ".", "threshold", "and", "counter", "<", "self", ".", "max_iter", ":", "dxs", "=", "[", "]", "f...
Take a robust, but not very efficient step towards the constraints. Arguments: | ``x`` -- The unknowns. | ``normals`` -- A numpy array with the gradients of the active constraints. Each row is one gradient. | ``values`` -- A numpy array with t...
[ "Take", "a", "robust", "but", "not", "very", "efficient", "step", "towards", "the", "constraints", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1115-L1138
molmod/molmod
molmod/minimizer.py
Constraints._fast_shake
def _fast_shake(self, x, normals, values, error): '''Take an efficient (not always robust) step towards the constraints. Arguments: | ``x`` -- The unknowns. | ``normals`` -- A numpy array with the gradients of the active constraints. Each row is o...
python
def _fast_shake(self, x, normals, values, error): '''Take an efficient (not always robust) step towards the constraints. Arguments: | ``x`` -- The unknowns. | ``normals`` -- A numpy array with the gradients of the active constraints. Each row is o...
[ "def", "_fast_shake", "(", "self", ",", "x", ",", "normals", ",", "values", ",", "error", ")", ":", "# filter out the degrees of freedom that do not feel the constraints.", "mask", "=", "(", "normals", "!=", "0", ")", ".", "any", "(", "axis", "=", "0", ")", ...
Take an efficient (not always robust) step towards the constraints. Arguments: | ``x`` -- The unknowns. | ``normals`` -- A numpy array with the gradients of the active constraints. Each row is one gradient. | ``values`` -- A numpy array with t...
[ "Take", "an", "efficient", "(", "not", "always", "robust", ")", "step", "towards", "the", "constraints", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1140-L1190
molmod/molmod
molmod/minimizer.py
Constraints.free_shake
def free_shake(self, x): '''Brings unknowns to the constraints. Arguments: | ``x`` -- The unknowns. ''' self.lock[:] = False normals, values, error = self._compute_equations(x)[:-1] counter = 0 while True: if error <= self.threshold: ...
python
def free_shake(self, x): '''Brings unknowns to the constraints. Arguments: | ``x`` -- The unknowns. ''' self.lock[:] = False normals, values, error = self._compute_equations(x)[:-1] counter = 0 while True: if error <= self.threshold: ...
[ "def", "free_shake", "(", "self", ",", "x", ")", ":", "self", ".", "lock", "[", ":", "]", "=", "False", "normals", ",", "values", ",", "error", "=", "self", ".", "_compute_equations", "(", "x", ")", "[", ":", "-", "1", "]", "counter", "=", "0", ...
Brings unknowns to the constraints. Arguments: | ``x`` -- The unknowns.
[ "Brings", "unknowns", "to", "the", "constraints", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1193-L1218
molmod/molmod
molmod/minimizer.py
Constraints.safe_shake
def safe_shake(self, x, fun, fmax): '''Brings unknowns to the constraints, without increasing fun above fmax. Arguments: | ``x`` -- The unknowns. | ``fun`` -- The function being minimized. | ``fmax`` -- The highest allowed value of the function being ...
python
def safe_shake(self, x, fun, fmax): '''Brings unknowns to the constraints, without increasing fun above fmax. Arguments: | ``x`` -- The unknowns. | ``fun`` -- The function being minimized. | ``fmax`` -- The highest allowed value of the function being ...
[ "def", "safe_shake", "(", "self", ",", "x", ",", "fun", ",", "fmax", ")", ":", "self", ".", "lock", "[", ":", "]", "=", "False", "def", "extra_equation", "(", "xx", ")", ":", "f", ",", "g", "=", "fun", "(", "xx", ",", "do_gradient", "=", "True"...
Brings unknowns to the constraints, without increasing fun above fmax. Arguments: | ``x`` -- The unknowns. | ``fun`` -- The function being minimized. | ``fmax`` -- The highest allowed value of the function being minimized. The functio...
[ "Brings", "unknowns", "to", "the", "constraints", "without", "increasing", "fun", "above", "fmax", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1220-L1244
molmod/molmod
molmod/minimizer.py
Constraints.project
def project(self, x, vector): '''Project a vector (gradient or direction) on the active constraints. Arguments: | ``x`` -- The unknowns. | ``vector`` -- A numpy array with a direction or a gradient. The return value is a gradient or direction, where the components...
python
def project(self, x, vector): '''Project a vector (gradient or direction) on the active constraints. Arguments: | ``x`` -- The unknowns. | ``vector`` -- A numpy array with a direction or a gradient. The return value is a gradient or direction, where the components...
[ "def", "project", "(", "self", ",", "x", ",", "vector", ")", ":", "scale", "=", "np", ".", "linalg", ".", "norm", "(", "vector", ")", "if", "scale", "==", "0.0", ":", "return", "vector", "self", ".", "lock", "[", ":", "]", "=", "False", "normals"...
Project a vector (gradient or direction) on the active constraints. Arguments: | ``x`` -- The unknowns. | ``vector`` -- A numpy array with a direction or a gradient. The return value is a gradient or direction, where the components that point away from the cons...
[ "Project", "a", "vector", "(", "gradient", "or", "direction", ")", "on", "the", "active", "constraints", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1246-L1299
molmod/molmod
molmod/minimizer.py
Minimizer.get_final
def get_final(self): """Return the final solution in the original coordinates""" if self.prec is None: return self.x else: return self.prec.undo(self.x)
python
def get_final(self): """Return the final solution in the original coordinates""" if self.prec is None: return self.x else: return self.prec.undo(self.x)
[ "def", "get_final", "(", "self", ")", ":", "if", "self", ".", "prec", "is", "None", ":", "return", "self", ".", "x", "else", ":", "return", "self", ".", "prec", ".", "undo", "(", "self", ".", "x", ")" ]
Return the final solution in the original coordinates
[ "Return", "the", "final", "solution", "in", "the", "original", "coordinates" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1388-L1393
molmod/molmod
molmod/minimizer.py
Minimizer._run
def _run(self): """Run the iterative optimizer""" success = self.initialize() while success is None: success = self.propagate() return success
python
def _run(self): """Run the iterative optimizer""" success = self.initialize() while success is None: success = self.propagate() return success
[ "def", "_run", "(", "self", ")", ":", "success", "=", "self", ".", "initialize", "(", ")", "while", "success", "is", "None", ":", "success", "=", "self", ".", "propagate", "(", ")", "return", "success" ]
Run the iterative optimizer
[ "Run", "the", "iterative", "optimizer" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1395-L1400
molmod/molmod
molmod/minimizer.py
Minimizer._print_header
def _print_header(self): """Print the header for screen logging""" header = " Iter Dir " if self.constraints is not None: header += ' SC CC' header += " Function" if self.convergence_condition is not None: header += self.convergence_condition.ge...
python
def _print_header(self): """Print the header for screen logging""" header = " Iter Dir " if self.constraints is not None: header += ' SC CC' header += " Function" if self.convergence_condition is not None: header += self.convergence_condition.ge...
[ "def", "_print_header", "(", "self", ")", ":", "header", "=", "\" Iter Dir \"", "if", "self", ".", "constraints", "is", "not", "None", ":", "header", "+=", "' SC CC'", "header", "+=", "\" Function\"", "if", "self", ".", "convergence_condition", "is", ...
Print the header for screen logging
[ "Print", "the", "header", "for", "screen", "logging" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1503-L1514
molmod/molmod
molmod/minimizer.py
Minimizer._screen
def _screen(self, s, newline=False): """Print something on screen when self.verbose == True""" if self.verbose: if newline: print(s) else: print(s, end=' ')
python
def _screen(self, s, newline=False): """Print something on screen when self.verbose == True""" if self.verbose: if newline: print(s) else: print(s, end=' ')
[ "def", "_screen", "(", "self", ",", "s", ",", "newline", "=", "False", ")", ":", "if", "self", ".", "verbose", ":", "if", "newline", ":", "print", "(", "s", ")", "else", ":", "print", "(", "s", ",", "end", "=", "' '", ")" ]
Print something on screen when self.verbose == True
[ "Print", "something", "on", "screen", "when", "self", ".", "verbose", "==", "True" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1516-L1522
molmod/molmod
molmod/minimizer.py
Minimizer._line_opt
def _line_opt(self): """Perform a line search along the current direction""" direction = self.search_direction.direction if self.constraints is not None: try: direction = self.constraints.project(self.x, direction) except ConstraintError: s...
python
def _line_opt(self): """Perform a line search along the current direction""" direction = self.search_direction.direction if self.constraints is not None: try: direction = self.constraints.project(self.x, direction) except ConstraintError: s...
[ "def", "_line_opt", "(", "self", ")", ":", "direction", "=", "self", ".", "search_direction", ".", "direction", "if", "self", ".", "constraints", "is", "not", "None", ":", "try", ":", "direction", "=", "self", ".", "constraints", ".", "project", "(", "se...
Perform a line search along the current direction
[ "Perform", "a", "line", "search", "along", "the", "current", "direction" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/minimizer.py#L1524-L1570
molmod/molmod
molmod/graphs.py
Graph.edge_index
def edge_index(self): """A map to look up the index of a edge""" return dict((edge, index) for index, edge in enumerate(self.edges))
python
def edge_index(self): """A map to look up the index of a edge""" return dict((edge, index) for index, edge in enumerate(self.edges))
[ "def", "edge_index", "(", "self", ")", ":", "return", "dict", "(", "(", "edge", ",", "index", ")", "for", "index", ",", "edge", "in", "enumerate", "(", "self", ".", "edges", ")", ")" ]
A map to look up the index of a edge
[ "A", "map", "to", "look", "up", "the", "index", "of", "a", "edge" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L196-L198
molmod/molmod
molmod/graphs.py
Graph.neighbors
def neighbors(self): """A dictionary with neighbors The dictionary will have the following form: ``{vertexX: (vertexY1, vertexY2, ...), ...}`` This means that vertexX and vertexY1 are connected etc. This also implies that the following elements are part of the dictio...
python
def neighbors(self): """A dictionary with neighbors The dictionary will have the following form: ``{vertexX: (vertexY1, vertexY2, ...), ...}`` This means that vertexX and vertexY1 are connected etc. This also implies that the following elements are part of the dictio...
[ "def", "neighbors", "(", "self", ")", ":", "neighbors", "=", "dict", "(", "(", "vertex", ",", "[", "]", ")", "for", "vertex", "in", "range", "(", "self", ".", "num_vertices", ")", ")", "for", "a", ",", "b", "in", "self", ".", "edges", ":", "neigh...
A dictionary with neighbors The dictionary will have the following form: ``{vertexX: (vertexY1, vertexY2, ...), ...}`` This means that vertexX and vertexY1 are connected etc. This also implies that the following elements are part of the dictionary: ``{vertexY1: (v...
[ "A", "dictionary", "with", "neighbors" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L201-L219
molmod/molmod
molmod/graphs.py
Graph.distances
def distances(self): """The matrix with the all-pairs shortest path lenghts""" from molmod.ext import graphs_floyd_warshall distances = np.zeros((self.num_vertices,)*2, dtype=int) #distances[:] = -1 # set all -1, which is just a very big integer #distances.ravel()[::len(distances...
python
def distances(self): """The matrix with the all-pairs shortest path lenghts""" from molmod.ext import graphs_floyd_warshall distances = np.zeros((self.num_vertices,)*2, dtype=int) #distances[:] = -1 # set all -1, which is just a very big integer #distances.ravel()[::len(distances...
[ "def", "distances", "(", "self", ")", ":", "from", "molmod", ".", "ext", "import", "graphs_floyd_warshall", "distances", "=", "np", ".", "zeros", "(", "(", "self", ".", "num_vertices", ",", ")", "*", "2", ",", "dtype", "=", "int", ")", "#distances[:] = -...
The matrix with the all-pairs shortest path lenghts
[ "The", "matrix", "with", "the", "all", "-", "pairs", "shortest", "path", "lenghts" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L222-L232
molmod/molmod
molmod/graphs.py
Graph.central_vertices
def central_vertices(self): """Vertices that have the lowest maximum distance to any other vertex""" max_distances = self.distances.max(0) max_distances_min = max_distances[max_distances > 0].min() return (max_distances == max_distances_min).nonzero()[0]
python
def central_vertices(self): """Vertices that have the lowest maximum distance to any other vertex""" max_distances = self.distances.max(0) max_distances_min = max_distances[max_distances > 0].min() return (max_distances == max_distances_min).nonzero()[0]
[ "def", "central_vertices", "(", "self", ")", ":", "max_distances", "=", "self", ".", "distances", ".", "max", "(", "0", ")", "max_distances_min", "=", "max_distances", "[", "max_distances", ">", "0", "]", ".", "min", "(", ")", "return", "(", "max_distances...
Vertices that have the lowest maximum distance to any other vertex
[ "Vertices", "that", "have", "the", "lowest", "maximum", "distance", "to", "any", "other", "vertex" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L243-L247
molmod/molmod
molmod/graphs.py
Graph.independent_vertices
def independent_vertices(self): """Lists of vertices that are only interconnected within each list This means that there is no path from a vertex in one list to a vertex in another list. In case of a molecular graph, this would yield the atoms that belong to individual molecule...
python
def independent_vertices(self): """Lists of vertices that are only interconnected within each list This means that there is no path from a vertex in one list to a vertex in another list. In case of a molecular graph, this would yield the atoms that belong to individual molecule...
[ "def", "independent_vertices", "(", "self", ")", ":", "candidates", "=", "set", "(", "range", "(", "self", ".", "num_vertices", ")", ")", "result", "=", "[", "]", "while", "len", "(", "candidates", ")", ">", "0", ":", "pivot", "=", "candidates", ".", ...
Lists of vertices that are only interconnected within each list This means that there is no path from a vertex in one list to a vertex in another list. In case of a molecular graph, this would yield the atoms that belong to individual molecules.
[ "Lists", "of", "vertices", "that", "are", "only", "interconnected", "within", "each", "list" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L259-L280
molmod/molmod
molmod/graphs.py
Graph.fingerprint
def fingerprint(self): """A total graph fingerprint The result is invariant under permutation of the vertex indexes. The chance that two different (molecular) graphs yield the same fingerprint is small but not zero. (See unit tests.)""" if self.num_vertices == 0: ...
python
def fingerprint(self): """A total graph fingerprint The result is invariant under permutation of the vertex indexes. The chance that two different (molecular) graphs yield the same fingerprint is small but not zero. (See unit tests.)""" if self.num_vertices == 0: ...
[ "def", "fingerprint", "(", "self", ")", ":", "if", "self", ".", "num_vertices", "==", "0", ":", "return", "np", ".", "zeros", "(", "20", ",", "np", ".", "ubyte", ")", "else", ":", "return", "sum", "(", "self", ".", "vertex_fingerprints", ")" ]
A total graph fingerprint The result is invariant under permutation of the vertex indexes. The chance that two different (molecular) graphs yield the same fingerprint is small but not zero. (See unit tests.)
[ "A", "total", "graph", "fingerprint" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L283-L292
molmod/molmod
molmod/graphs.py
Graph.vertex_fingerprints
def vertex_fingerprints(self): """A fingerprint for each vertex The result is invariant under permutation of the vertex indexes. Vertices that are symmetrically equivalent will get the same fingerprint, e.g. the hydrogens in methane would get the same fingerprint. ...
python
def vertex_fingerprints(self): """A fingerprint for each vertex The result is invariant under permutation of the vertex indexes. Vertices that are symmetrically equivalent will get the same fingerprint, e.g. the hydrogens in methane would get the same fingerprint. ...
[ "def", "vertex_fingerprints", "(", "self", ")", ":", "return", "self", ".", "get_vertex_fingerprints", "(", "[", "self", ".", "get_vertex_string", "(", "i", ")", "for", "i", "in", "range", "(", "self", ".", "num_vertices", ")", "]", ",", "[", "self", "."...
A fingerprint for each vertex The result is invariant under permutation of the vertex indexes. Vertices that are symmetrically equivalent will get the same fingerprint, e.g. the hydrogens in methane would get the same fingerprint.
[ "A", "fingerprint", "for", "each", "vertex" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L295-L306
molmod/molmod
molmod/graphs.py
Graph.equivalent_vertices
def equivalent_vertices(self): """A dictionary with symmetrically equivalent vertices.""" level1 = {} for i, row in enumerate(self.vertex_fingerprints): key = row.tobytes() l = level1.get(key) if l is None: l = set([i]) level1[k...
python
def equivalent_vertices(self): """A dictionary with symmetrically equivalent vertices.""" level1 = {} for i, row in enumerate(self.vertex_fingerprints): key = row.tobytes() l = level1.get(key) if l is None: l = set([i]) level1[k...
[ "def", "equivalent_vertices", "(", "self", ")", ":", "level1", "=", "{", "}", "for", "i", ",", "row", "in", "enumerate", "(", "self", ".", "vertex_fingerprints", ")", ":", "key", "=", "row", ".", "tobytes", "(", ")", "l", "=", "level1", ".", "get", ...
A dictionary with symmetrically equivalent vertices.
[ "A", "dictionary", "with", "symmetrically", "equivalent", "vertices", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L309-L324
molmod/molmod
molmod/graphs.py
Graph.symmetries
def symmetries(self): """Graph symmetries (permutations) that map the graph onto itself.""" symmetry_cycles = set([]) symmetries = set([]) for match in GraphSearch(EqualPattern(self))(self): match.cycles = match.get_closed_cycles() if match.cycles in symmetry_cyc...
python
def symmetries(self): """Graph symmetries (permutations) that map the graph onto itself.""" symmetry_cycles = set([]) symmetries = set([]) for match in GraphSearch(EqualPattern(self))(self): match.cycles = match.get_closed_cycles() if match.cycles in symmetry_cyc...
[ "def", "symmetries", "(", "self", ")", ":", "symmetry_cycles", "=", "set", "(", "[", "]", ")", "symmetries", "=", "set", "(", "[", "]", ")", "for", "match", "in", "GraphSearch", "(", "EqualPattern", "(", "self", ")", ")", "(", "self", ")", ":", "ma...
Graph symmetries (permutations) that map the graph onto itself.
[ "Graph", "symmetries", "(", "permutations", ")", "that", "map", "the", "graph", "onto", "itself", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L327-L338
molmod/molmod
molmod/graphs.py
Graph.symmetry_cycles
def symmetry_cycles(self): """The cycle representations of the graph symmetries""" result = set([]) for symmetry in self.symmetries: result.add(symmetry.cycles) return result
python
def symmetry_cycles(self): """The cycle representations of the graph symmetries""" result = set([]) for symmetry in self.symmetries: result.add(symmetry.cycles) return result
[ "def", "symmetry_cycles", "(", "self", ")", ":", "result", "=", "set", "(", "[", "]", ")", "for", "symmetry", "in", "self", ".", "symmetries", ":", "result", ".", "add", "(", "symmetry", ".", "cycles", ")", "return", "result" ]
The cycle representations of the graph symmetries
[ "The", "cycle", "representations", "of", "the", "graph", "symmetries" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L341-L346
molmod/molmod
molmod/graphs.py
Graph.canonical_order
def canonical_order(self): """The vertices in a canonical or normalized order. This routine will return a list of vertices in an order that does not depend on the initial order, but only depends on the connectivity and the return values of the function self.get_vertex_string. ...
python
def canonical_order(self): """The vertices in a canonical or normalized order. This routine will return a list of vertices in an order that does not depend on the initial order, but only depends on the connectivity and the return values of the function self.get_vertex_string. ...
[ "def", "canonical_order", "(", "self", ")", ":", "# A) find an appropriate starting vertex.", "# Here we take a central vertex that has a minimal number of symmetrical", "# equivalents, 'the highest atom number', and the highest fingerprint.", "# Note that the symmetrical equivalents are computed ...
The vertices in a canonical or normalized order. This routine will return a list of vertices in an order that does not depend on the initial order, but only depends on the connectivity and the return values of the function self.get_vertex_string. Only the vertices that are ...
[ "The", "vertices", "in", "a", "canonical", "or", "normalized", "order", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L349-L426
molmod/molmod
molmod/graphs.py
Graph.iter_breadth_first
def iter_breadth_first(self, start=None, do_paths=False, do_duplicates=False): """Iterate over the vertices with the breadth first algorithm. See http://en.wikipedia.org/wiki/Breadth-first_search for more info. If not start vertex is given, the central vertex is taken. By defa...
python
def iter_breadth_first(self, start=None, do_paths=False, do_duplicates=False): """Iterate over the vertices with the breadth first algorithm. See http://en.wikipedia.org/wiki/Breadth-first_search for more info. If not start vertex is given, the central vertex is taken. By defa...
[ "def", "iter_breadth_first", "(", "self", ",", "start", "=", "None", ",", "do_paths", "=", "False", ",", "do_duplicates", "=", "False", ")", ":", "if", "start", "is", "None", ":", "start", "=", "self", ".", "central_vertex", "else", ":", "try", ":", "s...
Iterate over the vertices with the breadth first algorithm. See http://en.wikipedia.org/wiki/Breadth-first_search for more info. If not start vertex is given, the central vertex is taken. By default, the distance to the starting vertex is also computed. If the path to the s...
[ "Iterate", "over", "the", "vertices", "with", "the", "breadth", "first", "algorithm", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L430-L481
molmod/molmod
molmod/graphs.py
Graph.iter_breadth_first_edges
def iter_breadth_first_edges(self, start=None): """Iterate over the edges with the breadth first convention. We need this for the pattern matching algorithms, but a quick look at Wikipedia did not result in a known and named algorithm. The edges are yielded one by one, togethe...
python
def iter_breadth_first_edges(self, start=None): """Iterate over the edges with the breadth first convention. We need this for the pattern matching algorithms, but a quick look at Wikipedia did not result in a known and named algorithm. The edges are yielded one by one, togethe...
[ "def", "iter_breadth_first_edges", "(", "self", ",", "start", "=", "None", ")", ":", "if", "start", "is", "None", ":", "start", "=", "self", ".", "central_vertex", "else", ":", "try", ":", "start", "=", "int", "(", "start", ")", "except", "ValueError", ...
Iterate over the edges with the breadth first convention. We need this for the pattern matching algorithms, but a quick look at Wikipedia did not result in a known and named algorithm. The edges are yielded one by one, together with the distance of the edge from the startin...
[ "Iterate", "over", "the", "edges", "with", "the", "breadth", "first", "convention", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L495-L536
molmod/molmod
molmod/graphs.py
Graph.get_subgraph
def get_subgraph(self, subvertices, normalize=False): """Constructs a subgraph of the current graph Arguments: | ``subvertices`` -- The vertices that should be retained. | ``normalize`` -- Whether or not the vertices should renumbered and reduced to the given...
python
def get_subgraph(self, subvertices, normalize=False): """Constructs a subgraph of the current graph Arguments: | ``subvertices`` -- The vertices that should be retained. | ``normalize`` -- Whether or not the vertices should renumbered and reduced to the given...
[ "def", "get_subgraph", "(", "self", ",", "subvertices", ",", "normalize", "=", "False", ")", ":", "if", "normalize", ":", "revorder", "=", "dict", "(", "(", "j", ",", "i", ")", "for", "i", ",", "j", "in", "enumerate", "(", "subvertices", ")", ")", ...
Constructs a subgraph of the current graph Arguments: | ``subvertices`` -- The vertices that should be retained. | ``normalize`` -- Whether or not the vertices should renumbered and reduced to the given set of subvertices. When True, also the edges a...
[ "Constructs", "a", "subgraph", "of", "the", "current", "graph" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L538-L604
molmod/molmod
molmod/graphs.py
Graph.get_vertex_fingerprints
def get_vertex_fingerprints(self, vertex_strings, edge_strings, num_iter=None): """Return an array with fingerprints for each vertex""" import hashlib def str2array(x): """convert a hash string to a numpy array of bytes""" if len(x) == 0: return np.zeros(0...
python
def get_vertex_fingerprints(self, vertex_strings, edge_strings, num_iter=None): """Return an array with fingerprints for each vertex""" import hashlib def str2array(x): """convert a hash string to a numpy array of bytes""" if len(x) == 0: return np.zeros(0...
[ "def", "get_vertex_fingerprints", "(", "self", ",", "vertex_strings", ",", "edge_strings", ",", "num_iter", "=", "None", ")", ":", "import", "hashlib", "def", "str2array", "(", "x", ")", ":", "\"\"\"convert a hash string to a numpy array of bytes\"\"\"", "if", "len", ...
Return an array with fingerprints for each vertex
[ "Return", "an", "array", "with", "fingerprints", "for", "each", "vertex" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L606-L640
molmod/molmod
molmod/graphs.py
Graph.get_halfs
def get_halfs(self, vertex1, vertex2): """Split the graph in two halfs by cutting the edge: vertex1-vertex2 If this is not possible (due to loops connecting both ends), a GraphError is raised. Returns the vertices in both halfs. """ def grow(origin, other): ...
python
def get_halfs(self, vertex1, vertex2): """Split the graph in two halfs by cutting the edge: vertex1-vertex2 If this is not possible (due to loops connecting both ends), a GraphError is raised. Returns the vertices in both halfs. """ def grow(origin, other): ...
[ "def", "get_halfs", "(", "self", ",", "vertex1", ",", "vertex2", ")", ":", "def", "grow", "(", "origin", ",", "other", ")", ":", "frontier", "=", "set", "(", "self", ".", "neighbors", "[", "origin", "]", ")", "frontier", ".", "discard", "(", "other",...
Split the graph in two halfs by cutting the edge: vertex1-vertex2 If this is not possible (due to loops connecting both ends), a GraphError is raised. Returns the vertices in both halfs.
[ "Split", "the", "graph", "in", "two", "halfs", "by", "cutting", "the", "edge", ":", "vertex1", "-", "vertex2" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L642-L667
molmod/molmod
molmod/graphs.py
Graph.get_part
def get_part(self, vertex_in, vertices_border): """List all vertices that are connected to vertex_in, but are not included in or 'behind' vertices_border. """ vertices_new = set(self.neighbors[vertex_in]) vertices_part = set([vertex_in]) while len(vertices_new) > 0: ...
python
def get_part(self, vertex_in, vertices_border): """List all vertices that are connected to vertex_in, but are not included in or 'behind' vertices_border. """ vertices_new = set(self.neighbors[vertex_in]) vertices_part = set([vertex_in]) while len(vertices_new) > 0: ...
[ "def", "get_part", "(", "self", ",", "vertex_in", ",", "vertices_border", ")", ":", "vertices_new", "=", "set", "(", "self", ".", "neighbors", "[", "vertex_in", "]", ")", "vertices_part", "=", "set", "(", "[", "vertex_in", "]", ")", "while", "len", "(", ...
List all vertices that are connected to vertex_in, but are not included in or 'behind' vertices_border.
[ "List", "all", "vertices", "that", "are", "connected", "to", "vertex_in", "but", "are", "not", "included", "in", "or", "behind", "vertices_border", "." ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L669-L685
molmod/molmod
molmod/graphs.py
Graph.get_halfs_double
def get_halfs_double(self, vertex_a1, vertex_b1, vertex_a2, vertex_b2): """Compute the two parts separated by ``(vertex_a1, vertex_b1)`` and ``(vertex_a2, vertex_b2)`` Raise a GraphError when ``(vertex_a1, vertex_b1)`` and ``(vertex_a2, vertex_b2)`` do not separate the graph in two ...
python
def get_halfs_double(self, vertex_a1, vertex_b1, vertex_a2, vertex_b2): """Compute the two parts separated by ``(vertex_a1, vertex_b1)`` and ``(vertex_a2, vertex_b2)`` Raise a GraphError when ``(vertex_a1, vertex_b1)`` and ``(vertex_a2, vertex_b2)`` do not separate the graph in two ...
[ "def", "get_halfs_double", "(", "self", ",", "vertex_a1", ",", "vertex_b1", ",", "vertex_a2", ",", "vertex_b2", ")", ":", "if", "vertex_a1", "not", "in", "self", ".", "neighbors", "[", "vertex_b1", "]", ":", "raise", "GraphError", "(", "\"vertex_a1 must be a n...
Compute the two parts separated by ``(vertex_a1, vertex_b1)`` and ``(vertex_a2, vertex_b2)`` Raise a GraphError when ``(vertex_a1, vertex_b1)`` and ``(vertex_a2, vertex_b2)`` do not separate the graph in two disconnected parts. The edges must be neighbors. If not a GraphError ...
[ "Compute", "the", "two", "parts", "separated", "by", "(", "vertex_a1", "vertex_b1", ")", "and", "(", "vertex_a2", "vertex_b2", ")" ]
train
https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/graphs.py#L687-L780