-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLigand.py
161 lines (129 loc) · 4.02 KB
/
Ligand.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"""
Ligands class object
"""
import functions
import BioSimSpace as bss
import os
class Ligand(object):
"""
Ligand object for AFE preparation.
Parameters:
-----------
path: str
path to /inputs/ligands
forcefield: str
ligand forcefield
Methods:
-------
"""
def __init__(self, file, parameterised=False):
"""
Class constructor
"""
self.parameterised = parameterised
if not self.parameterised:
self.file = functions.file_exists(file)
elif self.parameterised:
self.file = file # file arg will be a list of prm7, rst7
self.molecule = self.get_ligand()
self.name = self.get_name()
def get_ligand(self):
"""
Get ligand molecule in path as bss.Molecule object.
Return:
-------
ligands: bss.Molecule
ligand molecule
"""
ligand = bss.IO.readMolecules(self.file)[0]
return ligand
def get_name(self):
"""
Get ligand names in path.
Return:
-------
names: list
"""
if self.parameterised:
names = functions.get_filename(self.file[0])
else:
names = functions.get_filename(self.file)
return names
def parameterise(self, forcefield, charge):
"""
Parameterise ligand using BioSimSpace
Parameters:
-----------
forcefield:
name of the ligand force field, current options are GAFF and GAFF2
charge:
charge of the ligand
Return:
-------
self.parameters: bss.Molecule
parameterised ligand molecule object
"""
self.parameters = None
if forcefield == "gaff":
self.parameters = bss.Parameters.gaff(molecule=self.molecule, net_charge=charge).getMolecule()
elif forcefield == "gaff2":
self.parameters = bss.Parameters.gaff2(molecule=self.molecule, net_charge=charge).getMolecule()
else:
print(f"Forcefield {forcefield} is not supported for ligands.")
return self.parameters
def antechamber(self, charge, path, input_file=None, atom_type="gaff2", charge_method="bcc"):
"""
Parameterise ligand using antechamber
Parameters:
-----------
charge: float
charge of the ligand
Return:
-------
self: Ligand
Ligand object
"""
if not input_file:
input_file = self.file
else:
input_file = functions.file_exists(input_file)
input_file_extension = functions.get_file_extension(input_file)
command = f"antechamber -fi {input_file_extension} -fo mol2 -i {input_file} -o {self.name}.mol2 -c {charge_method} -at {atom_type} -pf y -nc {charge}"
work_dir = os.getcwd()
os.chdir(path)
os.system(command)
os.chdir(work_dir)
self.file = f"{path}/{self.name}.mol2"
self.molecule = self.get_ligand()
return self
def parmcheck(self, path, atom_type="gaff2"):
"""
Run parmchk2 from amber to create an frcmod file
Parameters:
-----------
Return:
-------
str:
full path to frcmod file
"""
command = f"parmchk2 -i {self.name}.mol2 -o {self.name}.frcmod -f mol2 -s {atom_type}"
work_dir = os.getcwd()
os.chdir(path)
os.system(command)
os.chdir(work_dir)
return functions.get_files(f"{path}/{self.name}.frcmod")[0]
def get_system(self):
"""
Get ligand system as a BSS system object
Return:
-------
ligands: bss.System
ligand system
"""
system = bss.IO.readMolecules(self.file)
return system
def main():
lig = Ligand("/home/jguven/projects/alchemistry/add_caps_to_kpc2/inputs/ligands/ligand_1.sdf")
print(lig.molecule, lig.name)
if __name__ == "__main__":
main()