1 | #! /usr/bin/env python |
||
2 | # |
||
3 | # Copyright (C) 2016 Rich Lewis <[email protected]> |
||
4 | # License: 3-clause BSD |
||
5 | |||
6 | 1 | """ |
|
7 | # skchem.utils.io |
||
8 | |||
9 | IO helper functions for skchem. |
||
10 | """ |
||
11 | |||
12 | 1 | import yaml |
|
0 ignored issues
–
show
|
|||
13 | 1 | import json |
|
14 | |||
15 | |||
16 | 1 | def line_count(filename): |
|
17 | |||
18 | """ Quickly count the number of lines in a file. |
||
19 | |||
20 | Adapted from http://stackoverflow.com/questions/845058/how-to-get-line-count-cheaply-in-python |
||
21 | |||
22 | Args: |
||
23 | filename (str): |
||
24 | The name of the file to count for. |
||
25 | |||
26 | """ |
||
27 | |||
28 | f = open(filename, 'rb') |
||
0 ignored issues
–
show
The name
f does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
29 | lines = 0 |
||
30 | buf_size = 1024 * 1024 |
||
31 | read_f = f.read |
||
32 | buf = read_f(buf_size) |
||
33 | while buf: |
||
34 | lines += buf.count(b'\n') |
||
35 | buf = read_f(buf_size) |
||
36 | return lines |
||
37 | |||
38 | |||
39 | 1 | def sdf_count(filename): |
|
40 | |||
41 | """ Efficiently count molecules in an sdf file. |
||
42 | |||
43 | Specifically, the function counts the number of times '$$$$' occurs at the |
||
44 | start of lines in the file. |
||
45 | |||
46 | Args: |
||
47 | filename (str): The filename of the sdf file. |
||
48 | |||
49 | Returns: |
||
50 | int: the number of molecules in the file. |
||
51 | """ |
||
52 | |||
53 | with open(filename, 'rb') as f: |
||
0 ignored issues
–
show
The name
f does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
54 | return sum(1 for l in f if l[:4] == b'$$$$') |
||
55 | |||
56 | |||
57 | 1 | def json_dump(obj, target=None): |
|
58 | """ Write object as json to file or stream, or return as string. """ |
||
59 | |||
60 | if target is None: |
||
61 | return json.dumps(obj) |
||
62 | elif isinstance(target, str): |
||
63 | with open(target, 'w') as f: |
||
0 ignored issues
–
show
The name
f does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
64 | json.dump(obj, f) |
||
65 | else: |
||
66 | json.dump(obj, target) |
||
67 | |||
68 | |||
69 | 1 | def yaml_dump(obj, target=None): |
|
70 | """ Write object as yaml to file or stream, or return as string. """ |
||
71 | |||
72 | if isinstance(target, str): |
||
73 | with open(target, 'w') as f: |
||
0 ignored issues
–
show
The name
f does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
74 | yaml.dump(obj, f, default_flow_style=False) |
||
75 | else: |
||
76 | return yaml.dump(obj, target, default_flow_style=False) |
||
77 |
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.