Skip to content

Commit 8e4d8d5

Browse files
committed
Added concat_mol2.py NO_JIRA
1 parent d70cdaa commit 8e4d8d5

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

scripts/concat_mol2/ReadMe.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Concat Mol2
2+
3+
----
4+
5+
## Summary
6+
7+
Opens a set of mol2 files in the working directory and creates one concatenated multi-mol2 file.
8+
Optionally delete the individual mol2 files other than the new concat.mol2
9+
10+
## Requirements
11+
12+
CSD Python API not required.
13+
Mol2 files must be in the same directory.
14+
15+
## Licensing Requirements
16+
17+
No licence required
18+
19+
## Instructions on running
20+
21+
```cmd
22+
> python concat_mol2.py
23+
```
24+
25+
Help output:
26+
```cmd
27+
> python concat_mol2.py -h
28+
29+
usage: concat_mol2.py [-h] [-d]
30+
31+
optional arguments:
32+
-h, --help show this help message and exit
33+
-d, --delete_contributors
34+
Remove contributing individual mol2 files after
35+
concatenation
36+
37+
```
38+
39+
## Author
40+
41+
_
42+
43+
> For feedback or to report any issues please contact [support@ccdc.cam.ac.uk](support@ccdc.cam.ac.uk)

scripts/concat_mol2/concat_mol2.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#
2+
# This script can be used for any purpose without limitation subject to the
3+
# conditions at http://www.ccdc.cam.ac.uk/Community/Pages/Licences/v2.aspx
4+
#
5+
# This permission notice and the following statement of attribution must be
6+
# included in all copies or substantial portions of this script.
7+
#
8+
# 2014-08-11: created by Peter Galek, The Cambridge Crystallographic Data Centre
9+
# 2022-02-24: updated by Alex Moldovan, The Cambridge Crystallographic Data Centre
10+
#
11+
12+
import glob
13+
import argparse
14+
import os
15+
16+
17+
def main(delete_separate_files):
18+
mol2_files = glob.glob('*.mol2')
19+
count = 0
20+
with open('concat.mol2', 'w') as outfile:
21+
for f in mol2_files:
22+
if f == 'concat.mol2':
23+
continue
24+
with open(f, 'r') as infile:
25+
outfile.write(infile.read())
26+
count += 1
27+
print(f"{count} files concatenated.")
28+
29+
if delete_separate_files == True:
30+
count = 0
31+
for f in mol2_files:
32+
if f == 'concat.mol2':
33+
continue
34+
os.remove(f)
35+
count += 1
36+
print(f"{count} files removed.")
37+
38+
39+
if __name__ == '__main__':
40+
parser = argparse.ArgumentParser(description=__doc__)
41+
parser.add_argument('-d', '--delete_contributors', action='store_true',
42+
help='Remove contributing individual mol2 files after concatenation')
43+
44+
args = parser.parse_args()
45+
main(args.delete_contributors)

0 commit comments

Comments
 (0)