_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
31
13.1k
language
stringclasses
1 value
meta_information
dict
q257700
ContentExtractor.get_siblings_content
validation
def get_siblings_content(self, current_sibling, baselinescore_siblings_para): """ adds any siblings that may have a decent score to this node """ if current_sibling.tag == 'p' and self.parser.getText(current_sibling): tmp = current_sibling if tmp.tail: tmp = deepcopy(tmp) tmp.tail = '' return [tmp] else: potential_paragraphs = self.parser.getElementsByTag(current_sibling, tag='p') if potential_paragraphs is None: return None
python
{ "resource": "" }
q257701
ContentExtractor.is_highlink_density
validation
def is_highlink_density(self, element): """ checks the density of links within a node, is there not much text and most of it contains linky shit? if so it's no good """ links = self.parser.getElementsByTag(element, tag='a') if not links: return False text = self.parser.getText(element) words = text.split(' ') words_number = float(len(words)) link_text_parts = [] for link in links: link_text_parts.append(self.parser.getText(link)) link_text = ''.join(link_text_parts) link_words = link_text.split('
python
{ "resource": "" }
q257702
ContentExtractor.nodes_to_check
validation
def nodes_to_check(self, docs): """\ returns a list of nodes we want to search on like paragraphs and tables """ nodes_to_check = [] for doc in docs: for tag in ['p', 'pre', 'td']:
python
{ "resource": "" }
q257703
ContentExtractor.post_cleanup
validation
def post_cleanup(self): """\ remove any divs that looks like non-content, clusters of links, or paras with no gusto """ parse_tags = ['p'] if self.config.parse_lists: parse_tags.extend(['ul', 'ol']) if self.config.parse_headers: parse_tags.extend(['h1', 'h2', 'h3', 'h4', 'h5',
python
{ "resource": "" }
q257704
TitleExtractor.get_title
validation
def get_title(self): """\ Fetch the article title and analyze it """ title = '' # rely on opengraph in case we have the data if "title" in list(self.article.opengraph.keys()): return self.clean_title(self.article.opengraph['title']) elif self.article.schema and "headline" in self.article.schema: return self.clean_title(self.article.schema['headline']) # try to fetch the meta headline meta_headline = self.parser.getElementsByTag(self.article.doc, tag="meta", attr="name",
python
{ "resource": "" }
q257705
MetasExtractor.get_canonical_link
validation
def get_canonical_link(self): """ if the article has meta canonical link set in the url """ if self.article.final_url: kwargs = {'tag': 'link', 'attr': 'rel', 'value': 'canonical'} meta = self.parser.getElementsByTag(self.article.doc, **kwargs) if meta is not None and len(meta) > 0: href = self.parser.getAttribute(meta[0], 'href') if href: href = href.strip()
python
{ "resource": "" }
q257706
Goose.close
validation
def close(self): ''' Close the network connection and perform any other required cleanup Note: Auto closed when using goose as a context manager or when garbage collected '''
python
{ "resource": "" }
q257707
Goose.extract
validation
def extract(self, url=None, raw_html=None): ''' Extract the most likely article content from the html page Args: url (str): URL to pull and parse raw_html (str): String representation of the HTML page Returns: Article:
python
{ "resource": "" }
q257708
Goose.__crawl
validation
def __crawl(self, crawl_candidate): ''' wrap the crawling functionality ''' def crawler_wrapper(parser, parsers_lst, crawl_candidate): try: crawler = Crawler(self.config, self.fetcher) article = crawler.crawl(crawl_candidate) except (UnicodeDecodeError, ValueError) as ex: if parsers_lst: parser = parsers_lst.pop(0) # remove it also! return crawler_wrapper(parser, parsers_lst, crawl_candidate)
python
{ "resource": "" }
q257709
smart_unicode
validation
def smart_unicode(string, encoding='utf-8', strings_only=False, errors='strict'): """ Returns a unicode object representing 's'. Treats bytestrings using the 'encoding' codec. If strings_only is True, don't convert (some) non-string-like objects. """ # if isinstance(s, Promise): #
python
{ "resource": "" }
q257710
force_unicode
validation
def force_unicode(string, encoding='utf-8', strings_only=False, errors='strict'): """ Similar to smart_unicode, except that lazy instances are resolved to strings, rather than kept as lazy objects. If strings_only is True, don't convert (some) non-string-like objects. """ # Handle the common case first, saves 30-40% in performance when s # is an instance of unicode. This function gets called often in that # setting. if isinstance(string, str): return string if strings_only and is_protected_type(string): return string try: if not isinstance(string, str): if hasattr(string, '__unicode__'): string = string.__unicode__() else: try: string = str(string, encoding, errors) except UnicodeEncodeError: if not isinstance(string, Exception): raise # If we get to here, the caller has passed in an Exception # subclass populated with non-ASCII data without special # handling to display as a string. We need to handle this # without raising a further exception. We do an # approximation to what the Exception's standard str() # output should be. string = ' '.join([force_unicode(arg, encoding, strings_only, errors) for arg in string]) elif
python
{ "resource": "" }
q257711
smart_str
validation
def smart_str(string, encoding='utf-8', strings_only=False, errors='strict'): """ Returns a bytestring version of 's', encoded as specified in 'encoding'. If strings_only is True, don't convert (some) non-string-like objects. """ if strings_only and isinstance(string, (type(None), int)): return string # if isinstance(s, Promise): # return unicode(s).encode(encoding, errors) if isinstance(string, str): try: return string.encode(encoding, errors) except UnicodeEncodeError: return string.encode('utf-8', errors) elif not isinstance(string, bytes): try: return str(string).encode(encoding, errors) except UnicodeEncodeError:
python
{ "resource": "" }
q257712
QuillAdmin.get_urls
validation
def get_urls(self): """Add URLs needed to handle image uploads.""" urls = patterns( '',
python
{ "resource": "" }
q257713
QuillAdmin.handle_upload
validation
def handle_upload(self, request): """Handle file uploads from WYSIWYG.""" if request.method != 'POST': raise Http404 if request.is_ajax(): try: filename = request.GET['quillUploadFile'] data = request is_raw = True except KeyError: return HttpResponseBadRequest("Invalid file upload.") else: if len(request.FILES) != 1:
python
{ "resource": "" }
q257714
QuillEditorWidget.render
validation
def render(self, name, value, attrs={}): """Render the Quill WYSIWYG.""" if value is None: value = '' final_attrs = self.build_attrs(attrs, name=name) quill_app = apps.get_app_config('quill') quill_config = getattr(quill_app, self.config)
python
{ "resource": "" }
q257715
RichTextField.formfield
validation
def formfield(self, **kwargs): """Get the form for field.""" defaults = { 'form_class': RichTextFormField,
python
{ "resource": "" }
q257716
render_toolbar
validation
def render_toolbar(context, config): """Render the toolbar for the given config.""" quill_config = getattr(quill_app, config) t =
python
{ "resource": "" }
q257717
get_meta_image_url
validation
def get_meta_image_url(request, image): """ Resize an image for metadata tags, and return an
python
{ "resource": "" }
q257718
check_mdrun_success
validation
def check_mdrun_success(logfile): """Check if ``mdrun`` finished successfully. Analyses the output from ``mdrun`` in *logfile*. Right now we are simply looking for the line "Finished mdrun on node" in the last 1kb of the file. (The file must be seeakable.) :Arguments: *logfile* : filename
python
{ "resource": "" }
q257719
get_double_or_single_prec_mdrun
validation
def get_double_or_single_prec_mdrun(): """Return double precision ``mdrun`` or fall back to single precision. This convenience function tries :func:`gromacs.mdrun_d` first and if it cannot run it, falls back to :func:`gromacs.mdrun` (without further checking). .. versionadded:: 0.5.1 """ try: gromacs.mdrun_d(h=True, stdout=False, stderr=False) logger.debug("using double precision gromacs.mdrun_d") return gromacs.mdrun_d except (AttributeError, GromacsError, OSError):
python
{ "resource": "" }
q257720
MDrunner.commandline
validation
def commandline(self, **mpiargs): """Returns simple command line to invoke mdrun. If :attr:`mpiexec` is set then :meth:`mpicommand` provides the mpi launcher command that prefixes the actual ``mdrun`` invocation: :attr:`mpiexec` [*mpiargs*] :attr:`mdrun` [*mdrun-args*] The *mdrun-args* are set on initializing the class. Override :meth:`mpicommand` to fit your system if
python
{ "resource": "" }
q257721
MDrunner.mpicommand
validation
def mpicommand(self, *args, **kwargs): """Return a list of the mpi command portion of the commandline. Only allows primitive mpi at the moment: *mpiexec* -n *ncores* *mdrun* *mdrun-args* (This is a primitive example for OpenMP. Override it for more complicated cases.) """
python
{ "resource": "" }
q257722
MDrunnerMpich2Smpd.prehook
validation
def prehook(self, **kwargs): """Launch local smpd.""" cmd = ['smpd', '-s']
python
{ "resource": "" }
q257723
glob_parts
validation
def glob_parts(prefix, ext): """Find files from a continuation run""" if ext.startswith('.'): ext = ext[1:] files = glob.glob(prefix+'.'+ext)
python
{ "resource": "" }
q257724
grompp_qtot
validation
def grompp_qtot(*args, **kwargs): """Run ``gromacs.grompp`` and return the total charge of the system. :Arguments: The arguments are the ones one would pass to :func:`gromacs.grompp`. :Returns: The total charge as reported Some things to keep in mind: * The stdout output of grompp is only shown when an error occurs. For debugging, look at the log file or screen output and try running the normal :func:`gromacs.grompp` command and analyze the output if the debugging messages are not sufficient. * Check that ``qtot`` is correct. Because the function is based on pattern matching of the informative output of :program:`grompp` it can break when the output format changes. This version recognizes lines like :: ' System has non-zero total charge: -4.000001e+00'
python
{ "resource": "" }
q257725
_mdp_include_string
validation
def _mdp_include_string(dirs): """Generate a string that can be added to a mdp 'include = ' line.""" include_paths
python
{ "resource": "" }
q257726
create_portable_topology
validation
def create_portable_topology(topol, struct, **kwargs): """Create a processed topology. The processed (or portable) topology file does not contain any ``#include`` statements and hence can be easily copied around. It also makes it possible to re-grompp without having any special itp files available. :Arguments: *topol* topology file *struct* coordinat (structure) file :Keywords: *processed* name of the new topology file; if not set then it is named like *topol* but with ``pp_`` prepended *includes* path or list of paths of directories in which itp files are searched for *grompp_kwargs** other options for :program:`grompp` such as ``maxwarn=2`` can also be supplied :Returns: full path to the processed topology """
python
{ "resource": "" }
q257727
edit_txt
validation
def edit_txt(filename, substitutions, newname=None): """Primitive text file stream editor. This function can be used to edit free-form text files such as the topology file. By default it does an **in-place edit** of *filename*. If *newname* is supplied then the edited file is written to *newname*. :Arguments: *filename* input text file *substitutions* substitution commands (see below for format) *newname* output filename; if ``None`` then *filename* is changed in place [``None``] *substitutions* is a list of triplets; the first two elements are regular expression strings, the last is the substitution value. It mimics ``sed`` search and replace. The rules for *substitutions*: .. productionlist:: substitutions: "[" search_replace_tuple, ... "]" search_replace_tuple: "(" line_match_RE "," search_RE "," replacement ")" line_match_RE: regular expression that selects the line (uses match) search_RE: regular expression that is searched in the line replacement: replacement string for search_RE Running :func:`edit_txt` does pretty much what a simple :: sed /line_match_RE/s/search_RE/replacement/ with repeated substitution commands does. Special replacement values: - ``None``: the rule is ignored - ``False``: the line is deleted (even if other rules match) .. note:: * No sanity checks are performed and the substitutions must be supplied exactly as shown. * All substitutions are applied to a line; thus the order of the substitution commands may matter when one substitution generates a match for a subsequent rule. * If replacement is set to ``None`` then the whole expression is ignored and whatever is in the template is used. To unset values you must provided an empty string or similar. * Delete a matching line if replacement=``False``. """ if newname is None: newname = filename # No sanity checks (figure out later how to give decent diagnostics). # Filter out any rules that have None in replacement. _substitutions = [{'lRE': re.compile(str(lRE)), 'sRE': re.compile(str(sRE)), 'repl': repl} for lRE,sRE,repl in substitutions if repl is not None]
python
{ "resource": "" }
q257728
make_ndx_captured
validation
def make_ndx_captured(**kwargs): """make_ndx that captures all output Standard :func:`~gromacs.make_ndx` command with the input and output pre-set in such a way that it can be conveniently used for :func:`parse_ndxlist`. Example:: ndx_groups = parse_ndxlist(make_ndx_captured(n=ndx)[0]) Note that the convenient :func:`get_ndx_groups` function does exactly
python
{ "resource": "" }
q257729
parse_groups
validation
def parse_groups(output): """Parse ``make_ndx`` output and return groups as a list of dicts.""" groups = [] for line in output.split('\n'): m = NDXGROUP.match(line) if m: d = m.groupdict()
python
{ "resource": "" }
q257730
Frames.delete_frames
validation
def delete_frames(self): """Delete all frames.""" for
python
{ "resource": "" }
q257731
IndexBuilder.gmx_resid
validation
def gmx_resid(self, resid): """Returns resid in the Gromacs index by transforming with offset.""" try: gmx_resid = int(self.offset[resid]) except (TypeError, IndexError): gmx_resid = resid + self.offset
python
{ "resource": "" }
q257732
IndexBuilder.combine
validation
def combine(self, name_all=None, out_ndx=None, operation='|', defaultgroups=False): """Combine individual groups into a single one and write output. :Keywords: name_all : string Name of the combined group, ``None`` generates a name. [``None``] out_ndx : filename Name of the output file that will contain the individual groups and the combined group. If ``None`` then default from the class constructor is used. [``None``] operation : character Logical operation that is used to generate the combined group from the individual groups: "|" (OR) or "&" (AND); if set to ``False`` then no combined group is created and only the individual groups are written. ["|"] defaultgroups : bool ``True``: append everything to the default groups produced by :program:`make_ndx` (or rather, the groups provided in the ndx file on initialization --- if this was ``None`` then these are truly default groups); ``False``: only use the generated groups :Returns: ``(combinedgroup_name, output_ndx)``, a tuple showing the actual group name and the name of the file; useful when all names are autogenerated. .. Warning:: The order of the atom numbers in the combined group is *not* guaranteed to be the same as the selections on input because ``make_ndx`` sorts them ascending. Thus you should be careful when using these index files for calculations of angles and dihedrals. Use :class:`gromacs.formats.NDX` in these cases. .. SeeAlso:: :meth:`IndexBuilder.write`. """ if not operation in ('|', '&', False): raise ValueError("Illegal operation {0!r}, only '|' (OR) and '&' (AND) or False allowed.".format( operation)) if name_all is None and operation: name_all = self.name_all or operation.join(self.indexfiles) if out_ndx is None: out_ndx = self.output if defaultgroups: # make a default file (using the original ndx where provided!!) fd, default_ndx = tempfile.mkstemp(suffix='.ndx', prefix='default__') try: self.make_ndx(o=default_ndx, input=['q']) except: utilities.unlink_gmx(default_ndx) raise
python
{ "resource": "" }
q257733
IndexBuilder.cat
validation
def cat(self, out_ndx=None): """Concatenate input index files. Generate a new index file that contains the default Gromacs index groups (if a structure file was defined) and all index groups from the input index files.
python
{ "resource": "" }
q257734
IndexBuilder._process_command
validation
def _process_command(self, command, name=None): """Process ``make_ndx`` command and return name and temp index file.""" self._command_counter += 1 if name is None: name = "CMD{0:03d}".format(self._command_counter) # Need to build it with two make_ndx calls because I cannot reliably # name the new group without knowing its number. try: fd, tmp_ndx = tempfile.mkstemp(suffix='.ndx', prefix='tmp_'+name+'__') cmd = [command, '', 'q'] # empty command '' necessary to get list # This sometimes fails with 'OSError: Broken Pipe' --- hard to debug
python
{ "resource": "" }
q257735
IndexBuilder._process_range
validation
def _process_range(self, selection, name=None): """Process a range selection. ("S234", "A300", "CA") --> selected all CA in this range ("S234", "A300") --> selected all atoms in this range .. Note:: Ignores residue type, only cares about the resid (but still required) """ try: first, last, gmx_atomname = selection except ValueError: try: first, last = selection gmx_atomname = '*' except: logger.error("%r is not a valid range selection", selection) raise if name is None: name = "{first!s}-{last!s}_{gmx_atomname!s}".format(**vars()) _first = self._translate_residue(first, default_atomname=gmx_atomname) _last = self._translate_residue(last, default_atomname=gmx_atomname) _selection = 'r {0:d} - {1:d} & &
python
{ "resource": "" }
q257736
IndexBuilder._translate_residue
validation
def _translate_residue(self, selection, default_atomname='CA'): """Translate selection for a single res to make_ndx syntax.""" m = self.RESIDUE.match(selection) if not m: errmsg = "Selection {selection!r} is not valid.".format(**vars()) logger.error(errmsg) raise ValueError(errmsg) gmx_resid = self.gmx_resid(int(m.group('resid'))) # magic offset correction residue = m.group('aa') if len(residue) == 1: gmx_resname = utilities.convert_aa_code(residue) # only works for AA else:
python
{ "resource": "" }
q257737
IndexBuilder.check_output
validation
def check_output(self, make_ndx_output, message=None, err=None): """Simple tests to flag problems with a ``make_ndx`` run.""" if message is None: message = "" else: message = '\n' + message def format(output, w=60): hrule = "====[ GromacsError (diagnostic output) ]".ljust(w,"=") return hrule + '\n' + str(output) + hrule rc = True if self._is_empty_group(make_ndx_output): warnings.warn("Selection produced empty group.{message!s}".format(**vars()), category=GromacsValueWarning) rc = False if self._has_syntax_error(make_ndx_output): rc = False out_formatted = format(make_ndx_output)
python
{ "resource": "" }
q257738
Transformer.outfile
validation
def outfile(self, p): """Path for an output file. If :attr:`outdir` is set then the path is ``outdir/basename(p)`` else just
python
{ "resource": "" }
q257739
Transformer.center_fit
validation
def center_fit(self, **kwargs): """Write compact xtc that is fitted to the tpr reference structure. See :func:`gromacs.cbook.trj_fitandcenter` for details and description of *kwargs* (including *input*, *input1*, *n* and *n1* for how to supply custom index groups). The most important ones are listed here but in most cases the defaults should work. :Keywords: *s* Input structure (typically the default tpr file but can be set to some other file with a different conformation for fitting) *n* Alternative index file. *o* Name of the output trajectory. *xy* : Boolean If ``True`` then only fit in xy-plane (useful for a membrane normal to z). The default is ``False``. *force* - ``True``: overwrite existing trajectories - ``False``: throw a IOError exception - ``None``: skip existing and log a warning [default] :Returns: dictionary with keys *tpr*, *xtc*, which are the names of the
python
{ "resource": "" }
q257740
Transformer.fit
validation
def fit(self, xy=False, **kwargs): """Write xtc that is fitted to the tpr reference structure. Runs :class:`gromacs.tools.trjconv` with appropriate arguments for fitting. The most important *kwargs* are listed here but in most cases the defaults should work. Note that the default settings do *not* include centering or periodic boundary treatment as this often does not work well with fitting. It is better to do this as a separate step (see :meth:`center_fit` or :func:`gromacs.cbook.trj_fitandcenter`) :Keywords: *s* Input structure (typically the default tpr file but can be set to some other file with a different conformation for fitting) *n* Alternative index file. *o* Name of the output trajectory. A default name is created. If e.g. *dt* = 100 is one of the *kwargs* then the default name includes "_dt100ps". *xy* : boolean If ``True`` then only do a rot+trans fit in the xy plane (good for membrane simulations); default is ``False``. *force* ``True``: overwrite existing trajectories ``False``: throw a IOError exception ``None``: skip existing and log a warning [default] *fitgroup* index group to fit on ["backbone"] .. Note:: If keyword *input* is supplied then it will override *fitgroup*; *input* = ``[fitgroup, outgroup]`` *kwargs* kwargs are passed to :func:`~gromacs.cbook.trj_xyfitted` :Returns: dictionary with keys *tpr*, *xtc*, which are the names of the the new files """ kwargs.setdefault('s', self.tpr) kwargs.setdefault('n', self.ndx) kwargs['f'] = self.xtc force = kwargs.pop('force', self.force) if xy: fitmode = 'rotxy+transxy' kwargs.pop('fit', None) infix_default = '_fitxy' else: fitmode = kwargs.pop('fit', 'rot+trans') # user can use 'progressive', too infix_default = '_fit' dt = kwargs.get('dt') if
python
{ "resource": "" }
q257741
Transformer.strip_fit
validation
def strip_fit(self, **kwargs): """Strip water and fit to the remaining system. First runs :meth:`strip_water` and then :meth:`fit`; see there for arguments. - *strip_input* is used for :meth:`strip_water` (but is only useful in special cases, e.g. when there is no Protein group defined. Then set *strip_input* = ``['Other']``. - *input* is passed on to :meth:`fit` and can contain the ``[center_group, fit_group, output_group]`` - *fitgroup* is only passed to :meth:`fit` and just contains the group to fit to ("backbone" by default) .. warning:: *fitgroup* can only be a Gromacs default group and not a custom group (because the indices change after stripping) - By default *fit* = "rot+trans" (and *fit* is passed to :meth:`fit`, together with the *xy* = ``False`` keyword) .. Note:: The call signature of :meth:`strip_water` is somewhat different from this one. """ kwargs.setdefault('fit', 'rot+trans') kw_fit = {}
python
{ "resource": "" }
q257742
create
validation
def create(logger_name, logfile='gromacs.log'): """Create a top level logger. - The file logger logs everything (including DEBUG). - The console logger only logs INFO and above. Logging to a file and the console. See http://docs.python.org/library/logging.html?#logging-to-multiple-destinations The top level logger of the library is named 'gromacs'. Note that we are configuring this logger with console output. If the root logger also does this then we will get two output lines to the
python
{ "resource": "" }
q257743
get_configuration
validation
def get_configuration(filename=CONFIGNAME): """Reads and parses the configuration file. Default values are loaded and then replaced with the values from ``~/.gromacswrapper.cfg`` if that file exists. The global configuration instance :data:`gromacswrapper.config.cfg` is updated as are a number of global variables such as :data:`configdir`, :data:`qscriptdir`, :data:`templatesdir`, :data:`logfilename`, ... Normally, the configuration is only loaded when the :mod:`gromacs` package is imported but a re-reading of the configuration can be forced anytime by calling :func:`get_configuration`. :Returns: a dict with all updated global configuration variables """ global cfg, configuration # very iffy --- most of the whole config mod should a class
python
{ "resource": "" }
q257744
setup
validation
def setup(filename=CONFIGNAME): """Prepare a default GromacsWrapper global environment. 1) Create the global config file. 2) Create the directories in which the user can store template and config files. This function can be run repeatedly without harm. """ # setup() must be separate and NOT run automatically when config # is loaded so that easy_install installations work # (otherwise we get a sandbox violation) # populate cfg with defaults (or existing data) get_configuration() if not os.path.exists(filename): with open(filename, 'w') as configfile: cfg.write(configfile) #
python
{ "resource": "" }
q257745
check_setup
validation
def check_setup(): """Check if templates directories are setup and issue a warning and help. Set the environment variable :envvar:`GROMACSWRAPPER_SUPPRESS_SETUP_CHECK` skip the check and make it always return ``True`` :return ``True`` if directories were found and ``False`` otherwise .. versionchanged:: 0.3.1 Uses :envvar:`GROMACSWRAPPER_SUPPRESS_SETUP_CHECK` to suppress check (useful for scripts run on a server) """ if "GROMACSWRAPPER_SUPPRESS_SETUP_CHECK" in os.environ: return True missing = [d for d in config_directories if not os.path.exists(d)] if len(missing) > 0:
python
{ "resource": "" }
q257746
get_tool_names
validation
def get_tool_names(): """ Get tool names from all configured groups. :return: list of tool names """ names = [] for group
python
{ "resource": "" }
q257747
GMXConfigParser.configuration
validation
def configuration(self): """Dict of variables that we make available as globals in the module. Can be used as :: globals().update(GMXConfigParser.configuration) # update configdir, templatesdir ... """ configuration = { 'configfilename': self.filename, 'logfilename': self.getpath('Logging', 'logfilename'), 'loglevel_console': self.getLogLevel('Logging', 'loglevel_console'), 'loglevel_file': self.getLogLevel('Logging', 'loglevel_file'), 'configdir': self.getpath('DEFAULT', 'configdir'), 'qscriptdir': self.getpath('DEFAULT', 'qscriptdir'),
python
{ "resource": "" }
q257748
GMXConfigParser.getpath
validation
def getpath(self, section, option): """Return option as an expanded path."""
python
{ "resource": "" }
q257749
GMXConfigParser.getLogLevel
validation
def getLogLevel(self, section, option): """Return the textual representation of logging level 'option' or the number. Note that option is always interpreted as an UPPERCASE string and hence integer log levels will not be recognized. .. SeeAlso:
python
{ "resource": "" }
q257750
Collection._canonicalize
validation
def _canonicalize(self, filename): """Use .collection as extension unless provided""" path, ext = os.path.splitext(filename)
python
{ "resource": "" }
q257751
scale_dihedrals
validation
def scale_dihedrals(mol, dihedrals, scale, banned_lines=None): """Scale dihedral angles""" if banned_lines is None: banned_lines = [] new_dihedrals = [] for dh in mol.dihedrals: atypes = dh.atom1.get_atomtype(), dh.atom2.get_atomtype(), dh.atom3.get_atomtype(), dh.atom4.get_atomtype() atypes = [a.replace("_", "").replace("=","") for a in atypes] # special-case: this is a [ dihedral ] override in molecule block, continue and don't match if dh.gromacs['param'] != []: for p in dh.gromacs['param']: p['kch'] *= scale new_dihedrals.append(dh) continue for iswitch in range(32): if (iswitch%2==0 ): a1=atypes[0]; a2=atypes[1]; a3=atypes[2]; a4=atypes[3] else: a1=atypes[3]; a2=atypes[2]; a3=atypes[1]; a4=atypes[0] if((iswitch//2)%2==1): a1="X"; if((iswitch//4)%2==1): a2="X"; if((iswitch//8)%2==1): a3="X"; if((iswitch//16)%2==1): a4="X"; key = "{0}-{1}-{2}-{3}-{4}".format(a1, a2, a3, a4, dh.gromacs['func'])
python
{ "resource": "" }
q257752
scale_impropers
validation
def scale_impropers(mol, impropers, scale, banned_lines=None): """Scale improper dihedrals""" if banned_lines is None: banned_lines = [] new_impropers = [] for im in mol.impropers: atypes = (im.atom1.get_atomtype(), im.atom2.get_atomtype(), im.atom3.get_atomtype(), im.atom4.get_atomtype()) atypes = [a.replace("_", "").replace("=", "") for a in atypes] # special-case: this is a [ dihedral ] override in molecule block, continue and don't match if im.gromacs['param'] != []: for p in im.gromacs['param']: p['kpsi'] *= scale new_impropers.append(im) continue for iswitch in range(32): if (iswitch%2==0): a1=atypes[0]; a2=atypes[1]; a3=atypes[2]; a4=atypes[3]; else: a1=atypes[3]; a2=atypes[2]; a3=atypes[1]; a4=atypes[0]; if((iswitch//2)%2==1): a1="X"; if((iswitch//4)%2==1): a2="X"; if((iswitch//8)%2==1): a3="X"; if((iswitch//16)%2==1): a4="X"; key = "{0}-{1}-{2}-{3}-{4}".format(a1, a2, a3, a4, im.gromacs['func']) if (key in impropers): for i, imt in enumerate(impropers[key]): imA = copy.deepcopy(im) param = copy.deepcopy(imt.gromacs['param'])
python
{ "resource": "" }
q257753
besttype
validation
def besttype(x): """Convert string x to the most useful type, i.e. int, float or unicode string. If x is a quoted string (single or double quotes) then the quotes are stripped and the enclosed string returned. .. Note:: Strings will be returned as Unicode strings (using :func:`to_unicode`). .. versionchanged:: 0.7.0 removed `encoding keyword argument """ x = to_unicode(x) # make unicode as soon as possible try: x = x.strip() except AttributeError: pass m = re.match(r"""['"](?P<value>.*)["']$""", x) if m is None:
python
{ "resource": "" }
q257754
to_int64
validation
def to_int64(a): """Return view of the recarray with all int32 cast to int64.""" # build new dtype and replace i4 --> i8 def promote_i4(typestr): if typestr[1:] == 'i4': typestr = typestr[0]+'i8' return
python
{ "resource": "" }
q257755
irecarray_to_py
validation
def irecarray_to_py(a): """Slow conversion of a recarray into a list of records with python types. Get the field names from :attr:`a.dtype.names`. :Returns: iterator so that one can handle big input arrays """ pytypes
python
{ "resource": "" }
q257756
XPM.col
validation
def col(self, c): """Parse colour specification""" m = self.COLOUR.search(c) if not m: self.logger.fatal("Cannot parse colour specification %r.", c)
python
{ "resource": "" }
q257757
Command.transform_args
validation
def transform_args(self, *args, **kwargs): """Transform arguments and return them as a list suitable for Popen.""" options = [] for option,value in kwargs.items(): if not option.startswith('-'): # heuristic for turning key=val pairs into options # (fails for commands such as 'find' -- then just use args) if len(option) == 1: option = '-' + option # POSIX style else: option = '--' + option # GNU option if value is True: options.append(option) continue
python
{ "resource": "" }
q257758
Command.help
validation
def help(self, long=False): """Print help; same as using ``?`` in ``ipython``. long=True also gives call signature.""" print("\ncommand: {0!s}\n\n".format(self.command_name)) print(self.__doc__)
python
{ "resource": "" }
q257759
GromacsCommand._combineargs
validation
def _combineargs(self, *args, **kwargs): """Add switches as 'options' with value True to the options dict.""" d = {arg: True for arg in
python
{ "resource": "" }
q257760
GromacsCommand._build_arg_list
validation
def _build_arg_list(self, **kwargs): """Build list of arguments from the dict; keys must be valid gromacs flags.""" arglist = [] for flag, value in kwargs.items(): # XXX: check flag against allowed values flag = str(flag) if flag.startswith('_'): flag = flag[1:] # python-illegal keywords are '_'-quoted if not flag.startswith('-'): flag = '-' + flag # now flag is guaranteed to start with '-' if value is True: arglist.append(flag) # simple command line flag elif value is False: if flag.startswith('-no'): # negate a negated flag ('noX=False' --> X=True --> -X ... but who uses that?) arglist.append('-' + flag[3:])
python
{ "resource": "" }
q257761
GromacsCommand.transform_args
validation
def transform_args(self,*args,**kwargs): """Combine arguments and turn them into gromacs tool arguments."""
python
{ "resource": "" }
q257762
GromacsCommand._get_gmx_docs
validation
def _get_gmx_docs(self): """Extract standard gromacs doc Extract by running the program and chopping the header to keep from 'DESCRIPTION' onwards. """ if self._doc_cache is not None: return self._doc_cache try: logging.disable(logging.CRITICAL) rc, header, docs = self.run('h', stdout=PIPE, stderr=PIPE, use_input=False) except: logging.critical("Invoking command {0} failed when determining its doc string. Proceed with caution".format(self.command_name)) self._doc_cache = "(No Gromacs documentation available)" return self._doc_cache finally: # ALWAYS restore logging...
python
{ "resource": "" }
q257763
autoconvert
validation
def autoconvert(s): """Convert input to a numerical type if possible. 1. A non-string object is returned as it is 2. Try conversion to int, float, str. """ if type(s) is not str: return s for converter in int, float, str: # try them in increasing order of lenience try: s = [converter(i) for i in s.split()] if len(s) == 1: return
python
{ "resource": "" }
q257764
isstream
validation
def isstream(obj): """Detect if `obj` is a stream. We consider anything a stream that has the methods - ``close()`` and either set of the following - ``read()``, ``readline()``, ``readlines()`` - ``write()``, ``writeline()``, ``writelines()`` :Arguments: *obj* stream or str :Returns: *bool*, ``True`` if `obj` is a stream, ``False`` otherwise .. SeeAlso:: :mod:`io` .. versionadded:: 0.7.1 """ signature_methods = ("close",) alternative_methods = ( ("read", "readline", "readlines"), ("write", "writeline", "writelines")) # Must have
python
{ "resource": "" }
q257765
convert_aa_code
validation
def convert_aa_code(x): """Converts between 3-letter and 1-letter amino acid codes.""" if len(x) == 1: return amino_acid_codes[x.upper()]
python
{ "resource": "" }
q257766
in_dir
validation
def in_dir(directory, create=True): """Context manager to execute a code block in a directory. * The directory is created if it does not exist (unless create=False is set) * At the end or after an exception code always returns to the directory that was the current directory before entering the block. """ startdir = os.getcwd() try: try: os.chdir(directory) logger.debug("Working in {directory!r}...".format(**vars())) except OSError as err: if create and err.errno == errno.ENOENT:
python
{ "resource": "" }
q257767
unlink_f
validation
def unlink_f(path): """Unlink path but do not complain if file does not exist.""" try: os.unlink(path)
python
{ "resource": "" }
q257768
remove_legend
validation
def remove_legend(ax=None): """Remove legend for axes or gca. See http://osdir.com/ml/python.matplotlib.general/2005-07/msg00285.html """
python
{ "resource": "" }
q257769
FileUtils.filename
validation
def filename(self,filename=None,ext=None,set_default=False,use_my_ext=False): """Supply a file name for the class object. Typical uses:: fn = filename() ---> <default_filename> fn = filename('name.ext') ---> 'name' fn = filename(ext='pickle') ---> <default_filename>'.pickle' fn = filename('name.inp','pdf') --> 'name.pdf' fn = filename('foo.pdf',ext='png',use_my_ext=True) --> 'foo.pdf' The returned filename is stripped of the extension (``use_my_ext=False``) and if provided, another extension is appended. Chooses a default if no filename is given. Raises a ``ValueError`` exception if no default file name is known. If ``set_default=True`` then the default filename is also set. ``use_my_ext=True`` lets the suffix of a provided filename take priority over a default ``ext`` tension. .. versionchanged:: 0.3.1 An empty string as *ext* = "" will suppress appending an extension. """ if filename is None: if not hasattr(self,'_filename'): self._filename = None # add attribute to class
python
{ "resource": "" }
q257770
FileUtils.check_file_exists
validation
def check_file_exists(self, filename, resolve='exception', force=None): """If a file exists then continue with the action specified in ``resolve``. ``resolve`` must be one of "ignore" always return ``False`` "indicate" return ``True`` if it exists "warn" indicate and issue a :exc:`UserWarning` "exception" raise :exc:`IOError` if it exists Alternatively, set *force* for the following behaviour (which ignores *resolve*): ``True`` same as *resolve* = "ignore" (will allow overwriting of files) ``False`` same as *resolve* = "exception" (will prevent overwriting of files) ``None`` ignored, do whatever *resolve* says """ def _warn(x): msg = "File {0!r} already exists.".format(x) logger.warn(msg) warnings.warn(msg) return True def _raise(x): msg = "File {0!r} already exists.".format(x)
python
{ "resource": "" }
q257771
Timedelta.strftime
validation
def strftime(self, fmt="%d:%H:%M:%S"): """Primitive string formatter. The only directives understood are the following: ============ ========================== Directive meaning ============ ========================== %d day as integer %H hour [00-23] %h hours including days
python
{ "resource": "" }
q257772
start_logging
validation
def start_logging(logfile="gromacs.log"): """Start logging of messages to file and console. The default logfile is named ``gromacs.log`` and messages are logged with the tag *gromacs*. """ from .
python
{ "resource": "" }
q257773
stop_logging
validation
def stop_logging(): """Stop logging to logfile and console.""" from . import log
python
{ "resource": "" }
q257774
tool_factory
validation
def tool_factory(clsname, name, driver, base=GromacsCommand): """ Factory for GromacsCommand derived types. """
python
{ "resource": "" }
q257775
find_executables
validation
def find_executables(path): """ Find executables in a path. Searches executables in a directory excluding some know commands unusable with GromacsWrapper. :param path: dirname to search for :return: list of executables """ execs = [] for exe in os.listdir(path): fullexe = os.path.join(path, exe)
python
{ "resource": "" }
q257776
load_v4_tools
validation
def load_v4_tools(): """ Load Gromacs 4.x tools automatically using some heuristic. Tries to load tools (1) in configured tool groups (2) and fails back to automatic detection from ``GMXBIN`` (3) then to a prefilled list. Also load any extra tool configured in ``~/.gromacswrapper.cfg`` :return: dict mapping tool names to GromacsCommand classes """ logger.debug("Loading v4 tools...") names = config.get_tool_names() if len(names) == 0 and 'GMXBIN' in os.environ: names = find_executables(os.environ['GMXBIN']) if len(names) == 0 or len(names) > len(V4TOOLS) * 4: names = list(V4TOOLS) names.extend(config.get_extra_tool_names()) tools = {} for name in
python
{ "resource": "" }
q257777
merge_ndx
validation
def merge_ndx(*args): """ Takes one or more index files and optionally one structure file and returns a path for a new merged index file. :param args: index files and zero or one structure file :return: path for the new merged index file """ ndxs = [] struct = None for fname in args: if fname.endswith('.ndx'): ndxs.append(fname) else: if struct is not None: raise ValueError("only one structure file supported") struct = fname
python
{ "resource": "" }
q257778
break_array
validation
def break_array(a, threshold=numpy.pi, other=None): """Create a array which masks jumps >= threshold. Extra points are inserted between two subsequent values whose absolute difference differs by more than threshold (default is pi). Other can be a secondary array which is also masked according to *a*. Returns (*a_masked*, *other_masked*) (where *other_masked* can be ``None``) """ assert len(a.shape) == 1, "Only 1D arrays supported" if other is not None and a.shape != other.shape: raise ValueError("arrays must be of identical shape") # jump occurs after the index in break breaks =
python
{ "resource": "" }
q257779
XVG.ma
validation
def ma(self): """Represent data as a masked array. The array is returned with column-first indexing, i.e. for a data file with columns X Y1 Y2
python
{ "resource": "" }
q257780
XVG._tcorrel
validation
def _tcorrel(self, nstep=100, **kwargs): """Correlation "time" of data. The 0-th column of the data is interpreted as a time and the decay of the data is computed from the autocorrelation function (using FFT). .. SeeAlso:: :func:`numkit.timeseries.tcorrel` """
python
{ "resource": "" }
q257781
XVG.set_correlparameters
validation
def set_correlparameters(self, **kwargs): """Set and change the parameters for calculations with correlation functions. The parameters persist until explicitly changed. :Keywords: *nstep* only process every *nstep* data point to speed up the FFT; if left empty a default is chosen that produces roughly 25,000 data points (or whatever is set in *ncorrel*) *ncorrel* If no *nstep* is supplied, aim at using *ncorrel* data points for the FFT; sets :attr:`XVG.ncorrel` [25000]
python
{ "resource": "" }
q257782
XVG.parse
validation
def parse(self, stride=None): """Read and cache the file as a numpy array. Store every *stride* line of data; if ``None`` then the class default is used. The array is returned with column-first indexing, i.e. for a data file with columns X Y1 Y2 Y3 ... the array a will be a[0] = X, a[1] = Y1, ... . """ if stride is None: stride = self.stride self.corrupted_lineno = [] irow = 0 # count rows of data # cannot use numpy.loadtxt() because xvg can have two types of 'comment' lines with utilities.openany(self.real_filename) as xvg: rows = [] ncol = None for lineno,line in enumerate(xvg): line = line.strip() if len(line) == 0: continue if "label" in line and "xaxis" in line: self.xaxis = line.split('"')[-2] if "label" in line and "yaxis" in line: self.yaxis = line.split('"')[-2] if line.startswith("@ legend"): if not "legend" in self.metadata: self.metadata["legend"] = [] self.metadata["legend"].append(line.split("legend ")[-1]) if line.startswith("@ s") and "subtitle" not in line: name = line.split("legend ")[-1].replace('"','').strip()
python
{ "resource": "" }
q257783
XVG.plot
validation
def plot(self, **kwargs): """Plot xvg file data. The first column of the data is always taken as the abscissa X. Additional columns are plotted as ordinates Y1, Y2, ... In the special case that there is only a single column then this column is plotted against the index, i.e. (N, Y). :Keywords: *columns* : list Select the columns of the data to be plotted; the list is used as a numpy.array extended slice. The default is to use all columns. Columns are selected *after* a transform. *transform* : function function ``transform(array) -> array`` which transforms the original array; must return a 2D numpy array of shape [X, Y1, Y2, ...] where X, Y1, ... are column vectors. By default the transformation is the identity [``lambda x: x``]. *maxpoints* : int limit the total number of data points; matplotlib has issues processing png files with >100,000 points and pdfs take forever to display. Set to ``None`` if really all data should be displayed. At the moment we simply decimate the data at regular intervals. [10000] *method* method to decimate the data to *maxpoints*, see :meth:`XVG.decimate` for details *color* single color (used for all plots); sequence of colors (will be repeated as necessary); or a matplotlib colormap (e.g. "jet", see :mod:`matplotlib.cm`). The default is to use the :attr:`XVG.default_color_cycle`. *ax* plot into given axes or create new one if ``None`` [``None``] *kwargs* All other keyword arguments are passed on to :func:`matplotlib.pyplot.plot`. :Returns: *ax* axes instance """ columns = kwargs.pop('columns', Ellipsis) # slice for everything maxpoints = kwargs.pop('maxpoints', self.maxpoints_default) transform = kwargs.pop('transform', lambda x: x) # default is identity transformation method = kwargs.pop('method', "mean") ax = kwargs.pop('ax', None) if columns is Ellipsis or columns is None: columns = numpy.arange(self.array.shape[0]) if len(columns) == 0: raise MissingDataError("plot() needs at least one column of data")
python
{ "resource": "" }
q257784
topology
validation
def topology(struct=None, protein='protein', top='system.top', dirname='top', posres="posres.itp", ff="oplsaa", water="tip4p", **pdb2gmx_args): """Build Gromacs topology files from pdb. :Keywords: *struct* input structure (**required**) *protein* name of the output files *top* name of the topology file *dirname* directory in which the new topology will be stored *ff* force field (string understood by ``pdb2gmx``); default "oplsaa" *water* water model (string), default "tip4p" *pdb2gmxargs* other arguments for ``pdb2gmx``
python
{ "resource": "" }
q257785
make_main_index
validation
def make_main_index(struct, selection='"Protein"', ndx='main.ndx', oldndx=None): """Make index file with the special groups. This routine adds the group __main__ and the group __environment__ to the end of the index file. __main__ contains what the user defines as the *central* and *most important* parts of the system. __environment__ is everything else. The template mdp file, for instance, uses these two groups for T-coupling. These groups are mainly useful if the default groups "Protein" and "Non-Protein" are not appropriate. By using symbolic names such as __main__ one can keep scripts more general. :Returns: *groups* is a list of dictionaries that describe the index groups. See :func:`gromacs.cbook.parse_ndxlist` for details. :Arguments: *struct* : filename structure (tpr, pdb, gro) *selection* : string is a ``make_ndx`` command such as ``"Protein"`` or ``r DRG`` which determines what is considered the main group for centering etc. It is passed directly to ``make_ndx``. *ndx* : string name of the final index file *oldndx* : string name of index file that should be used as a basis; if None then the ``make_ndx`` default groups are used. This routine is very dumb at the moment; maybe some heuristics will be added later as could be other symbolic groups such as __membrane__. """ logger.info("Building the main index file {ndx!r}...".format(**vars())) # pass 1: select # get a list of groups # need the first "" to get make_ndx to spit out the group list. _,out,_ = gromacs.make_ndx(f=struct, n=oldndx, o=ndx, stdout=False, input=("", "q")) groups = cbook.parse_ndxlist(out) # find the matching groups, # there is a nasty bug in GROMACS where make_ndx may have multiple # groups, which caused the previous approach to fail big time. # this is a work around the make_ndx bug. # striping the "" allows compatibility with existing make_ndx selection commands. selection = selection.strip("\"") selected_groups = [g for g in groups if g['name'].lower() == selection.lower()] if len(selected_groups) > 1: logging.warn("make_ndx created duplicated groups, performing work around") if len(selected_groups) <= 0: msg = "no groups found for selection {0}, available groups are {1}".format(selection, groups) logging.error(msg) raise ValueError(msg) # Found at least one matching group, we're OK # index of last group last = len(groups) - 1 assert
python
{ "resource": "" }
q257786
get_lipid_vdwradii
validation
def get_lipid_vdwradii(outdir=os.path.curdir, libdir=None): """Find vdwradii.dat and add special entries for lipids. See :data:`gromacs.setup.vdw_lipid_resnames` for lipid resnames. Add more if necessary. """ vdwradii_dat = os.path.join(outdir, "vdwradii.dat") if libdir is not None: filename = os.path.join(libdir, 'vdwradii.dat') # canonical name if not os.path.exists(filename): msg = 'No VDW database file found in {filename!r}.'.format(**vars()) logger.exception(msg) raise OSError(msg, errno.ENOENT) else: try: filename = os.path.join(os.environ['GMXLIB'], 'vdwradii.dat') except KeyError: try: filename = os.path.join(os.environ['GMXDATA'], 'top', 'vdwradii.dat') except KeyError: msg = "Cannot find vdwradii.dat. Set GMXLIB (point to 'top') or GMXDATA ('share/gromacs')." logger.exception(msg) raise OSError(msg, errno.ENOENT) if not os.path.exists(filename): msg = "Cannot find {filename!r}; something is wrong with the Gromacs installation.".format(**vars()) logger.exception(msg, errno.ENOENT) raise OSError(msg) # make sure to catch 3 and 4 letter resnames patterns
python
{ "resource": "" }
q257787
solvate
validation
def solvate(struct='top/protein.pdb', top='top/system.top', distance=0.9, boxtype='dodecahedron', concentration=0, cation='NA', anion='CL', water='tip4p', solvent_name='SOL', with_membrane=False, ndx = 'main.ndx', mainselection = '"Protein"', dirname='solvate', **kwargs): """Put protein into box, add water, add counter-ions. Currently this really only supports solutes in water. If you need to embedd a protein in a membrane then you will require more sophisticated approaches. However, you *can* supply a protein already inserted in a bilayer. In this case you will probably want to set *distance* = ``None`` and also enable *with_membrane* = ``True`` (using extra big vdw radii for typical lipids). .. Note:: The defaults are suitable for solvating a globular protein in a fairly tight (increase *distance*!) dodecahedral box. :Arguments: *struct* : filename pdb or gro input structure *top* : filename Gromacs topology *distance* : float When solvating with water, make the box big enough so that at least *distance* nm water are between the solute *struct* and the box boundary. Set *boxtype* to ``None`` in order to use a box size in the input file (gro or pdb). *boxtype* or *bt*: string Any of the box types supported by :class:`~gromacs.tools.Editconf` (triclinic, cubic, dodecahedron, octahedron). Set the box dimensions either with *distance* or the *box* and *angle* keywords. If set to ``None`` it will ignore *distance* and use the box inside the *struct* file. *bt* overrides the value of *boxtype*. *box* List of three box lengths [A,B,C] that are used by :class:`~gromacs.tools.Editconf` in combination with *boxtype* (``bt`` in :program:`editconf`) and *angles*. Setting *box* overrides *distance*. *angles* List of three angles (only necessary for triclinic boxes). *concentration* : float Concentration of the free ions in mol/l. Note that counter ions are added in excess of this concentration. *cation* and *anion* : string Molecule names of the ions. This depends on the chosen force field. *water* : string Name of the water model; one of "spc", "spce", "tip3p", "tip4p". This should be appropriate for the chosen force field. If an alternative solvent is required, simply supply the path to a box with solvent molecules (used by :func:`~gromacs.genbox`'s *cs* argument) and also supply the molecule name
python
{ "resource": "" }
q257788
energy_minimize
validation
def energy_minimize(dirname='em', mdp=config.templates['em.mdp'], struct='solvate/ionized.gro', top='top/system.top', output='em.pdb', deffnm="em", mdrunner=None, mdrun_args=None, **kwargs): """Energy minimize the system. This sets up the system (creates run input files) and also runs ``mdrun_d``. Thus it can take a while. Additional itp files should be in the same directory as the top file. Many of the keyword arguments below already have sensible values. :Keywords: *dirname* set up under directory dirname [em] *struct* input structure (gro, pdb, ...) [solvate/ionized.gro] *output* output structure (will be put under dirname) [em.pdb] *deffnm* default name for mdrun-related files [em] *top* topology file [top/system.top] *mdp* mdp file (or use the template) [templates/em.mdp] *includes* additional directories to search for itp files *mdrunner* :class:`gromacs.run.MDrunner` instance; by default we just try :func:`gromacs.mdrun_d` and :func:`gromacs.mdrun` but a MDrunner instance gives the user the ability to run mpi jobs etc. [None] *mdrun_args* arguments for *mdrunner* (as a dict), e.g. ``{'nt': 2}``; empty by default .. versionaddedd:: 0.7.0 *kwargs* remaining key/value pairs that should be changed in the template mdp file, eg ``nstxtcout=250, nstfout=250``. .. note:: If :func:`~gromacs.mdrun_d` is not found, the function falls back to :func:`~gromacs.mdrun` instead. """ structure = realpath(struct) topology = realpath(top) mdp_template = config.get_template(mdp) deffnm = deffnm.strip() mdrun_args = {} if mdrun_args is None else mdrun_args # write the processed topology to the default output kwargs.setdefault('pp', 'processed.top') # filter some kwargs that might come through when feeding output # from previous stages such as solvate(); necessary because *all* # **kwargs must be *either* substitutions in the mdp file *or* valid # command line parameters for ``grompp``. kwargs.pop('ndx', None) # mainselection is not used but only passed through; right now we # set it to the default that is being used in all argument lists # but that is not pretty. TODO. mainselection = kwargs.pop('mainselection', '"Protein"') # only interesting when passed from solvate() qtot = kwargs.pop('qtot', 0) # mdp is now the *output* MDP that will be generated from mdp_template mdp = deffnm+'.mdp' tpr = deffnm+'.tpr' logger.info("[{dirname!s}] Energy minimization of struct={struct!r}, top={top!r}, mdp={mdp!r} ...".format(**vars())) cbook.add_mdp_includes(topology, kwargs) if qtot != 0: # At the moment this is purely user-reported and really only here because # it might get fed into the function when using the keyword-expansion pipeline # usage paradigm. wmsg = "Total charge was reported as qtot = {qtot:g} <> 0; probably a problem.".format(**vars()) logger.warn(wmsg) warnings.warn(wmsg, category=BadParameterWarning)
python
{ "resource": "" }
q257789
em_schedule
validation
def em_schedule(**kwargs): """Run multiple energy minimizations one after each other. :Keywords: *integrators* list of integrators (from 'l-bfgs', 'cg', 'steep') [['bfgs', 'steep']] *nsteps* list of maximum number of steps; one for each integrator in in the *integrators* list [[100,1000]] *kwargs* mostly passed to :func:`gromacs.setup.energy_minimize` :Returns: dictionary with paths to final structure ('struct') and other files :Example: Conduct three minimizations: 1. low memory Broyden-Goldfarb-Fletcher-Shannon (BFGS) for 30 steps 2. steepest descent for 200 steps 3. finish with BFGS for another 30 steps We also do a multi-processor minimization when possible (i.e. for steep (and conjugate gradient) by using a :class:`gromacs.run.MDrunner` class for a :program:`mdrun` executable compiled for OpenMP in 64 bit (see :mod:`gromacs.run` for details):: import gromacs.run gromacs.setup.em_schedule(struct='solvate/ionized.gro', mdrunner=gromacs.run.MDrunnerOpenMP64, integrators=['l-bfgs', 'steep', 'l-bfgs'], nsteps=[50,200, 50]) .. Note:: You might have to prepare the mdp file carefully because at the moment one can only modify the *nsteps* parameter on a per-minimizer basis. """
python
{ "resource": "" }
q257790
MD_restrained
validation
def MD_restrained(dirname='MD_POSRES', **kwargs): """Set up MD with position restraints. Additional itp files should be in the same directory as the top file. Many of the keyword arguments below already have sensible values. Note that setting *mainselection* = ``None`` will disable many of the automated choices and is often recommended when using your own mdp file. :Keywords: *dirname* set up under directory dirname [MD_POSRES] *struct* input structure (gro, pdb, ...) [em/em.pdb] *top* topology file [top/system.top] *mdp* mdp file (or use the template) [templates/md.mdp] *ndx* index file (supply when using a custom mdp) *includes* additional directories to search for itp files *mainselection* :program:`make_ndx` selection to select main group ["Protein"] (If ``None`` then no canonical index file is generated and it is the user's responsibility to set *tc_grps*, *tau_t*, and *ref_t* as keyword arguments, or provide the mdp template with all parameter pre-set in *mdp* and probably also your own *ndx* index file.) *deffnm* default filename for Gromacs run [md] *runtime* total length of the simulation in ps [1000] *dt* integration time step in ps [0.002] *qscript* script to submit to the queuing system; by default uses the template :data:`gromacs.config.qscript_template`, which can be manually set to another template from :data:`gromacs.config.templates`; can also be a list of template names. *qname* name to be used for the job in the queuing system [PR_GMX] *mdrun_opts* option flags for the :program:`mdrun` command in the queuing system scripts such as "-stepout 100". [""] *kwargs* remaining key/value pairs that should be changed in the template mdp file, eg ``nstxtcout=250, nstfout=250`` or command line options for ``grompp` such as ``maxwarn=1``. In particular one can also set **define** and activate whichever position restraints have been coded into the itp and top file. For instance one could have *define* = "-DPOSRES_MainChain -DPOSRES_LIGAND" if these preprocessor constructs exist. Note that there **must not be any space between "-D" and the value.** By default *define* is set to "-DPOSRES". :Returns: a dict that can be fed into :func:`gromacs.setup.MD` (but check, just in case, especially if you want to
python
{ "resource": "" }
q257791
MD
validation
def MD(dirname='MD', **kwargs): """Set up equilibrium MD. Additional itp files should be in the same directory as the top file. Many of the keyword arguments below already have sensible values. Note that setting *mainselection* = ``None`` will disable many of the automated choices and is often recommended when using your own mdp file. :Keywords: *dirname* set up under directory dirname [MD] *struct* input structure (gro, pdb, ...) [MD_POSRES/md_posres.pdb] *top* topology file [top/system.top] *mdp* mdp file (or use the template) [templates/md.mdp] *ndx* index file (supply when using a custom mdp) *includes* additional directories to search for itp files *mainselection* ``make_ndx`` selection to select main group ["Protein"] (If ``None`` then no canonical index file is generated and it is the user's responsibility to set *tc_grps*, *tau_t*, and *ref_t* as keyword arguments, or provide the mdp template with all parameter pre-set in *mdp* and probably also your own *ndx* index file.) *deffnm* default filename for Gromacs run [md] *runtime* total length of the simulation in ps [1000] *dt* integration time step in ps [0.002] *qscript* script to submit to the queuing
python
{ "resource": "" }
q257792
generate_submit_scripts
validation
def generate_submit_scripts(templates, prefix=None, deffnm='md', jobname='MD', budget=None, mdrun_opts=None, walltime=1.0, jobarray_string=None, startdir=None, npme=None, **kwargs): """Write scripts for queuing systems. This sets up queuing system run scripts with a simple search and replace in templates. See :func:`gromacs.cbook.edit_txt` for details. Shell scripts are made executable. :Arguments: *templates* Template file or list of template files. The "files" can also be names or symbolic names for templates in the templates directory. See :mod:`gromacs.config` for details and rules for writing templates. *prefix* Prefix for the final run script filename; by default the filename will be the same as the template. [None] *dirname* Directory in which to place the submit scripts. [.] *deffnm* Default filename prefix for :program:`mdrun` ``-deffnm`` [md] *jobname* Name of the job in the queuing system. [MD] *budget* Which budget to book the runtime on [None] *startdir* Explicit path on the remote system (for run scripts that need to `cd` into this directory at the beginning of execution) [None] *mdrun_opts* String of additional options for :program:`mdrun`. *walltime* Maximum runtime of the job in hours. [1] *npme* number of PME nodes *jobarray_string* Multi-line string that is spliced in for job array functionality (see :func:`gromacs.qsub.generate_submit_array`; do not use manually) *kwargs* all other kwargs are ignored :Returns: list of generated run scripts """ if not jobname[0].isalpha(): jobname = 'MD_'+jobname wmsg = "To make the jobname legal it must start with a letter: changed to {0!r}".format(jobname) logger.warn(wmsg) warnings.warn(wmsg, category=AutoCorrectionWarning) if prefix is None: prefix = "" if mdrun_opts is not None: mdrun_opts = '"'+str(mdrun_opts)+'"' # TODO: could test if quotes already present dirname = kwargs.pop('dirname', os.path.curdir) wt = Timedelta(hours=walltime) walltime = wt.strftime("%h:%M:%S") wall_hours = wt.ashours def write_script(template): submitscript = os.path.join(dirname, prefix + os.path.basename(template)) logger.info("Setting up queuing system script {submitscript!r}...".format(**vars())) # These substitution rules are documented for the user in the module doc string qsystem = detect_queuing_system(template) if qsystem is not None and (qsystem.name == 'Slurm'): cbook.edit_txt(template, [('^ *DEFFNM=','(?<==)(.*)', deffnm), ('^#.*(-J)', '((?<=-J\s))\s*\w+', jobname),
python
{ "resource": "" }
q257793
generate_submit_array
validation
def generate_submit_array(templates, directories, **kwargs): """Generate a array job. For each ``work_dir`` in *directories*, the array job will 1. cd into ``work_dir`` 2. run the job as detailed in the template It will use all the queuing system directives found in the template. If more complicated set ups are required, then this function cannot be used. :Arguments: *templates* Basic template for a single job; the job array logic is spliced into the position of the line :: # JOB_ARRAY_PLACEHOLDER The appropriate commands for common queuing systems (Sun Gridengine, PBS) are hard coded here. The queuing system is detected from the suffix of the template. *directories* List of directories under *dirname*. One task is set up for each directory. *dirname* The array script will be placed in this directory. The *directories* **must** be located under *dirname*. *kwargs* See :func:`gromacs.setup.generate_submit_script` for details. """ dirname = kwargs.setdefault('dirname', os.path.curdir) reldirs = [relpath(p, start=dirname) for p in asiterable(directories)] missing = [p for p in (os.path.join(dirname, subdir) for subdir in reldirs) if not os.path.exists(p)] if len(missing) > 0: logger.debug("template=%(template)r: dirname=%(dirname)r reldirs=%(reldirs)r", vars())
python
{ "resource": "" }
q257794
QueuingSystem.isMine
validation
def isMine(self, scriptname): """Primitive queuing system detection; only looks at suffix at the moment.""" suffix = os.path.splitext(scriptname)[1].lower()
python
{ "resource": "" }
q257795
Molecule.anumb_to_atom
validation
def anumb_to_atom(self, anumb): '''Returns the atom object corresponding to an atom number''' assert isinstance(anumb, int), "anumb must be integer" if not self._anumb_to_atom: # empty dictionary if self.atoms: for atom in self.atoms: self._anumb_to_atom[atom.number] = atom return self._anumb_to_atom[anumb] else: self.logger("no atoms in the molecule")
python
{ "resource": "" }
q257796
total_regular_pixels_from_mask
validation
def total_regular_pixels_from_mask(mask): """Compute the total number of unmasked regular pixels in a masks.""" total_regular_pixels = 0
python
{ "resource": "" }
q257797
mask_circular_annular_from_shape_pixel_scale_and_radii
validation
def mask_circular_annular_from_shape_pixel_scale_and_radii(shape, pixel_scale, inner_radius_arcsec, outer_radius_arcsec, centre=(0.0, 0.0)): """Compute an annular masks from an input inner and outer masks radius and regular shape.""" mask = np.full(shape, True) centres_arcsec = mask_centres_from_shape_pixel_scale_and_centre(shape=mask.shape, pixel_scale=pixel_scale, centre=centre) for y in range(mask.shape[0]): for x in range(mask.shape[1]):
python
{ "resource": "" }
q257798
mask_blurring_from_mask_and_psf_shape
validation
def mask_blurring_from_mask_and_psf_shape(mask, psf_shape): """Compute a blurring masks from an input masks and psf shape. The blurring masks corresponds to all pixels which are outside of the masks but will have a fraction of their \ light blur into the masked region due to PSF convolution.""" blurring_mask = np.full(mask.shape, True) for y in range(mask.shape[0]): for x in range(mask.shape[1]): if not mask[y, x]: for y1 in range((-psf_shape[0] + 1) // 2, (psf_shape[0] + 1) // 2): for x1 in range((-psf_shape[1] + 1) // 2, (psf_shape[1] + 1) // 2): if 0 <= x + x1 <= mask.shape[1] - 1 and 0 <= y + y1 <= mask.shape[0] - 1: if mask[y + y1, x + x1]:
python
{ "resource": "" }
q257799
edge_pixels_from_mask
validation
def edge_pixels_from_mask(mask): """Compute a 1D array listing all edge pixel indexes in the masks. An edge pixel is a pixel which is not fully \ surrounding by False masks values i.e. it is on an edge.""" edge_pixel_total = total_edge_pixels_from_mask(mask) edge_pixels = np.zeros(edge_pixel_total) edge_index = 0 regular_index = 0 for y in range(mask.shape[0]): for x in range(mask.shape[1]): if not mask[y, x]: if mask[y + 1, x] or mask[y - 1, x] or
python
{ "resource": "" }